import { Label } from "@radix-ui/react-label" import { Input } from "./ui/input" import { FieldName } from "@conform-to/react" import { useId } from "react" import { cn } from "~/utils" import { Checkbox } from "~/components/ui/checkbox" 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: FieldName } & React.ComponentPropsWithoutRef labelProps: React.LabelHTMLAttributes errors?: ListOfErrors className?: string }) => { const fallbackId = useId() const id = inputProps.id ?? fallbackId const errorId = errors?.length ? `${id}-error` : undefined return (
) } export type ListOfErrors = Array | null | undefined export function ErrorList({ id, errors }: { errors?: ListOfErrors id?: string }) { const errorsToRender = errors?.filter(Boolean) if (!errorsToRender?.length) return null return (
    {errorsToRender.map((e) => (
  • {e}
  • ))}
) }