From 6b059a1194f0ff2145dd559c7c2c8b67d4d34300 Mon Sep 17 00:00:00 2001 From: Driss Chelouati Date: Sun, 18 Feb 2024 22:42:31 +0100 Subject: [PATCH] feat(Listbox): add color focus prop to listbox --- src/plugins/components/listbox/index.ts | 13 ++ .../components/listbox/listbox.component.ts | 2 + .../components/listbox/listbox.config.ts | 8 + .../components/listbox/listbox.doc.mdx | 12 ++ .../components/listbox/listbox.stories.ts | 146 ++++++++++++++++++ .../components/listbox/listbox.types.ts | 1 + 6 files changed, 182 insertions(+) diff --git a/src/plugins/components/listbox/index.ts b/src/plugins/components/listbox/index.ts index e8bea64..b056f9f 100644 --- a/src/plugins/components/listbox/index.ts +++ b/src/plugins/components/listbox/index.ts @@ -458,6 +458,19 @@ export default plugin(({ addComponents, theme }) => { {}, }, }, + //Focus:color + '&.nui-listbox-focus': { + '.nui-listbox-button': { + //Transition + [`@apply transition-colors duration-300`]: {}, + //Focus + [`@apply focus:!border-${config.button.focus.border.color.light} dark:focus:!border-${config.button.focus.border.color.dark}`]: + {}, + //Force focus + [`@apply focus:hover:!border-${config.button.focus.border.color.light} dark:focus:hover:!border-${config.button.focus.border.color.dark}`]: + {}, + }, + }, //Listbox:loaded '&:not(.nui-listbox-loading)': { '.nui-listbox-button ~ .nui-label-float': { diff --git a/src/plugins/components/listbox/listbox.component.ts b/src/plugins/components/listbox/listbox.component.ts index 0560a06..47091c1 100644 --- a/src/plugins/components/listbox/listbox.component.ts +++ b/src/plugins/components/listbox/listbox.component.ts @@ -16,6 +16,7 @@ export const Listbox = ({ contrast = 'default', label, labelFloat, + colorFocus, multiple, loading, error, @@ -33,6 +34,7 @@ export const Listbox = ({ error && !loading && 'nui-listbox-error', loading && 'nui-listbox-loading', labelFloat && 'nui-listbox-label-float', + colorFocus && 'nui-listbox-focus', icon && 'nui-has-icon', classes?.wrapper, ] diff --git a/src/plugins/components/listbox/listbox.config.ts b/src/plugins/components/listbox/listbox.config.ts index 5b79d44..69606b0 100644 --- a/src/plugins/components/listbox/listbox.config.ts +++ b/src/plugins/components/listbox/listbox.config.ts @@ -27,6 +27,14 @@ export const defaultConfig = { size: 'sm', align: 'start', }, + focus: { + border: { + color: { + light: 'primary-500', + dark: 'primary-500', + }, + }, + }, iconBox: { margin: { x: '2', diff --git a/src/plugins/components/listbox/listbox.doc.mdx b/src/plugins/components/listbox/listbox.doc.mdx index fd44479..da399c0 100644 --- a/src/plugins/components/listbox/listbox.doc.mdx +++ b/src/plugins/components/listbox/listbox.doc.mdx @@ -107,6 +107,18 @@ Listboxes can have a floating label instead of the regular label. ## State +### State: color focus + +Listboxes can have a colored border when focused. + +
+ + + +
+ +
+ ### State: disabled Listboxes can be shown in a disabled state. diff --git a/src/plugins/components/listbox/listbox.stories.ts b/src/plugins/components/listbox/listbox.stories.ts index 60dab6c..1e39d57 100644 --- a/src/plugins/components/listbox/listbox.stories.ts +++ b/src/plugins/components/listbox/listbox.stories.ts @@ -1072,6 +1072,152 @@ export const DisabledLg: Story = { } // #endregion +// #region State: color focus +export const ColorFocusSm: Story = { + name: 'State color focus: sm', + args: { + value: languages[0].name, + label: 'Languages', + colorFocus: true, + size: 'sm', + contrast: 'default', + rounded: 'sm', + id: 'listbox', + placeholder: 'Select a language...', + classes: { + wrapper: 'min-w-[280px] max-w-[280px] min-h-[260px]', + }, + items: html` + ${languages.map( + (item, index) => html` +
+ ${item.name} + ${index === 0 + ? html` +
+ + + +
+ ` + : ''} +
+ `, + )} + `, + }, +} + +export const ColorFocusMd: Story = { + name: 'State color focus: md', + args: { + value: languages[0].name, + label: 'Languages', + colorFocus: true, + size: 'md', + contrast: 'default', + rounded: 'sm', + id: 'listbox', + placeholder: 'Select a language...', + classes: { + wrapper: 'min-w-[280px] max-w-[280px] min-h-[260px]', + }, + items: html` + ${languages.map( + (item, index) => html` +
+ ${item.name} + ${index === 0 + ? html` +
+ + + +
+ ` + : ''} +
+ `, + )} + `, + }, +} + +export const ColorFocusLg: Story = { + name: 'State color focus: lg', + args: { + value: languages[0].name, + label: 'Languages', + colorFocus: true, + size: 'lg', + contrast: 'default', + rounded: 'sm', + id: 'listbox', + placeholder: 'Select a language...', + classes: { + wrapper: 'min-w-[280px] max-w-[280px] min-h-[260px]', + }, + items: html` + ${languages.map( + (item, index) => html` +
+ ${item.name} + ${index === 0 + ? html` +
+ + + +
+ ` + : ''} +
+ `, + )} + `, + }, +} +// #endregion + // #region State: loading export const LoadingSm: Story = { name: 'State loading: sm', diff --git a/src/plugins/components/listbox/listbox.types.ts b/src/plugins/components/listbox/listbox.types.ts index 1aff1ad..b4d8236 100644 --- a/src/plugins/components/listbox/listbox.types.ts +++ b/src/plugins/components/listbox/listbox.types.ts @@ -7,6 +7,7 @@ export interface ListboxProps extends Record { rounded?: 'none' | 'sm' | 'md' | 'lg' | 'full' label?: string labelFloat?: boolean + colorFocus?: boolean error?: string | boolean size?: 'sm' | 'md' | 'lg' contrast?: 'default' | 'default-contrast' | 'muted' | 'muted-contrast'