import { type Ref } from 'react'; import { Button as AriaButton, Select as AriaSelect, type SelectProps as AriaSelectProps, FieldError, ListBox, ListBoxItem, Popover, SelectValue, } from 'react-aria-components'; import clsx from 'clsx'; import { tv } from 'tailwind-variants'; export type SelectOption = { label: string; value: string | number; isDisabled?: boolean; }; const selectStyle = tv({ base: 'flex items-center text-start gap-4 w-full bg-white text-sm text-dabeeo-black-34 border border-dabeeo-gray-be cursor-default px-3 h-9 min-w-[120px] outline-0', variants: { isDisabled: { true: 'text-dabeeo-gray-99 bg-dabeeo-gray-eb border-dabeeo-gray-be cursor-not-allowed', false: 'hover:text-dabeeo-black-34 hover:border-dabeeo-black-34 data-pressed:text-dabeeo-black-34 data-pressed:border-dabeeo-black-34', }, isReadOnly: { true: 'text-dabeeo-black-34 bg-dabeeo-yellow-secondary cursor-auto', }, isFocused: { true: 'border-dabeeo-black-34', }, }, }); export interface SelectProps extends Omit, 'selectionMode' | 'onChange' | 'children'> { items?: Iterable; onChange?: (value: T['value']) => void; maxHeight?: number; placement?: 'bottom' | 'top'; ref?: Ref; isReadOnly?: boolean; } export const Select = (props: SelectProps) => { const { className, items, onChange, maxHeight, placement = 'bottom', ref, isReadOnly, ...restProps } = props; return ( { onChange?.(key as T['value']); }} > selectStyle({ ...renderProps, isDisabled: props.isDisabled || isReadOnly, isReadOnly })} {...{ isDisabled: props.isDisabled || isReadOnly }} > {({ selectedText, defaultChildren }) => selectedText || defaultChildren} {(item) => ( {item.label} )} ); };