import { type Dispatch, type FocusEventHandler, type ReactNode } from 'react'; import type { FormControlState } from '../../../core/types/form-control-state.js'; import { type FormFieldMessagesReducerAction } from '../state/formfield-messages-state-reducer.js'; import type { FormFieldMessageContextState } from '../types/formfield-messages.types.js'; /** * When validation errors first become visible. * - `'immediate'` (default): an error is surfaced as soon as it exists (after * the field is touched). It stays visible and updates live while the user is * editing. * - `'after-blur'`: an error becomes visible on blur. While the user is editing * (focus inside), a shown error stays visible until all errors are resolved, * then clears; a new error raised while editing is held back until the next * blur. Used by complex inputs (e.g. `FilterField`) where intermediate values * are expected to be invalid. * * See `forms/validation/api-proposals/validation-visibility.md`. * @internal */ export type ValidationVisibility = 'immediate' | 'after-blur'; /** * Props for `useFormControl`. Mirrors the inputs of the legacy form-control * hook stack that Strato controls used to call individually. * @internal — Strato controls only. */ export interface UseFormControlProps { /** Control id passed directly to the form control. */ propId?: string; /** Disabled state passed directly to the form control. */ propDisabled?: boolean; /** Aria-disabled state passed directly to the form control. */ propAriaDisabled?: boolean | 'true' | 'false'; /** Required state passed directly to the form control. */ propRequired?: boolean; /** Read-only state passed directly to the form control. */ propReadOnly?: boolean; /** * Legacy `controlState` plumbing for hint/error. * Removed by APPDEV-8298. */ controlState?: FormControlState; /** * When validation errors first become visible. Defaults to `'immediate'`. * @internal */ validationVisibility?: ValidationVisibility; /** * Control-local validation state used by complex controls while their * message-context update has not rendered yet. This does not replace the * message context; it only lets after-blur visibility react in the same * render as the control's own validation state. * Ignored when `validationVisibility === 'immediate'`. * @internal */ hasValidationError?: boolean; } /** @internal */ export interface UseFormControlReturnType { id: string; disabled: boolean | undefined; required: boolean | undefined; readOnly: boolean | undefined; ariaDisabled: boolean | undefined; inputProps: { 'aria-describedby'?: string; 'aria-invalid': boolean; }; hintProps: { id: string; 'aria-live': 'polite'; }; /** Hint content from the legacy `controlState` prop, if any. */ hint: ReactNode; /** True if the control should render error styling right now. Disabled-gated. */ showError: boolean; /** Always present (defaults to empty state when no FormField wraps). */ messageState: FormFieldMessageContextState; /** Undefined when no FormField wraps the control. */ messageDispatch: Dispatch | undefined; /** * Focus handlers for the element that defines "the field". Only * meaningful in `'after-blur'` mode; an empty object otherwise, so callers * can spread it unconditionally. * @internal */ focusHandlers: { onFocus?: FocusEventHandler; onBlur?: FocusEventHandler; }; /** * Mark the field touched and reveal any error immediately, ignoring focus. * Wire to a control's imperative `validate()` so parent-driven validation * paints the error even while focus is still inside the field. No-op in * `'immediate'` mode. * @internal */ markTouched: () => void; } /** * Single entry point for Strato controls to wire id, disabled/required/readOnly * synchronisation with the FormField context, error/hint plumbing, and ARIA * attributes. Has no knowledge of `_Form`; that wiring lives in * `useInternalFormRegistration`. * @internal — Strato controls only. */ export declare function useFormControl({ propId, propDisabled, propAriaDisabled, propRequired, propReadOnly, controlState, validationVisibility, hasValidationError, }: UseFormControlProps): UseFormControlReturnType; //# sourceMappingURL=useFormControl.d.ts.map