From 06ea029ef624116792230fdb57cdcee13b610fc0 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Fri, 5 Apr 2024 17:05:03 +0200 Subject: [PATCH] feat(Tabs): handle items `icon` --- playground/pages/tabs.vue | 3 + src/runtime/components/Accordion.vue | 4 +- src/runtime/components/Tabs.vue | 10 ++- src/theme/tabs.ts | 3 +- test/components/Tabs.spec.ts | 3 + .../__snapshots__/Tabs.spec.ts.snap | 64 ++++++++++++++++--- 6 files changed, 75 insertions(+), 12 deletions(-) diff --git a/playground/pages/tabs.vue b/playground/pages/tabs.vue index 90f4dbd0..2086e048 100644 --- a/playground/pages/tabs.vue +++ b/playground/pages/tabs.vue @@ -1,12 +1,15 @@ diff --git a/src/runtime/components/Accordion.vue b/src/runtime/components/Accordion.vue index 964755ef..60f429d2 100644 --- a/src/runtime/components/Accordion.vue +++ b/src/runtime/components/Accordion.vue @@ -11,9 +11,9 @@ const appConfig = _appConfig as AppConfig & { ui: { accordion: Partial } } @@ -11,8 +12,9 @@ const tabs = tv({ extend: tv(theme), ...(appConfig.ui?.tabs || {}) }) export interface TabsItem { label?: string - value?: string + icon?: IconProps['name'] slot?: string + value?: string disabled?: boolean content?: string } @@ -57,9 +59,15 @@ const ui = computed(() => tv({ extend: tabs, slots: props.ui })()) + + + + {{ item.label }} + + diff --git a/src/theme/tabs.ts b/src/theme/tabs.ts index 56efd8b0..bdb44d22 100644 --- a/src/theme/tabs.ts +++ b/src/theme/tabs.ts @@ -4,8 +4,9 @@ export default { list: 'relative w-full flex data-[orientation=vertical]:flex-col data-[orientation=vertical]:items-center justify-center rounded-lg bg-gray-50 dark:bg-gray-800 data-[orientation=horizontal]:h-10 p-1 group', // FIXME: Replace `transition-all` with `transition-[width,transform]` when available indicator: 'absolute group-data-[orientation=horizontal]:left-0 group-data-[orientation=vertical]:top-0 group-data-[orientation=horizontal]:inset-y-1 group-data-[orientation=vertical]:inset-x-1 group-data-[orientation=horizontal]:w-[--radix-tabs-indicator-size] group-data-[orientation=vertical]:h-[--radix-tabs-indicator-size] group-data-[orientation=horizontal]:translate-x-[--radix-tabs-indicator-position] group-data-[orientation=vertical]:translate-y-[--radix-tabs-indicator-position] transition-all duration-200 bg-white dark:bg-gray-900 rounded-md shadow-sm', - trigger: 'relative inline-flex items-center justify-center shrink-0 flex-1 h-8 text-gray-500 data-[state=active]:text-gray-900 dark:text-gray-400 dark:data-[state=active]:text-white px-3 text-sm font-medium rounded-md disabled:cursor-not-allowed disabled:opacity-75 transition-colors duration-200 ease-out focus-visible:ring-2 focus-visible:ring-primary-500 dark:focus-visible:ring-primary-400 focus:outline-none', + trigger: 'relative inline-flex items-center justify-center gap-1.5 shrink-0 flex-1 h-8 text-gray-500 data-[state=active]:text-gray-900 dark:text-gray-400 dark:data-[state=active]:text-white px-3 text-sm font-medium rounded-md disabled:cursor-not-allowed disabled:opacity-75 transition-colors duration-200 ease-out focus-visible:ring-2 focus-visible:ring-primary-500 dark:focus-visible:ring-primary-400 focus:outline-none', content: 'focus:outline-none', + leadingIcon: 'shrink-0 size-5', label: 'truncate' } } diff --git a/test/components/Tabs.spec.ts b/test/components/Tabs.spec.ts index 52d1e217..7ff20fa7 100644 --- a/test/components/Tabs.spec.ts +++ b/test/components/Tabs.spec.ts @@ -4,12 +4,15 @@ import ComponentRender from '../component-render' const items = [{ label: 'Tab1', + icon: 'i-heroicons-home', content: 'This is the content shown for Tab1' }, { label: 'Tab2', + icon: 'i-heroicons-user', content: 'And, this is the content for Tab2' }, { label: 'Tab3', + icon: 'i-heroicons-bell', content: 'Finally, this is the content for Tab3' }] diff --git a/test/components/__snapshots__/Tabs.spec.ts.snap b/test/components/__snapshots__/Tabs.spec.ts.snap index a9078dbd..84926086 100644 --- a/test/components/__snapshots__/Tabs.spec.ts.snap +++ b/test/components/__snapshots__/Tabs.spec.ts.snap @@ -3,7 +3,13 @@ exports[`Tabs > renders basic case correctly 1`] = ` "
-
+
This is the content shown for Tab1
@@ -14,7 +20,13 @@ exports[`Tabs > renders basic case correctly 1`] = ` exports[`Tabs > renders with class correctly 1`] = ` "
-
+
This is the content shown for Tab1
@@ -25,7 +37,13 @@ exports[`Tabs > renders with class correctly 1`] = ` exports[`Tabs > renders with content slot correctly 1`] = ` "
-
+
Content slot
@@ -36,7 +54,13 @@ exports[`Tabs > renders with content slot correctly 1`] = ` exports[`Tabs > renders with default slot correctly 1`] = ` "
-
+
This is the content shown for Tab1
@@ -47,7 +71,13 @@ exports[`Tabs > renders with default slot correctly 1`] = ` exports[`Tabs > renders with defaultValue correctly 1`] = ` "
-
+
And, this is the content for Tab2
@@ -58,7 +88,13 @@ exports[`Tabs > renders with defaultValue correctly 1`] = ` exports[`Tabs > renders with modelValue correctly 1`] = ` "
-
+
And, this is the content for Tab2
@@ -69,7 +105,13 @@ exports[`Tabs > renders with modelValue correctly 1`] = ` exports[`Tabs > renders with orientation correctly 1`] = ` "
-
+
This is the content shown for Tab1
@@ -80,7 +122,13 @@ exports[`Tabs > renders with orientation correctly 1`] = ` exports[`Tabs > renders with ui correctly 1`] = ` "
-
+
This is the content shown for Tab1