diff --git a/packages/design-system/lib/components/Select/Select.stories.tsx b/packages/design-system/lib/components/Select/Select.stories.tsx index a04fb7e75..daf9e067a 100644 --- a/packages/design-system/lib/components/Select/Select.stories.tsx +++ b/packages/design-system/lib/components/Select/Select.stories.tsx @@ -19,8 +19,32 @@ export const Default: Story = { icon: 'star', itemIcon: 'check', items: ['Foo', 'Bar', 'Baz'], - // items: new Array(30).fill(null).map((_, idx) => idx), label: 'Select an item', name: 'foo', }, } + +export const ObjectItem: Story = { + args: { + icon: 'star', + itemIcon: 'check', + items: [ + { label: 'Foo', value: 'foo' }, + { label: 'Bar', value: 'bar' }, + { label: 'Baz', value: 'baz' }, + ], + label: 'Select an item', + name: 'foo', + }, +} + +export const Filtering: Story = { + args: { + icon: 'star', + itemIcon: 'check', + items: ['Foo', 'Bar', 'Baz'], + label: 'Select an item', + name: 'foo', + enableFiltering: true, + }, +} diff --git a/packages/design-system/lib/components/Select/Select.tsx b/packages/design-system/lib/components/Select/Select.tsx index 343c07f54..299d542de 100644 --- a/packages/design-system/lib/components/Select/Select.tsx +++ b/packages/design-system/lib/components/Select/Select.tsx @@ -5,14 +5,17 @@ import { ListBox, Button, } from 'react-aria-components' -import { Typography } from '../Typography' +import { cx } from 'class-variance-authority' -import styles from './select.module.css' import { MaterialIcon } from '../Icons/MaterialIcon' +import { Typography } from '../Typography' import { SelectItem } from './SelectItem' +import { SelectFilter } from './SelectFilter' import type { SelectProps } from './types' +import styles from './select.module.css' + export function Select({ name, label, @@ -21,7 +24,21 @@ export function Select({ isDisabled, icon, itemIcon, + enableFiltering, }: SelectProps) { + if (enableFiltering) { + return ( + + ) + } const iconColor = isDisabled ? 'Icon/Interactive/Disabled' : 'Icon/Default' return ( @@ -32,7 +49,7 @@ export function Select({ isRequired={isRequired} isDisabled={isDisabled} > - + {items.map((item, idx) => ( diff --git a/packages/design-system/lib/components/Select/SelectFilter.tsx b/packages/design-system/lib/components/Select/SelectFilter.tsx new file mode 100644 index 000000000..33c9886f1 --- /dev/null +++ b/packages/design-system/lib/components/Select/SelectFilter.tsx @@ -0,0 +1,104 @@ +import { + Button, + ComboBox, + Input, + Key, + ListBox, + Popover, +} from 'react-aria-components' +import { cx } from 'class-variance-authority' +import { useState } from 'react' + +import { MaterialIcon } from '../Icons/MaterialIcon' +import { Typography } from '../Typography' +import { SelectItem } from './SelectItem' + +import type { SelectProps } from './types' + +import styles from './select.module.css' + +export function SelectFilter({ + name, + label, + items, + isRequired, + isDisabled, + icon, + itemIcon, +}: SelectProps) { + const [focus, setFocus] = useState(false) + const [value, setValue] = useState(null) + const iconColor = isDisabled ? 'Icon/Interactive/Disabled' : 'Icon/Default' + + return ( + setValue(val)} + onFocus={() => setFocus(true)} + onBlur={() => setFocus(false)} + > + + + + + {items.map((item, idx) => ( + + {typeof item === 'object' ? ( + + {item.label} + + ) : ( + + {item.toString()} + + )} + + ))} + + + + ) +} diff --git a/packages/design-system/lib/components/Select/index.ts b/packages/design-system/lib/components/Select/index.ts index 65e5c3fbf..20fbbe724 100644 --- a/packages/design-system/lib/components/Select/index.ts +++ b/packages/design-system/lib/components/Select/index.ts @@ -1,2 +1,3 @@ export { Select } from './Select' export { SelectItem } from './SelectItem' +export { SelectFilter } from './SelectFilter' diff --git a/packages/design-system/lib/components/Select/select.module.css b/packages/design-system/lib/components/Select/select.module.css index 35c839131..a4eefbebf 100644 --- a/packages/design-system/lib/components/Select/select.module.css +++ b/packages/design-system/lib/components/Select/select.module.css @@ -1,5 +1,8 @@ .select { position: relative; + background-color: var(--Surface-UI-Fill-Default); + border: 1px solid var(--Border-Default); + border-radius: var(--Corner-radius-md); max-width: 300px; &[data-required] .label::after { @@ -9,48 +12,81 @@ rotate: -90deg; } &[data-focused] { - .button { - border: 1px solid var(--Border-Interactive-Focus); + border: 1px solid var(--Border-Interactive-Focus); + + .button, + .input { outline: none; } - .selectValue { + .input { + position: unset; + } + .label { color: var(--Text-Interactive-Focus); } } + &[data-disabled] { + .inner { + background-color: var(--Surface-Primary-Disabled); + color: var(--Text-Interactive-Disabled); + } + .button, + .input, + .label, + .selectValue { + color: var(--Text-Interactive-Disabled); + } + } } .chevron { rotate: 90deg; } -.button { - background-color: var(--Surface-UI-Fill-Default); - border: 1px solid var(--Border-Default); - border-radius: var(--Corner-radius-md); - padding: var(--Space-x1); +.inner { display: flex; align-items: center; gap: var(--Space-x1); width: 100%; height: 56px; + padding: var(--Space-x1); + box-sizing: border-box; - &[disabled] { - color: var(--Text-Interactive-Disabled); - background-color: var(--Surface-Primary-Disabled); + .button { + padding: 0; + } +} - .label, - .selectValue { - color: var(--Text-Interactive-Disabled); - } +.button, +.input { + background: none; + border: 0; +} + +.input { + position: absolute; + padding: 0; + + &.hasValue { + position: unset; + } +} + +.displayText { + display: flex; + flex-direction: column; + gap: calc(var(--Space-x05) / 2); + flex: 1; + justify-content: center; + height: 100%; + + &:has(.input) { + cursor: text; } } .selectValue { - display: flex; - flex-direction: column; - gap: calc(var(--Space-x05) / 2); align-items: flex-start; - flex: 1; color: var(--Text-Default); } diff --git a/packages/design-system/lib/components/Select/types.ts b/packages/design-system/lib/components/Select/types.ts index a92502315..9eeabfa22 100644 --- a/packages/design-system/lib/components/Select/types.ts +++ b/packages/design-system/lib/components/Select/types.ts @@ -17,6 +17,7 @@ export interface SelectProps extends ComponentProps { label: string isRequired?: boolean isDisabled?: boolean + enableFiltering?: boolean } export interface SelectItemProps extends ComponentProps {