From e54dd55053b6b6c39b98f1195cc820c616f1ebdd Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Wed, 17 Apr 2024 12:00:39 +0200 Subject: [PATCH] chore(Tabs): move `#default` slot around trigger --- src/runtime/components/Tabs.vue | 23 +++--- test/components/Tabs.spec.ts | 22 +++-- .../__snapshots__/Tabs.spec.ts.snap | 82 ++++++++++++++++--- 3 files changed, 96 insertions(+), 31 deletions(-) diff --git a/src/runtime/components/Tabs.vue b/src/runtime/components/Tabs.vue index 2f38a437..754e20e2 100644 --- a/src/runtime/components/Tabs.vue +++ b/src/runtime/components/Tabs.vue @@ -32,8 +32,9 @@ export interface TabsEmits extends TabsRootEmits {} type SlotProps = (props: { item: T, index: number }) => any export type TabsSlots = { - leading: SlotProps default: SlotProps + leading: SlotProps + label: SlotProps trailing: SlotProps content: SlotProps [key: string]: SlotProps @@ -65,16 +66,18 @@ const ui = computed(() => tv({ extend: tabs, slots: props.ui })({ orientation: p - - - + + + + + + + + {{ item.label }} + + + - - - {{ item.label }} - - - diff --git a/test/components/Tabs.spec.ts b/test/components/Tabs.spec.ts index 9b727d92..9aa61c2a 100644 --- a/test/components/Tabs.spec.ts +++ b/test/components/Tabs.spec.ts @@ -17,17 +17,23 @@ describe('Tabs', () => { content: 'Finally, this is the content for Tab3' }] + const props = { items } + it.each([ // Props - ['with items', { props: { items } }], - ['with modelValue', { props: { items, modelValue: '1' } }], - ['with defaultValue', { props: { items, defaultValue: '1' } }], - ['with orientation vertical', { props: { items, orientation: 'vertical' as const } }], - ['with class', { props: { items, class: 'w-96' } }], - ['with ui', { props: { items, ui: { content: 'w-full ring ring-gray-200 dark:ring-gray-800' } } }], + ['with items', { props }], + ['with modelValue', { props: { ...props, modelValue: '1' } }], + ['with defaultValue', { props: { ...props, defaultValue: '1' } }], + ['with orientation vertical', { props: { ...props, orientation: 'vertical' as const } }], + ['with class', { props: { ...props, class: 'w-96' } }], + ['with ui', { props: { ...props, ui: { content: 'w-full ring ring-gray-200 dark:ring-gray-800' } } }], // Slots - ['with default slot', { props: { items }, slots: { default: () => 'Default slot' } }], - ['with content slot', { props: { items }, slots: { content: () => 'Content slot' } }] + ['with default slot', { props, slots: { default: () => 'Default slot' } }], + ['with leading slot', { props, slots: { leading: () => 'Leading slot' } }], + ['with label slot', { props, slots: { label: () => 'Label slot' } }], + ['with trailing slot', { props, slots: { trailing: () => 'Trailing slot' } }], + ['with content slot', { props, slots: { content: () => 'Content slot' } }], + ['with custom slot', { props, slots: { custom: () => 'Custom slot' } }] ])('renders %s correctly', async (nameOrHtml: string, options: { props?: TabsProps, slots?: any }) => { const html = await ComponentRender(nameOrHtml, options, Tabs) expect(html).toMatchSnapshot() diff --git a/test/components/__snapshots__/Tabs.spec.ts.snap b/test/components/__snapshots__/Tabs.spec.ts.snap index 5bee231b..629f5eeb 100644 --- a/test/components/__snapshots__/Tabs.spec.ts.snap +++ b/test/components/__snapshots__/Tabs.spec.ts.snap @@ -20,30 +20,41 @@ exports[`Tabs > renders with class correctly 1`] = ` exports[`Tabs > renders with content slot correctly 1`] = ` "
-
-
Content slot
- - +
Content slot
+ + +
" +`; + +exports[`Tabs > renders with custom slot correctly 1`] = ` +"
+
+
+
+
This is the content shown for Tab1
+ +
" `; exports[`Tabs > renders with default slot correctly 1`] = ` "
-
+
This is the content shown for Tab1
@@ -85,6 +96,34 @@ exports[`Tabs > renders with items correctly 1`] = `
" `; +exports[`Tabs > renders with label slot correctly 1`] = ` +"
+
+
+
+
This is the content shown for Tab1
+ + +
" +`; + +exports[`Tabs > renders with leading slot correctly 1`] = ` +"
+
+
+
+
This is the content shown for Tab1
+ + +
" +`; + exports[`Tabs > renders with modelValue correctly 1`] = ` "
@@ -119,6 +158,23 @@ exports[`Tabs > renders with orientation vertical correctly 1`] = `
" `; +exports[`Tabs > renders with trailing slot correctly 1`] = ` +"
+
+
+
+
This is the content shown for Tab1
+ + +
" +`; + exports[`Tabs > renders with ui correctly 1`] = ` "