/** * FormSelect Component * * Reusable Select field with Controller integration for react-hook-form. * Handles label, error display, and description automatically. * * @module components/forms/FormSelect */ 'use client'; import { Controller, type Control, type FieldValues, type Path } from 'react-hook-form'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; export interface SelectOption { value: string; label: string; } export interface FormSelectProps { /** Field name (must be a valid path in the form) */ name: Path; /** Form control from useForm */ control: Control; /** Field label */ label: string; /** Available options */ options: SelectOption[]; /** Is field required? Shows asterisk if true */ required?: boolean; /** Placeholder text when no value selected */ placeholder?: string; /** Helper text below the field */ description?: string; /** Disable the select */ disabled?: boolean; /** Additional class name */ className?: string; } /** * FormSelect - Controlled Select field for react-hook-form * * Automatically handles: * - Controller wrapper for react-hook-form * - Label with required indicator * - Error message display * - Description/helper text * - Accessibility attributes * * @example * ```tsx * * ``` */ export function FormSelect({ name, control, label, options, required = false, placeholder, description, disabled = false, className, }: FormSelectProps) { const selectId = String(name); const errorId = `${selectId}-error`; const descriptionId = description ? `${selectId}-description` : undefined; return ( (
{fieldState.error && ( )} {description && (

{description}

)}
)} /> ); }