ListBox
A list that opens from a button, for picking one option. Use it for a setting outside a form, such as items per page.
Import
Copy code
import { ListBox } from '@k8ordo/ui';Usage
Fruit
Copy code
const OPTIONS: readonly Option[] = [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
{ value: 'cherry', label: 'Cherry' },
{ value: 'grape', label: 'Grape' },
{ value: 'melon', label: 'Melon' },
];
const [selected, setSelected] = useState<string>();
<ListBox.Root
onChange={(value) => setSelected(value)}
options={OPTIONS}
value={selected}
>
<ListBox.Trigger label="Fruit" />
<ListBox.Content />
</ListBox.Root>Sizes
Fruit (sm)
Fruit (md)
Fruit (lg)
Copy code
<ListBox.Root onChange={onChange} options={OPTIONS} value={value}>
<ListBox.Trigger label="Fruit (sm)" size="sm" />
<ListBox.Content />
</ListBox.Root>
<ListBox.Root onChange={onChange} options={OPTIONS} value={value}>
<ListBox.Trigger label="Fruit (md)" size="md" />
<ListBox.Content />
</ListBox.Root>
<ListBox.Root onChange={onChange} options={OPTIONS} value={value}>
<ListBox.Trigger label="Fruit (lg)" size="lg" />
<ListBox.Content />
</ListBox.Root>Icon trigger
Fruit
Copy code
import { ListIcon } from '@k8ordo/ui/icons';
<ListBox.Root onChange={onChange} options={OPTIONS} value={value}>
<ListBox.IconTrigger icon={<ListIcon />} label="Fruit" />
<ListBox.Content />
</ListBox.Root>Props
ListBox.Root
options- Type:
readonly Option[] - Default: -
children?- Type:
ReactNode - Default: -
defaultValue?- Type:
Option['value'] - Default: -
onChange?- Type:
(value: Option['value']) => void - Default: -
placement?- Type:
Placement - Default:
'bottom' value?- Type:
Option['value'] - Default: -
| Prop | Type | Default |
|---|---|---|
options | readonly Option[] | - |
children? | ReactNode | - |
defaultValue? | Option['value'] | - |
onChange? | (value: Option['value']) => void | - |
placement? | Placement | 'bottom' |
value? | Option['value'] | - |
ListBox.Trigger
label?- Type:
string - Default: -
size?- Type:
ComponentProps<typeof Button>['size'] - Default:
'md'
| Prop | Type | Default |
|---|---|---|
label? | string | - |
size? | ComponentProps<typeof Button>['size'] | 'md' |
ListBox.IconTrigger
icon- Type:
ReactElement - Default: -
label?- Type:
string - Default: -
size?- Type:
ComponentProps<typeof Button>['size'] - Default:
'md'
| Prop | Type | Default |
|---|---|---|
icon | ReactElement | - |
label? | string | - |
size? | ComponentProps<typeof Button>['size'] | 'md' |
ListBox.Content
helpContent?- Type:
ReactElement - Default: -
| Prop | Type | Default |
|---|---|---|
helpContent? | ReactElement | - |