= {
sm: 'size-5 [&_svg]:size-3.5',
md: 'size-6 [&_svg]:size-4',
lg: 'size-7 [&_svg]:size-4.5',
}
/** A real, labelled button that clears the value. Positioned over the trigger's spacer. */
export function ClearButton({
size,
label,
onClear,
className,
}: {
size: SelectSize
label: string
onClear: () => void
className?: string
}) {
return (
)
}
/** Label, description and custom rendering of one option. */
function OptionBody({
option,
selected,
renderOption,
descriptionId,
}: {
option: SelectOption
selected: boolean
renderOption?: RenderOption
descriptionId: string
}) {
if (renderOption) return {renderOption(option, { selected })}
return (
{option.label}
{option.description && (
{option.description}
)}
)
}
function SelectItem({
option,
selected,
renderOption,
}: {
option: SelectOption
selected: boolean
renderOption?: RenderOption
}) {
const descriptionId = useId()
const described = option.description && !renderOption
return (
)
}
/** Items for a Base UI Select list, grouped by `group` when any option has one. */
export function SelectOptions({
options,
isSelected,
renderOption,
}: {
options: SelectOption[]
isSelected: (value: string) => boolean
renderOption?: RenderOption
}) {
return groupOptions(options).map((group, index) => {
const items = group.items.map((option) => (
))
if (group.label === null) return {items}
return (
{index > 0 && }
{group.label}
{items}
)
})
}
export function ComboboxItem({
option,
selected,
renderOption,
index,
}: {
option: SelectOption
selected: boolean
renderOption?: RenderOption
index?: number
}) {
const descriptionId = useId()
const described = option.description && !renderOption
return (
)
}
/** The list inside a Base UI Combobox popup, grouped or flat. */
export function ComboboxOptions({
grouped,
isSelected,
renderOption,
}: {
grouped: boolean
isSelected: (value: string) => boolean
renderOption?: RenderOption
}) {
if (!grouped) {
return (
{(option: SelectOption, index: number) => (
)}
)
}
return (
{(group: ComboboxGroup, index: number) => (
{index > 0 && }
{group.value && (
{group.value}
)}
{(option: SelectOption) => (
)}
)}
)
}
/** A muted row for loading, empty and status messages. */
export function StatusRow({ loading, children }: { loading?: boolean; children: ReactNode }) {
return (
{loading && }
{children}
)
}
/** Footer button in a popup, such as "Add department". */
export function ActionFooter({ action, onDone }: { action: SelectActionButton; onDone: () => void }) {
return (
)
}