@k8ordo/ui

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

ts
import { ListBox } from '@k8ordo/ui';

Usage

Fruit
tsx
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)
tsx
<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
tsx
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: -
PropTypeDefault
optionsreadonly 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'
PropTypeDefault
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'
PropTypeDefault
iconReactElement-
label?string-
size?ComponentProps<typeof Button>['size']'md'

ListBox.Content

helpContent?
Type: ReactElement
Default: -
PropTypeDefault
helpContent?ReactElement-
k8ordo

React libraries that use Baseline features without holding back.