import { forwardRef, useId, type InputHTMLAttributes, type TextareaHTMLAttributes, type ReactNode, } from "react"; import s from "./Field.module.css"; interface BaseProps { label?: ReactNode; hint?: ReactNode; error?: ReactNode; required?: boolean; } export interface TextFieldProps extends Omit, "size">, BaseProps {} export interface TextAreaProps extends TextareaHTMLAttributes, BaseProps {} function Wrap(props: { id: string; label?: ReactNode; hint?: ReactNode; error?: ReactNode; required?: boolean; children: ReactNode; }) { const { id, label, hint, error, required, children } = props; return (
{label && ( )} {children} {error ?
{error}
: hint ?
{hint}
: null}
); } export const TextField = forwardRef((props, ref) => { const { id, label, hint, error, required, className, ...rest } = props; const auto = useId(); const inputId = id ?? auto; const cls = [ s.input, error ? s.invalid : "", className ?? "" ] .filter(Boolean).join(" "); return ( ); }); TextField.displayName = "TextField"; export const TextArea = forwardRef((props, ref) => { const { id, label, hint, error, required, className, ...rest } = props; const auto = useId(); const inputId = id ?? auto; const cls = [ s.textarea, error ? s.invalid : "", className ?? "" ] .filter(Boolean).join(" "); return (