import { forwardRef, SelectHTMLAttributes } from 'react'; import { Box } from './Box'; import { Text } from './Text'; export interface SelectOption { value: string | number; label: string; } export interface SelectProps extends Omit, 'size'> { label?: string; options: SelectOption[]; error?: string; hint?: string; fullWidth?: boolean; size?: 'sm' | 'md' | 'lg'; pl?: number; } export const Select = forwardRef(({ label, options, error, hint, fullWidth = false, size = 'md', pl, ...props }, ref) => { const sizeClasses = { sm: 'px-3 py-1.5 text-xs', md: 'px-4 py-2 text-sm', lg: 'px-4 py-3 text-base' }; const baseClasses = 'bg-[var(--ui-color-bg-surface)] border border-[var(--ui-color-border-default)] text-[var(--ui-color-text-high)] focus:outline-none focus:border-[var(--ui-color-intent-primary)] transition-colors appearance-none'; const errorClasses = error ? 'border-[var(--ui-color-intent-critical)]' : ''; const widthClasses = fullWidth ? 'w-full' : ''; const classes = [ baseClasses, sizeClasses[size], errorClasses, widthClasses, ].filter(Boolean).join(' '); const style: React.CSSProperties = { ...(pl !== undefined ? { paddingLeft: `${pl * 0.25}rem` } : {}), }; return ( {label && ( {label} )}
{error && ( {error} )} {hint && !error && ( {hint} )}
); }); Select.displayName = 'Select';