mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
fix(types): improve dynamic slots (#3857)
This commit is contained in:
@@ -115,9 +115,9 @@ const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.accordion ||
|
||||
</AccordionHeader>
|
||||
|
||||
<AccordionContent v-if="item.content || !!slots.content || (item.slot && !!slots[item.slot as keyof AccordionSlots<T>]) || !!slots.body || (item.slot && !!slots[`${item.slot}-body` as keyof AccordionSlots<T>])" :class="ui.content({ class: props.ui?.content })">
|
||||
<slot :name="((item.slot || 'content') as keyof AccordionSlots<T>)" :item="item" :index="index" :open="open">
|
||||
<slot :name="((item.slot || 'content') as keyof AccordionSlots<T>)" :item="(item as Extract<T, { slot: string; }>)" :index="index" :open="open">
|
||||
<div :class="ui.body({ class: props.ui?.body })">
|
||||
<slot :name="((item.slot ? `${item.slot}-body`: 'body') as keyof AccordionSlots<T>)" :item="item" :index="index" :open="open">
|
||||
<slot :name="((item.slot ? `${item.slot}-body`: 'body') as keyof AccordionSlots<T>)" :item="(item as Extract<T, { slot: string; }>)" :index="index" :open="open">
|
||||
{{ item.content }}
|
||||
</slot>
|
||||
</div>
|
||||
|
||||
@@ -16,18 +16,21 @@ export type DeepPartial<T, O = any> = {
|
||||
[key: string]: O | TightMap<O>
|
||||
}
|
||||
|
||||
export type DynamicSlotsKeys<Name extends string | undefined, Suffix extends string | undefined = undefined> = (
|
||||
Name extends string
|
||||
? Suffix extends string
|
||||
? Name | `${Name}-${Suffix}`
|
||||
: Name
|
||||
: never
|
||||
)
|
||||
export type DynamicSlots<
|
||||
T extends { slot?: string },
|
||||
S extends string | undefined = undefined,
|
||||
D extends object = {}
|
||||
Suffix extends string | undefined = undefined,
|
||||
ExtraProps extends object = {}
|
||||
> = {
|
||||
[
|
||||
K in T['slot'] as K extends string
|
||||
? S extends string
|
||||
? (K | `${K}-${S}`)
|
||||
: K
|
||||
: never
|
||||
]?: (props: { item: Extract<T, { slot: K extends `${infer Base}-${S}` ? Base : K }> } & D) => any
|
||||
[K in DynamicSlotsKeys<T['slot'], Suffix>]: (
|
||||
props: { item: Extract<T, { slot: K extends `${infer Base}-${Suffix}` ? Base : K }> } & ExtraProps
|
||||
) => any
|
||||
}
|
||||
|
||||
export type GetObjectField<MaybeObject, Key extends string> = MaybeObject extends Record<string, any>
|
||||
|
||||
Reference in New Issue
Block a user