47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import * as SelectPrimitive from '@radix-ui/react-select'
|
|
import { Check, ChevronDown } from 'lucide-react'
|
|
import { cn } from '../../lib/utils'
|
|
|
|
export interface SelectOption {
|
|
value: string
|
|
label: string
|
|
}
|
|
|
|
interface SelectProps {
|
|
value: string
|
|
onValueChange: (value: string) => void
|
|
options: SelectOption[]
|
|
placeholder?: string
|
|
disabled?: boolean
|
|
className?: string
|
|
}
|
|
|
|
export function Select({ value, onValueChange, options, placeholder, disabled, className }: SelectProps) {
|
|
return (
|
|
<SelectPrimitive.Root value={value} onValueChange={onValueChange} disabled={disabled}>
|
|
<SelectPrimitive.Trigger className={cn('an-select', className)}>
|
|
<span className="an-select__value">
|
|
<SelectPrimitive.Value placeholder={placeholder} />
|
|
</span>
|
|
<SelectPrimitive.Icon>
|
|
<ChevronDown size={16} />
|
|
</SelectPrimitive.Icon>
|
|
</SelectPrimitive.Trigger>
|
|
<SelectPrimitive.Portal>
|
|
<SelectPrimitive.Content className="an-select__content" position="popper">
|
|
<SelectPrimitive.Viewport>
|
|
{options.map((option) => (
|
|
<SelectPrimitive.Item key={option.value} value={option.value} className="an-select__item">
|
|
<SelectPrimitive.ItemText>{option.label}</SelectPrimitive.ItemText>
|
|
<SelectPrimitive.ItemIndicator>
|
|
<Check size={14} />
|
|
</SelectPrimitive.ItemIndicator>
|
|
</SelectPrimitive.Item>
|
|
))}
|
|
</SelectPrimitive.Viewport>
|
|
</SelectPrimitive.Content>
|
|
</SelectPrimitive.Portal>
|
|
</SelectPrimitive.Root>
|
|
)
|
|
}
|