UNPKG

form-container

Version:

Lightweight React form container with validation (written in TypeScript)

98 lines (91 loc) 3.46 kB
// Generated by dts-bundle v0.7.3 // Dependencies for this module: // ../../react // ../../es6-error declare module 'form-container' { export { connectForm } from 'form-container/FormContainer'; export { IFormProps, IFormConfig, ValidationRule, ValidationType } from 'form-container/interfaces'; export { ValidationRuleFactory } from 'form-container/validators'; export { SubmissionError } from 'form-container/SubmissionError'; } declare module 'form-container/FormContainer' { import { IFormConfig } from 'form-container/interfaces'; export const connectForm: <T extends {} = any>(validators?: any[], config?: IFormConfig<T, object>) => (Component: any) => any; } declare module 'form-container/interfaces' { import * as React from 'react'; export type ComponentInstance<P = any, S = any> = new () => React.Component<P, S>; export type Validator = (model: any, allProps?: any) => boolean; export type ErrorMessage = { [name: string]: string | undefined; }; export type Condition = (value: string) => boolean; export type ValidationRule = <T = any>(prop: keyof T, errorMessage: string, type?: ValidationType) => ValidationRuleResult; export type ValidationRuleResult = [Validator, ErrorMessage, ValidationType]; export enum ValidationType { Error = "error", Warning = "warning", } export interface IBoundInput { name: string; value: string; onChange: (e: React.ChangeEvent<any>) => void; onFocus: (e: React.FocusEvent<any>) => void; onBlur: (e: React.FocusEvent<any>) => void; ref?: (input: any) => void; } export interface IFormMethods<T = any> { bindInput: (name: keyof T) => IBoundInput; bindNativeInput: (name: keyof T) => IBoundInput; bindToChangeEvent: (e: React.ChangeEvent<any>) => void; setProperty: (prop: keyof T, value: T[keyof T]) => any; clearSubmitError: (props: keyof T) => void; setModel: (model: { [name in keyof T]?: any; }) => any; setFieldToTouched: (prop: keyof T) => any; handleSubmit: <T = any>(submit: (model: any) => Promise<T>) => () => any; } export interface IFormProps<T = any> { form: { model: any; inputs: any; isValid?: boolean; submitErrors: { [key in keyof T]: string; }; validationErrors: { [key in keyof T]: string; }; validationWarnings: { [key in keyof T]: string; }; touched: { [key: string]: boolean; }; }; formMethods: IFormMethods<T>; initialModel?: any; } export interface IFormConfig<T = object, M = object> { initialModel?: Partial<T>; onInputBlur?: (e: React.FocusEvent<any>) => any; middleware?: (props: T) => T & M; } } declare module 'form-container/validators' { export const ValidationRuleFactory: any; export const hasError: any; } declare module 'form-container/SubmissionError' { import ExtendableError from 'es6-error'; export class SubmissionError<T = any> extends ExtendableError { errors: { [key in keyof T]: string; }; constructor(errors: { [key in keyof T]: string; }); } export default SubmissionError; }