/** * @usevyre/react — Form + FormField * * AI CONTEXT: * ┌──────────────────────────────────────────────────────────────────┐ * │ Components: Form, FormField │ * │ Import: import { Form, FormField } from "@usevyre/react" │ * │ │ * │ Controlled, data-driven form. Zero dependencies. Validation runs │ * │ on submit and (after the first submit) on blur. Errors map into │ * │ the wrapped Field automatically (state="error" + hint=message). │ * │ │ * │
│ * │ values? = Record (controlled) │ * │ defaultValues?= Record (uncontrolled) │ * │ onChange? = (values) => void │ * │ onSubmit = (values) => void | Promise (valid only) │ * │ onInvalid? = (errors: Record) => void │ * │ │ * │ │ * │ ← single control child │ * │ │ * │ rules = { required?: boolean | string, │ * │ minLength?, maxLength?, min?, max?: number, │ * │ pattern?: RegExp, email?: boolean, │ * │ validate?: (value, allValues) => string | null } │ * │ │ * │ FormField injects name / value / onChange / onBlur into its │ * │ child and wraps it in . │ * └──────────────────────────────────────────────────────────────────┘ * * @example * const [values, setValues] = useState({ email: "", password: "" }); * signIn(v)} * > * * * * * * * * */ import React from "react"; export interface FormRules { /** Non-empty required. Pass a string to use it as the message. */ required?: boolean | string; /** Minimum string length */ minLength?: number; /** Maximum string length */ maxLength?: number; /** Minimum numeric value */ min?: number; /** Maximum numeric value */ max?: number; /** Must match this pattern */ pattern?: RegExp; /** Must be a valid email address */ email?: boolean; /** Custom validator — return an error message string, or null if valid */ validate?: (value: unknown, allValues: Record) => string | null | undefined; } type Values = Record; type Errors = Record; export interface FormProps extends Omit, "onSubmit" | "onChange" | "onInvalid"> { /** Controlled values map */ values?: Values; /** Initial values when uncontrolled */ defaultValues?: Values; /** Called whenever any field value changes */ onChange?: (values: Values) => void; /** Called with the values when the form is submitted AND valid */ onSubmit?: (values: Values) => void | Promise; /** Called with the error map when submitted but invalid */ onInvalid?: (errors: Errors) => void; } export declare const Form: React.ForwardRefExoticComponent>; export interface FormFieldProps { /** Key into the form's values map */ name: string; /** Label rendered by the wrapping Field */ label?: string; /** Helper text shown when there is no error */ hint?: string; /** Validation rules */ rules?: FormRules; /** Single form control element (Input, Textarea, Select, …) */ children: React.ReactElement; className?: string; } export declare const FormField: React.FC; export {};