'use client'; import type { BaseFormInputProps, WithPlaceholderProps } from '@/components/blocks/asset-form/asset-form-types'; import { getAriaAttributes } from '@/components/blocks/asset-form/asset-form-types'; import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { cn } from '@/lib/utils'; import { useRef } from 'react'; import type { FieldValues } from 'react-hook-form'; type Option = { /** The display text for the option */ label: string; /** The value of the option */ value: string; }; type AssetFormSelectProps = BaseFormInputProps & WithPlaceholderProps & { /** The list of options to display in the select */ options: Option[]; /** The default selected value */ defaultValue?: string; }; /** * A form select component that wraps shadcn's Select component with form field functionality. * Provides a dropdown selection with support for default values and custom options. * * @example * ```tsx * * ``` */ export function AssetFormSelect({ label, description, required, placeholder = 'Select an option', options, className, defaultValue, ...props }: AssetFormSelectProps) { const triggerRef = useRef(null); return ( { const ariaAttrs = getAriaAttributes(field.name, !!fieldState.error, props.disabled); return ( {label && ( {label} {required && *} )} {description && {description}} ); }} /> ); }