import { Label } from "@radix-ui/react-label" import { Input } from "./ui/input" import { type FieldName, useInputControl } from "@conform-to/react" import { useId } from "react" import { cn } from "~/utils" import { Checkbox } from "~/components/ui/checkbox" import { Textarea } from "./ui/textarea" export const Field = ({ inputProps, labelProps, errors, className }: { inputProps: { name: FieldName } & React.HTMLProps labelProps: React.LabelHTMLAttributes errors?: ListOfErrors className?: string }) => { const fallbackId = useId() const id = inputProps.id ?? fallbackId const errorId = errors?.length ? `${id}-error` : undefined return (
) } export const FieldCheckbox = ({ inputProps, labelProps, errors, className }: { inputProps: { name: string form: string value?: string } & React.ComponentPropsWithoutRef labelProps: React.LabelHTMLAttributes errors?: ListOfErrors className?: string }) => { const { key, defaultChecked, ...checkboxProps } = inputProps const checkedValue = inputProps.value ?? "on" const input = useInputControl({ key, name: inputProps.name, formId: inputProps.form, initialValue: defaultChecked ? checkedValue : undefined }) const fallbackId = useId() const id = inputProps.id ?? fallbackId const errorId = errors?.length ? `${id}-error` : undefined return ( <>
{ input.change(state.valueOf() ? checkedValue : "") inputProps.onCheckedChange?.(state) }} onFocus={(event) => { input.focus() inputProps.onFocus?.(event) }} onBlur={(event) => { input.blur() inputProps.onBlur?.(event) }} type="button" />
{errorId ? : null}
) } export function TextareaField({ labelProps, textareaProps, errors, className, }: { labelProps: React.LabelHTMLAttributes textareaProps: React.TextareaHTMLAttributes errors?: ListOfErrors className?: string }) { const fallbackId = useId() const id = textareaProps.id ?? textareaProps.name ?? fallbackId const errorId = errors?.length ? `${id}-error` : undefined return (