Choices
Button-style radio group for choosing one value from a short list.
Demo
$20$50$100Other
Compact
HoursDays
Disabled choice
$20$50$100
Default
import { useState } from 'react'
import { Choices } from 'regen-ui'
const amounts = [
{ label: '$20', value: '20' },
{ label: '$50', value: '50' },
{ label: '$100', value: '100' },
{ label: 'Other', value: 'other' },
] as const
export function DepositAmount() {
const [amount, setAmount] = useState<(typeof amounts)[number]['value']>('50')
return (
<Choices
items={amounts}
label="Deposit amount"
onChange={setAmount}
value={amount}
/>
)
}Compact
import { useState } from 'react'
import { Choices, Input } from 'regen-ui'
const units = [
{ label: 'Hours', value: 'hours' },
{ label: 'Days', value: 'days' },
] as const
export function ExpiryUnit() {
const [unit, setUnit] = useState<(typeof units)[number]['value']>('days')
return (
<Input
label="Expires after"
placeholder="30…"
suffix={
<Choices
items={units}
label="Expiry unit"
onChange={setUnit}
value={unit}
variant="compact"
/>
}
/>
)
}API Reference
Choices.Props<value extends string = string>
| Name | Type | Default | Description |
|---|---|---|---|
className | string | None | Additional class names for the root. |
items | readonly Item<value>[] | None | Selectable choices. |
label | string | None | Accessible label for the choices group. |
onChange | (value: value) => void | None | Called with the selected option value. |
style | CSSProperties | None | Custom root styles. |
value | value | None | Current selected option value. Leave undefined when no option is selected. |
variant | 'compact' | 'default' | 'default' | Visual size and treatment. |
Inherits HTMLAttributes<HTMLDivElement>, except children, defaultValue, onChange. | |||
classNameType
stringDefaultNone
Additional class names for the root.itemsType
readonly Item<value>[]DefaultNone
Selectable choices.labelType
stringDefaultNone
Accessible label for the choices group.onChangeType
(value: value) => voidDefaultNone
Called with the selected option value.styleType
CSSPropertiesDefaultNone
Custom root styles.valueType
valueDefaultNone
Current selected option value. Leave undefined when no option is selected.variantType
'compact' | 'default'Default
Visual size and treatment.'default'Inherits
HTMLAttributes<HTMLDivElement>, except children, defaultValue, onChange.Choices.Item<value extends string = string>
A selectable option.
| Name | Type | Default | Description |
|---|---|---|---|
disabled | boolean | None | Disable this option. |
label | ReactNode | None | Visible option label. |
value | value | None | Stable option value. |
disabledType
booleanDefaultNone
Disable this option.labelType
ReactNodeDefaultNone
Visible option label.valueType
valueDefaultNone
Stable option value.