import type { SelectHTMLAttributes } from "react"; export interface SelectOption { value: string; label: string; disabled?: boolean; } export interface SelectProps extends Omit, "size"> { label?: string; error?: string; helperText?: string; fullWidth?: boolean; options: SelectOption[]; placeholder?: string; } export function Select({ label, error, helperText, fullWidth = false, options, placeholder = "Select an option...", className = "", id, ...props }: SelectProps) { const selectId = id || `select-${Math.random().toString(36).substr(2, 9)}`; const errorId = error ? `${selectId}-error` : undefined; const helperId = helperText ? `${selectId}-helper` : undefined; const baseStyles = "px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors bg-white"; const widthStyles = fullWidth ? "w-full" : ""; const errorStyles = error ? "border-red-500 focus:ring-red-500" : "border-gray-300"; const combinedClassName = [baseStyles, widthStyles, errorStyles, className].filter(Boolean).join(" "); return ( {label && ( {label} )} {placeholder} {options.map((option) => ( {option.label} ))} {error && ( {error} )} {helperText && !error && ( {helperText} )} ); }
{error}
{helperText}