import React, { forwardRef, useId } from "react"; import FormField, { FormFieldProps } from "./form-field"; import { cn } from "~/lib/utils"; import { Controller, FieldValues, Path } from "react-hook-form"; import { useFormReturn } from "~/hooks/useForm"; export type SelectItem = { label: string; value: string; }; type BaseSelectProps = React.ComponentPropsWithoutRef<"select"> & FormFieldProps & { inputClassName?: string; items?: SelectItem[] | null; }; const BaseSelect = forwardRef( (props, ref) => { const { className, label, error, inputClassName, items, ...restProps } = props; const id = useId(); const input = ( ); if (label || error) { return ( ); } return input; } ); type SelectProps = Omit< BaseSelectProps, "form" | "name" > & { form?: useFormReturn; name?: Path; }; const Select = (props: SelectProps) => { const { form, ...restProps } = props; if (form && props.name) { return ( ( )} /> ); } return ; }; export default Select;