Skip to content

Commit

Permalink
feat(Autocomplete): add color focus prop to autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
driss-chelouati committed Feb 18, 2024
1 parent 6b059a1 commit d6f2024
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/plugins/components/autocomplete/autocomplete.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const Autocomplete = ({
contrast = 'default',
label,
labelFloat,
colorFocus,
clearable,
dropdown,
multiple,
Expand All @@ -35,6 +36,7 @@ export const Autocomplete = ({
error && !loading && 'nui-autocomplete-error',
loading && 'nui-autocomplete-loading',
labelFloat && 'nui-autocomplete-label-float',
colorFocus && 'nui-autocomplete-focus',
icon && 'nui-has-icon',
classes?.wrapper,
]
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/components/autocomplete/autocomplete.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export const defaultConfig = {
dark: 'primary-500',
},
},
border: {
color: {
light: 'primary-500',
dark: 'primary-500',
},
},
},
icon: {
color: {
Expand Down
12 changes: 12 additions & 0 deletions src/plugins/components/autocomplete/autocomplete.doc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ Autocompletes can have a clear button.

<br />

### State: color focus

Autocompletes can have a different border color when focused.

<div className="flex items-end gap-2 bg-slate-100 dark:bg-slate-900 p-6 rounded-sm">
<Story of={AutocompleteStories.ColorFocusSm} />
<Story of={AutocompleteStories.ColorFocusMd} />
<Story of={AutocompleteStories.ColorFocusLg} />
</div>

<br />

### State: disabled

Autocompletes can be shown in a disabled state.
Expand Down
83 changes: 83 additions & 0 deletions src/plugins/components/autocomplete/autocomplete.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,89 @@ export const DisabledLg: Story = {
}
// #endregion

// #region State: color focus
export const ColorFocusSm: Story = {
name: 'Color focus: sm',
args: {
label: 'Search',
colorFocus: true,
size: 'sm',
contrast: 'default',
rounded: 'sm',
id: 'autocomplete',
placeholder: 'Search languages...',
classes: {
wrapper: 'min-w-[280px] max-w-[280px] min-h-[280px]',
},
items: html`
${languages.map(
(item) => html`
<div class="nui-autocomplete-results-item">
<div class="nui-autocomplete-results-item-inner">
<span>${item.name}</span>
</div>
</div>
`,
)}
`,
},
}

export const ColorFocusMd: Story = {
name: 'Color focus: md',
args: {
label: 'Search',
colorFocus: true,
size: 'md',
contrast: 'default',
rounded: 'sm',
id: 'autocomplete',
placeholder: 'Search languages...',
classes: {
wrapper: 'min-w-[280px] max-w-[280px] min-h-[280px]',
},
items: html`
${languages.map(
(item) => html`
<div class="nui-autocomplete-results-item">
<div class="nui-autocomplete-results-item-inner">
<span>${item.name}</span>
</div>
</div>
`,
)}
`,
},
}

export const ColorFocusLg: Story = {
name: 'Color focus: lg',
args: {
label: 'Search',
colorFocus: true,
size: 'lg',
contrast: 'default',
rounded: 'sm',
id: 'autocomplete',
placeholder: 'Search languages...',
classes: {
wrapper: 'min-w-[280px] max-w-[280px] min-h-[280px]',
},
items: html`
${languages.map(
(item) => html`
<div class="nui-autocomplete-results-item">
<div class="nui-autocomplete-results-item-inner">
<span>${item.name}</span>
</div>
</div>
`,
)}
`,
},
}
// #endregion

// #region State: loading
export const LoadingSm: Story = {
name: 'Loading: sm',
Expand Down
1 change: 1 addition & 0 deletions src/plugins/components/autocomplete/autocomplete.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface AutocompleteProps extends Record<string, unknown> {
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'
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/components/autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,19 @@ export default plugin(({ addComponents, theme }) => {
{},
},
},
//Focus:color
'&.nui-autocomplete-focus': {
'.nui-autocomplete-input': {
//Transition
[`@apply transition-colors duration-300`]: {},
//Focus
[`@apply focus:!border-${config.input.focus.border.color.light} dark:focus:!border-${config.input.focus.border.color.dark}`]:
{},
//Force focus
[`@apply focus:hover:!border-${config.input.focus.border.color.light} dark:focus:hover:!border-${config.input.focus.border.color.dark}`]:
{},
},
},
//Autocomplete:not loading
'&:not(.nui-autocomplete-loading)': {
'.nui-autocomplete-input:placeholder-shown ~ .nui-label-float': {
Expand Down

0 comments on commit d6f2024

Please sign in to comment.