|
| 1 | +// Type definitions for React Joi Validation |
| 2 | +// Project: react-joi-validation |
| 3 | + |
| 4 | +import { Component } from 'react'; |
| 5 | +import * as Joi from 'joi'; |
| 6 | + |
| 7 | +export function guessCorrectValue(event: Event, value: any): any; |
| 8 | +export function useEventTargetValue(event: Event): any; |
| 9 | +export function useFirstArgument<T>(value: T): T; |
| 10 | +export function useSecondArgument<T>(arg1: any, value: T): T; |
| 11 | +export function useThirdArgument<T>(arg1: any, arg2: any, value: T): T; |
| 12 | + |
| 13 | +type Path = String; |
| 14 | +type ListOrSingle<T> = T|Array<T>; |
| 15 | + |
| 16 | +interface ValidatorComponentProps { |
| 17 | + |
| 18 | +} |
| 19 | + |
| 20 | +interface ValidatedComponentProps extends ValidatorComponentProps { |
| 21 | + errors: object; |
| 22 | + |
| 23 | + changeHandler: (path: Path, options?: { value?: any, strategy?: Function, validate?: boolean, callback?: Function }) => () => void; |
| 24 | + changesHandler: (changes: Array<[Path,any]>, options?: { validate?: boolean, callback?: Function }) => () => void; |
| 25 | + changeValue: (path: Path, value: any, options?: { validate?: boolean, callback?: Function }) => void; |
| 26 | + changeValues: (changes: Array<[Path,any]>, options?: { validate?: boolean, callback?: Function }) => void; |
| 27 | + |
| 28 | + pushHandler: (path: Path, options?: { allowDuplicates?: boolean, value?: any, strategy?: Function, validate?: boolean, callback?: Function }) => () => void; |
| 29 | + pushValue: (path: Path, value: any, options?: { allowDuplicates?: boolean, validate?: boolean, callback?: Function }) => void; |
| 30 | + togglePushHandler: (path: Path, options?: { value?: any, strategy?: Function, validate?: boolean, callback?: Function }) => () => void; |
| 31 | + togglePushValue: (path: Path, value: any, options?: { validate?: boolean, callback?: Function }) => void; |
| 32 | + |
| 33 | + unshiftHandler: (path: Path, options?: { allowDuplicates?: boolean, value?: any, strategy?: Function, validate?: boolean, callback?: Function }) => () => void; |
| 34 | + unshiftValue: (path: Path, value: any, options?: { allowDuplicates?: boolean, validate?: boolean, callback?: Function }) => void; |
| 35 | + toggleUnshiftHandler: (path: Path, options?: { value?: any, strategy?: Function, validate?: boolean, callback?: Function }) => () => void; |
| 36 | + toggleUnshiftValue: (path: Path, value: any, options?: { validate?: boolean, callback?: Function }) => void; |
| 37 | + |
| 38 | + pullHandler: (path: Path, options?: { index?: number, removeAllInstances?: boolean, value?: any, strategy?: Function, validate?: boolean, callback?: Function }) => () => void; |
| 39 | + pullValue: (path: Path, value: any, options?: { index?: number, removeAllInstances?: boolean, validate?: boolean, callback?: Function }) => void; |
| 40 | + |
| 41 | + validateAllHandler: (callback?: Function) => () => void; |
| 42 | + validateAll: (callback?: Function) => void; |
| 43 | + validateHandler: (paths: ListOrSingle<Path>, callback?: Function) => () => void; |
| 44 | + validate: (paths: ListOrSingle<Path>, callback?: Function) => void; |
| 45 | + |
| 46 | + clearValidationAndResetValues: (paths?: ListOrSingle<Path>) => void; |
| 47 | + clearValidation: (paths?: ListOrSingle<Path>) => void; |
| 48 | + clearTouchedValues: () => void; |
| 49 | +} |
| 50 | + |
| 51 | +interface ValidatorComponentPropsWithChildren extends ValidatorComponentProps { |
| 52 | + children: Component<ValidatedComponentProps, object>; |
| 53 | +} |
| 54 | + |
| 55 | +interface ValidatorComponentState { |
| 56 | + errors: object; |
| 57 | + values: object; |
| 58 | + touchedValues: object; |
| 59 | + validatedValues: object; |
| 60 | + changingValues: Array<Path>; |
| 61 | + validatedAllValues: boolean; |
| 62 | +} |
| 63 | + |
| 64 | +interface ValidatorOptions extends ValidatorComponentState { |
| 65 | + valuesWithDefaults: object; |
| 66 | + touchedValues: Array<Path>; |
| 67 | + validatedValues: Array<Path>; |
| 68 | + props: ValidatorComponentProps; |
| 69 | + errors: object; |
| 70 | +} |
| 71 | + |
| 72 | +type ValidatorFunction = (options: ValidatorOptions) => { errors: object, values: object }; |
| 73 | + |
| 74 | +export default function(ValidatedComponent: Component, options: { |
| 75 | + joiSchema?: Joi.Schema, |
| 76 | + joiOptions?: Joi.ValidationOptions, |
| 77 | + validator?: ListOrSingle<ValidatorFunction>, |
| 78 | + only?: ListOrSingle<Path>, |
| 79 | + pseudoValues?: ListOrSingle<Path>, |
| 80 | + externalErrorsPath?: Path, |
| 81 | + changeHandlerStrategy?: Function, |
| 82 | +} = { pseudoValues: [], changeHandlerStrategy: guessCorrectValue }): Component<ValidatorComponentPropsWithChildren, ValidatorComponentState>; |
0 commit comments