import * as React from 'react'; import { ValidatorData, ValidatorRules, ValidatorMessageGenerator, Omit } from '../../types'; import { FormComponentState } from '../Form'; export interface BoundComponentCommonProps { /** Unique form component identifier */ name: string; /** Whether or not a value is required */ required?: boolean; /** Whether or not the value has been modified */ pristine?: boolean; /** Data which reflects the current validator state for the component. */ validatorData?: ValidatorData; /** Current form component value */ value?: any; /** Should be called when component has been blurred */ onBlur?: (event: any) => void; /** Should be called when component has been focused */ onFocus?: (event: any) => void; } export interface BoundComponentInjectedProps { /** Should be called when component value has changed */ setValue?: BoundComponent['setValue']; } /** Props used by the HOC only. They are not passed to the wrapped component. */ export interface BoundComponentHOCProps { /** Validation rules which should be applied to the component */ validatorRules?: ValidatorRules; /** Custom validator messages for specific validator rules */ validatorMessages?: { [ruleKey: string]: string | ValidatorMessageGenerator; }; /** Triggers validator to execute on the specified component names when this component is modified */ validatorTrigger?: string | string[]; /** Default value to be applied if the component does not have a managed, state or initial value */ defaultValue?: any; } export declare type BoundComponentProps = BoundComponentInjectedProps & BoundComponentCommonProps & BoundComponentHOCProps; /** * Derived form component state from the nearest Form ancestor. This state data is * used instead of `this.state` & `this.setState` to avoid unnecessary renders and * duplicate component state, as the Form should always be the source of truth. */ export interface BoundComponentDerivedState { pristine?: boolean; validatorData?: ValidatorData; value?: any; } export interface BoundComponent extends React.Component { clear: () => Promise; reset: () => Promise; validate: () => Promise; isValid: () => boolean; isPristine: () => boolean; getValidatorData: () => ValidatorData; getValue: () => any; setValidatorData: (data: ValidatorData) => Promise; setValue: (value: any, pristine?: boolean) => Promise; _update: (state: FormComponentState) => Promise; _isRecursive: () => boolean; } export declare function bind(WrappedComponent: React.ComponentClass): WrappedComponentStatics & { /** * Use explicit type for React.Component ref to allow consumers to pass a * React.RefObject` to ref prop of their connected * component. Without explicitly typing this, the inferred type will be wrong. * * The custom ref prop is injected here instead of in the `ComponentProps` * interface so that consumers are able to provide a RefObject, but they're * not able to use it in their wrapped component. */ new (props: WrappedComponentProps): Omit, 'props'> & { props: WrappedComponentProps & { ref?: React.RefObject; unboundRef?: React.RefObject; }; }; };