mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-18 14:08:06 +01:00
feat(Tabs): handle content prop as boolean
This commit is contained in:
@@ -21,7 +21,7 @@ export interface TabsItem extends Partial<Pick<TabsTriggerProps, 'disabled' | 'v
|
||||
|
||||
export interface TabsProps<T> extends Omit<TabsRootProps, 'asChild'> {
|
||||
items?: T[]
|
||||
content?: Omit<TabsContentProps, 'asChild' | 'value'>
|
||||
content?: boolean | Omit<TabsContentProps, 'asChild' | 'value'>
|
||||
class?: any
|
||||
ui?: Partial<typeof tabs.slots>
|
||||
}
|
||||
@@ -45,6 +45,7 @@ import { TabsRoot, TabsList, TabsIndicator, TabsTrigger, TabsContent, useForward
|
||||
import { reactivePick } from '@vueuse/core'
|
||||
|
||||
const props = withDefaults(defineProps<TabsProps<T>>(), {
|
||||
content: true,
|
||||
defaultValue: '0',
|
||||
orientation: 'horizontal'
|
||||
})
|
||||
@@ -52,7 +53,7 @@ const emits = defineEmits<TabsEmits>()
|
||||
const slots = defineSlots<TabsSlots<T>>()
|
||||
|
||||
const rootProps = useForwardPropsEmits(reactivePick(props, 'as', 'defaultValue', 'orientation', 'activationMode', 'modelValue'), emits)
|
||||
const contentProps = toRef(() => defu(props.content, { forceMount: true }) as TabsContentProps)
|
||||
const contentProps = toRef(() => defu(props.content || {}, { forceMount: true }) as TabsContentProps)
|
||||
|
||||
const ui = computed(() => tv({ extend: tabs, slots: props.ui })({ orientation: props.orientation }))
|
||||
</script>
|
||||
@@ -76,10 +77,12 @@ const ui = computed(() => tv({ extend: tabs, slots: props.ui })({ orientation: p
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent v-for="(item, index) of items" :key="index" v-bind="contentProps" :value="item.value || String(index)" :class="ui.content()">
|
||||
<slot :name="item.slot || 'content'" :item="item" :index="index">
|
||||
{{ item.content }}
|
||||
</slot>
|
||||
</TabsContent>
|
||||
<template v-if="!!content">
|
||||
<TabsContent v-for="(item, index) of items" :key="index" v-bind="contentProps" :value="item.value || String(index)" :class="ui.content()">
|
||||
<slot :name="item.slot || 'content'" :item="item" :index="index">
|
||||
{{ item.content }}
|
||||
</slot>
|
||||
</TabsContent>
|
||||
</template>
|
||||
</TabsRoot>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user