import * as React from 'react'; import { Prompt } from '../Prompt'; import { StandardProps } from '../../common'; import { ReactComponentDefaultProps } from '../../utils/react-18-compat'; export interface FormSubmitEvent { /** * The data to be submitted. */ data: FormValuesData; /** * Validation errors */ errors?: Array; /** * Indicates whether the data has changed from the initial state. */ changed: boolean; } export interface FormChangeEvent { /** * The current values of the form fields. */ value: FormValuesData; /** * Indicates whether the data has changed from the initial state. */ changed: boolean; } export interface FormValidateEvent { /** * The current values of the form fields. */ value: FormValuesData; /** * Validation errors */ errors?: Array; } export interface FormValuesData { [name: string]: any; } export interface FormValidationError { field: string; error: React.ReactChild; } export interface FormProps extends StandardProps, ReactComponentDefaultProps { /** * Shows the given message if the user wants to navigate * with changes being made or renders custom component with message if provided. */ prompt?: ((changed: boolean) => React.ReactChild) | string; /** * The value of the form to be used in controlled mode. */ value?: FormValues; /** * The initial value of the form to be used in managed mode. */ defaultValue?: FormValues; /** * Rules for validating fields values. */ validationRules?: { [T in keyof FormValues]?: (value: any, formValues: FormValues) => React.ReactChild | true; }; /** * Event emitted when a field of the form changed. */ onChange?(e: FormChangeEvent): void; /** * Event emitted when the form is submitted. */ onSubmit?(e: FormSubmitEvent): void; /** * Event emitted when form errors are set or cleared */ onValidate?(e: FormValidateEvent): void; /** * Disables the form in case of invalid input. Effectively * disables the possibility of submitting forms. * @default false */ disabled?: boolean; } export interface FormState { changed: boolean; initial: FormValues; controlled: boolean; current: FormValues; errors: Partial<{ [T in keyof FormValues]: React.ReactChild; }>; } /** * Represents a field aggregator that enables easily creating forms. */ export declare class Form extends React.Component, FormState> { private readonly fields; private readonly ctx; constructor(props: FormProps); UNSAFE_componentWillReceiveProps(nextProps: FormProps): void; componentDidUpdate(_: FormProps, prevState: FormState): void; private getErrorsAsArray; private setValues; private getError; private setFieldError; private setError; private setErrors; private createContext; private submit; render(): JSX.Element; static inner: { readonly StyledForm: any; readonly Prompt: typeof Prompt; }; }