Components
- 3DCard Component
- AirpodsProLeft Component
- AirpodsProRight Component
- Alert Component
- Audio Component
- Button Component
- Card Component
- ChargingIconRight Component
- ChargingTextLeft Component
- Checkbox Component
- Collapse Component
- EmptyState Component
- ErrorMessage Component
- Form Component
- GridLayout Component
- HelpTooltip Component
- Image Component
- Input Component
- Lamp Component
- LightBox Component
- Modal Component
- MovingBorder Component
- PageLoading Component
- Popover Component
- PropertyDefault Component
- Radio Component
- RangeSlider Component
- Select
- SilentIconLeft Component
- SongThumbnail Component
- SilentTextRight Component
- Spinner Component
- TabButton Component
- TextArea Component
- Toggle Component
- Toggle2 Component
- Tooltip Component
- WarningMessage Component
Components
Select
import type { ComponentProps } from 'react';
import { forwardRef, useId } from 'react';
import cn from '../cn';
interface SelectProps extends ComponentProps<'select'> {
className?: string;
label?: string;
options?: {
disabled?: boolean;
label: string;
selected?: boolean;
value: number | string;
}[];
}
export const Select = forwardRef<HTMLSelectElement, SelectProps>(
function Select({ className = '', label, options, ...rest }, ref) {
const id = useId();
return (
<label htmlFor={id}>
{label ? <div className="label">{label}</div> : null}
<select
className={cn(
'focus:border-brand-500 focus:ring-brand-400 w-full rounded-xl border border-gray-300 bg-white outline-none dark:border-gray-700 dark:bg-gray-800',
className
)}
id={id}
ref={ref}
{...rest}
>
{options?.map(({ disabled, label, selected, value }) => (
<option disabled={disabled} selected={selected} value={value}>
{label}
</option>
))}
</select>
</label>
);
}
);