From af43b5df250fb65bf9696b5b3fb6cb507b2184a1 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Tue, 28 May 2024 15:29:22 +0200 Subject: [PATCH] feat(NavigationMenu): replace `line` variant with `highlight` prop --- playground/pages/navigation-menu.vue | 14 +- src/runtime/components/NavigationMenu.vue | 9 +- src/theme/navigation-menu.ts | 89 ++--- test/components/NavigationMenu.spec.ts | 2 + .../__snapshots__/NavigationMenu.spec.ts.snap | 325 ++++++++++++++---- 5 files changed, 321 insertions(+), 118 deletions(-) diff --git a/playground/pages/navigation-menu.vue b/playground/pages/navigation-menu.vue index b233489b..523730dd 100644 --- a/playground/pages/navigation-menu.vue +++ b/playground/pages/navigation-menu.vue @@ -6,8 +6,10 @@ const variants = Object.keys(theme.variants.variant) const orientations = Object.keys(theme.variants.orientation) const color = ref(theme.defaultVariants.color) +const highlightColor = ref(theme.defaultVariants.highlightColor) const variant = ref(theme.defaultVariants.variant) const orientation = ref('horizontal' as const) +const highlight = ref(true) const items = [ [{ @@ -84,16 +86,22 @@ const items = [ + + diff --git a/src/runtime/components/NavigationMenu.vue b/src/runtime/components/NavigationMenu.vue index fae6ea7a..c38227b3 100644 --- a/src/runtime/components/NavigationMenu.vue +++ b/src/runtime/components/NavigationMenu.vue @@ -40,6 +40,11 @@ export interface NavigationMenuProps extends Omit arrow?: boolean class?: any @@ -78,7 +83,9 @@ const contentProps = toRef(() => props.content) const ui = computed(() => tv({ extend: navigationMenu, slots: props.ui })({ orientation: props.orientation, color: props.color, - variant: props.variant + variant: props.variant, + highlight: props.highlight, + highlightColor: props.highlightColor })) const lists = computed(() => props.items?.length ? (Array.isArray(props.items[0]) ? props.items : [props.items]) as T[][] : []) diff --git a/src/theme/navigation-menu.ts b/src/theme/navigation-menu.ts index 0b13f61c..5a79ee17 100644 --- a/src/theme/navigation-menu.ts +++ b/src/theme/navigation-menu.ts @@ -32,9 +32,12 @@ export default (config: { colors: string[] }) => ({ ...Object.fromEntries(config.colors.map((color: string) => [color, ''])), black: '' }, + highlightColor: { + ...Object.fromEntries(config.colors.map((color: string) => [color, ''])), + black: '' + }, variant: { pill: '', - line: '', link: '' }, orientation: { @@ -68,20 +71,23 @@ export default (config: { colors: string[] }) => ({ true: { link: 'cursor-not-allowed opacity-75' } + }, + highlight: { + true: '' } }, compoundVariants: [{ - variant: 'line', + highlight: true, orientation: 'horizontal', class: { - link: 'after:absolute after:-bottom-[calc(var(--spacing-2)+1px)] after:inset-x-2.5 after:block after:h-0.5 after:rounded-full' + link: 'after:absolute after:-bottom-[calc(var(--spacing-2)+1px)] after:inset-x-2.5 after:block after:h-px after:rounded-full' } }, { - variant: 'line', + highlight: true, orientation: 'vertical', class: { item: 'px-2', - link: 'after:absolute after:-left-[calc(var(--spacing-2)+1px)] after:inset-y-0.5 after:block after:w-0.5 after:rounded-full' + link: 'after:absolute after:-left-[calc(var(--spacing-2)+1px)] after:inset-y-0.5 after:block after:w-px after:rounded-full' } }, { disabled: false, @@ -96,7 +102,7 @@ export default (config: { colors: string[] }) => ({ variant: 'pill', active: true, class: { - link: `text-${color}-500 dark:text-${color}-400 before:bg-gray-100 dark:before:bg-gray-800`, + link: `text-${color}-500 dark:text-${color}-400`, linkLeadingIcon: `text-${color}-500 dark:text-${color}-400` } })), { @@ -104,29 +110,22 @@ export default (config: { colors: string[] }) => ({ variant: 'pill', active: true, class: { - link: 'text-gray-900 dark:text-white before:bg-gray-100 dark:before:bg-gray-800', + link: 'text-gray-900 dark:text-white', linkLeadingIcon: 'text-gray-900 dark:text-white' } }, { - disabled: false, - variant: 'line', - class: { - link: 'hover:text-gray-900 dark:hover:text-white transition-colors hover:before:bg-gray-50 dark:hover:before:bg-gray-800/50 before:transition-colors', - linkLeadingIcon: 'group-hover:text-gray-700 dark:group-hover:text-gray-200 transition-colors' - } - }, ...config.colors.map((color: string) => ({ - color, - variant: 'line', + variant: 'pill', active: true, + highlight: false, class: { - link: `after:bg-${color}-500 dark:after:bg-${color}-400` + link: 'before:bg-gray-100 dark:before:bg-gray-800' } - })), { - color: 'black', - variant: 'line', + }, { + variant: 'pill', active: true, + highlight: true, class: { - link: 'after:bg-gray-900 dark:after:bg-white' + link: 'hover:before:bg-gray-50 dark:hover:before:bg-gray-800/50 before:transition-colors' } }, { disabled: false, @@ -152,42 +151,24 @@ export default (config: { colors: string[] }) => ({ link: 'text-gray-900 dark:text-white', linkLeadingIcon: 'text-gray-900 dark:text-white' } + }, ...config.colors.map((highlightColor: string) => ({ + highlightColor, + highlight: true, + active: true, + class: { + link: `after:bg-${highlightColor}-500 dark:after:bg-${highlightColor}-400` + } + })), { + highlightColor: 'black', + highlight: true, + active: true, + class: { + link: 'after:bg-gray-900 dark:after:bg-white' + } }], - // compoundVariants: [{ - // disabled: false, - // active: false, - // class: { - // item: 'hover:text-gray-900 dark:hover:text-white transition-colors', - // itemLeadingIcon: 'group-hover:text-gray-700 dark:group-hover:text-gray-200 transition-colors' - // } - // }, { - // orientation: 'horizontal', - // active: true, - // class: { - // item: 'after:bg-primary-500 dark:after:bg-primary-400' - // } - // }, { - // orientation: 'horizontal', - // disabled: false, - // class: { - // item: 'hover:before:bg-gray-50 dark:hover:before:bg-gray-800/50 before:transition-colors' - // } - // }, { - // orientation: 'vertical', - // active: true, - // class: { - // item: 'before:bg-gray-100 dark:before:bg-gray-800' - // } - // }, { - // orientation: 'vertical', - // active: false, - // disabled: false, - // class: { - // item: 'hover:before:bg-gray-50 dark:hover:before:bg-gray-800/50 before:transition-colors' - // } - // }], defaultVariants: { color: 'primary', + highlightColor: 'primary', variant: 'pill' } }) diff --git a/test/components/NavigationMenu.spec.ts b/test/components/NavigationMenu.spec.ts index 63aaea31..26fbdff7 100644 --- a/test/components/NavigationMenu.spec.ts +++ b/test/components/NavigationMenu.spec.ts @@ -84,6 +84,8 @@ describe('NavigationMenu', () => { ['with orientation vertical', { props: { ...props, orientation: 'vertical' as const } }], ...colors.map((color: string) => [`with color ${color}`, { props: { ...props, color } }]), ...variants.map((variant: string) => [`with variant ${variant}`, { props: { ...props, variant } }]), + ...variants.map((variant: string) => [`with highlight ${variant}`, { props: { ...props, highlight: true, variant } }]), + ...colors.map((highlightColor: string) => [`with highlight color ${highlightColor}`, { props: { ...props, highlight: true, highlightColor } }]), ['with trailingIcon', { props: { ...props, trailingIcon: 'i-heroicons-plus' } }], ['with class', { props: { ...props, class: 'w-48' } }], ['with ui', { props: { items, ui: { itemLeadingIcon: 'size-4' } } }], diff --git a/test/components/__snapshots__/NavigationMenu.spec.ts.snap b/test/components/__snapshots__/NavigationMenu.spec.ts.snap index 4833ce10..3a2948ff 100644 --- a/test/components/__snapshots__/NavigationMenu.spec.ts.snap +++ b/test/components/__snapshots__/NavigationMenu.spec.ts.snap @@ -47,13 +47,13 @@ exports[`NavigationMenu > renders with class correctly 1`] = ` "