import { forwardRef, useId } from "react"; import { inputVariants } from "@cloudflare/kumo/components/input"; import { Label } from "@cloudflare/kumo/components/label"; import { Select as KumoSelect } from "@cloudflare/kumo/components/select"; import { cn } from "~/utils/cn"; const CONTROL = cn(inputVariants({ focusIndicator: true }), "w-full disabled:opacity-60"); const ERROR_CONTROL = cn(inputVariants({ variant: "error", focusIndicator: true }), "w-full disabled:opacity-60"); function controlClass(error: string | null | undefined, className?: string): string { return cn(error ? ERROR_CONTROL : CONTROL, className); } type FieldShellProps = { label: string; hint?: string; error?: string | null; id: string; children: React.ReactNode; }; function FieldShell({ label, hint, error, id, children }: FieldShellProps) { return (
{children} {hint && !error && (

{hint}

)} {error && {error}}
); } function describedBy(id: string, hint?: string, error?: string | null): string | undefined { if (error) return `${id}-error`; if (hint) return `${id}-hint`; return undefined; } type InputProps = Omit, "id"> & { label: string; hint?: string; error?: string | null; }; export const TextField = forwardRef(function TextField( { label, hint, error, className, ...rest }, ref, ) { const id = useId(); return ( ); }); TextField.displayName = "TextField"; type TextAreaProps = Omit, "id"> & { label: string; hint?: string; error?: string | null; }; export const TextAreaField = forwardRef(function TextAreaField( { label, hint, error, className, ...rest }, ref, ) { const id = useId(); return (