UNPKG

8.78 kBTypeScriptView Raw
1import { JSXElementConstructor } from 'react';
2import { GridSize, GridProps } from '@material-ui/core/Grid';
3import { OutlinedInputProps } from '@material-ui/core/OutlinedInput';
4import { StepperProps } from '@material-ui/core/Stepper';
5import { Breakpoint } from '@material-ui/core/styles/createBreakpoints';
6import { TextFieldProps } from '@material-ui/core/TextField';
7import { ActionsFiles } from './inputsTypes/FileInput/Props';
8import { StepsBuilder, StepValidator, FieldsBuilder, FieldBuilder } from './utils';
9import { validators, InputValidator, InputsValidator } from './utils/validate';
10export interface Message {
11 ns?: string;
12 message: string;
13 /**
14 * @description Properties to be passed to translate
15 */
16 props?: any;
17}
18export interface EventField<V = value> {
19 target: {
20 name: string;
21 value: V;
22 type?: string;
23 };
24}
25export declare type changeField<V = value> = (e: (EventField<V> | React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) & {
26 field?: FieldBuilder<V>;
27}, callback?: () => void) => void | (() => void);
28export declare type onSetValue<V = value> = (e: {
29 lastValue: V;
30 newValue: V;
31 field: FieldBuilder<V>;
32}) => void;
33export interface ChangeField<V = value> {
34 changeField?: changeField<V>;
35}
36export declare type value = any;
37export declare type GlobalProps = () => {
38 [key: string]: any;
39};
40export declare type transPosition = string | boolean;
41export declare type activeStep = number;
42export interface InitialState {
43 ns?: string;
44}
45interface GlobalPropsInterface {
46 globalProps?: GlobalProps;
47}
48export interface InitialStateSteps extends InitialState, GlobalPropsInterface {
49 validate?: boolean;
50 steps: StepProps[];
51 activeStep: activeStep;
52 loading?: boolean;
53 footerSteps?: {
54 [key: number]: Record<'next' | 'back', Message & {
55 state?: boolean;
56 }>;
57 };
58}
59export declare function buildFields(a: PropsField[]): PropsField[];
60export declare type FieldsAll = PropsField[];
61export interface InitialStateFields extends InitialState, GlobalPropsInterface {
62 validate?: boolean | ((inputsValidator: InputsValidator) => boolean);
63 fields: PropsField[];
64}
65export interface ChangeValueField<V = value> {
66 field: FieldBuilder;
67 action: EventField<V>['target'];
68}
69export interface ChangeValueFields<V = value> {
70 fieldsBuilder: FieldsBuilder;
71 action: EventField<V>['target'];
72}
73export interface ChangeValueSteps {
74 activeStep: activeStep;
75 steps: StepValidator[];
76 action: ChangeValueFields['action'];
77}
78export declare type ValidateInputsValidator = ValidationsFields['validate'];
79interface GridRender {
80 /**
81 * @default true
82 */
83 grid?: boolean;
84}
85export interface FieldsProps extends InitialState, GlobalPropsInterface, ValidationsFields, GridRender {
86 fields: PropsField[];
87}
88export interface StepProps extends FieldsProps {
89 label: Message | string;
90 stepper?: boolean;
91 elevation?: number;
92}
93export interface StepsRender extends ChangeField {
94 footerRender?: ({ stepsLength, activeStep, footerSteps, }: {
95 stepsLength: number;
96 activeStep: activeStep;
97 footerSteps: Partial<InitialStateSteps['footerSteps']>;
98 }) => Record<'next' | 'back', Message & {
99 state?: boolean;
100 }>;
101 handleNextStep: (activeStep: activeStep) => void;
102 handleBackStep: (activeStep: activeStep) => void;
103 gridProps?: Omit<GridProps, 'children'>;
104 stepperProps?: Omit<StepperProps, 'activeStep' | 'children'>;
105 getSteps?: () => StepProps[];
106 stepsBuild: InitialStateSteps;
107}
108export declare type Rules = keyof typeof validators;
109export interface Validation extends Message {
110 rule: Rules;
111 args?: any;
112}
113export interface AllPropsValidationFunction<V = value> extends Partial<Validate<V>> {
114 fieldsBuilder?: FieldsBuilder;
115 field: FieldBuilder<V>;
116 stepsBuilder?: StepsBuilder;
117 activeStep?: activeStep;
118}
119/**
120 * @description
121 * Defines the map of errors returned from failed validation checks.
122 *
123 * @publicApi
124 */
125export declare type ValidationError = string | React.ReactElement<any> | Message;
126export declare type ValidationErrors = ValidationError[];
127export declare type ReturnValidationError = undefined | void | ValidationError;
128export declare type ValidationFunction<V = value> = (all: AllPropsValidationFunction<V>) => ReturnValidationError | Promise<ReturnValidationError>;
129export interface Validations<V = value> {
130 validate?: boolean | ((arg: any) => boolean);
131 value: V;
132 validations?: (Validation | ValidationFunction<V>)[];
133}
134export interface ValidationsField<V = value> extends Validations<V> {
135 validate?: boolean | ((inputValidator: InputValidator<V>) => boolean);
136}
137export interface ValidationsFields {
138 validate?: boolean | ((inputsValidator: InputsValidator) => boolean);
139}
140export interface ExtraProps extends ActionsFiles {
141 helpMessage?: boolean;
142 searchField?: string | number | ((e: PropsField[]) => string | number);
143 searchId?: string;
144 search?: {
145 state: boolean;
146 value: string | number;
147 };
148 renderItem?: React.ReactNode;
149 timeConsult?: number;
150 actions?: {
151 onDelete(e: any): any;
152 onAdd(e: any): any;
153 };
154 loading?: boolean;
155 accept?: string | string[];
156 extensions?: string[];
157 multiple?: boolean;
158 validateExtensions?: boolean;
159 validateAccept?: boolean;
160 subLabel?: Message;
161}
162export declare type ChildrenRender = React.ReactElement<FieldProps, JSXElementConstructor<FieldProps>>;
163export declare type RenderField = (element: {
164 children: ChildrenRender;
165 props: FieldProps;
166}) => React.CElement<any, any>;
167export declare type ComponentField = React.ElementType<FieldProps>;
168export interface ComponentErrorsProps<V = any> {
169 errors: ValidationErrors;
170 field?: FieldBuilder<V>;
171}
172export declare type ComponentErrors<V = any> = React.ElementType<ComponentErrorsProps<V>>;
173export declare type TypeTextField = 'date' | 'email' | 'number' | 'password' | 'search' | 'tel' | 'text' | 'time' | 'url' | 'week' | 'datetime-local';
174export declare type TypeField = 'component' | 'file' | TypeTextField;
175export declare function createField<V = value>(params: PropsField<V>): PropsField<V>;
176export declare type TextFieldPropsField = Pick<TextFieldProps, 'multiline' | 'rows' | 'autoComplete' | 'autoFocus' | 'color' | 'defaultValue' | 'disabled' | 'FormHelperTextProps' | 'fullWidth' | 'helperText' | 'id' | 'InputLabelProps' | 'inputRef' | 'label' | 'margin' | 'placeholder' | 'required' | 'rowsMax' | 'select' | 'SelectProps'>;
177export declare type LabelPropsField = string | React.ReactElement<any> | Message;
178export declare type InputPropsField = ((a: {
179 type: InputProps['type'];
180 changeType: (type: InputProps['type'], callback?: () => void) => void;
181} & BaseRender) => Partial<OutlinedInputProps>) | Partial<OutlinedInputProps>;
182export declare type BreakpointsField = Partial<Record<Breakpoint, boolean | GridSize>>;
183export declare enum StatusField {
184 'VALID' = "VALID",
185 'INVALID' = "INVALID",
186 'PENDING' = "PENDING",
187 'DISABLED' = "DISABLED"
188}
189export interface PropsFieldBase<V = value> {
190 type?: TypeField;
191 name: string;
192 value: V;
193 disabled?: boolean;
194 defaultInputValue?: V;
195 label?: LabelPropsField;
196 onChange?: changeField<V>;
197 onSetValue?: onSetValue<V>;
198}
199export interface PropsField<V = value> extends PropsFieldBase<V>, ValidationsField<V>, InitialState, GridRender {
200 extraProps?: ExtraProps;
201 render?: RenderField;
202 fullWidth?: boolean;
203 errors?: ValidationErrors;
204 autoComplete?: string;
205 InputProps?: InputPropsField;
206 textFieldProps?: TextFieldPropsField;
207 breakpoints?: BreakpointsField;
208 component?: ComponentField;
209 renderErrors?: ComponentErrors<V>;
210}
211export interface Validate<V = value> extends Validations<V> {
212 state?: boolean;
213}
214export interface BaseRender<V = value> {
215 field: FieldBuilder<V>;
216}
217export interface FieldProps<V = value> extends BaseRender<V>, ChangeField, GridRender {
218}
219export interface InputProps extends FieldProps {
220 type?: TypeTextField;
221}
222export interface BaseBuilder<V = value> extends ChangeField<V> {
223 getSteps?: () => StepProps[];
224 activeStep?: activeStep;
225 getFields?: () => PropsField[];
226}
227export declare type FieldRenderProps<V = value> = BaseBuilder<V> & BaseRender<V>;
228export declare type FieldsRenderProps = FieldsProps & BaseBuilder;
229export declare type FieldRenderComponentProps<V = value> = FieldRenderProps<V>;
230export {};