1 | import { JSXElementConstructor } from 'react';
|
2 | import { GridSize, GridProps } from '@material-ui/core/Grid';
|
3 | import { OutlinedInputProps } from '@material-ui/core/OutlinedInput';
|
4 | import { StepperProps } from '@material-ui/core/Stepper';
|
5 | import { Breakpoint } from '@material-ui/core/styles/createBreakpoints';
|
6 | import { TextFieldProps } from '@material-ui/core/TextField';
|
7 | import { ActionsFiles } from './inputsTypes/FileInput/Props';
|
8 | import { StepsBuilder, StepValidator, FieldsBuilder, FieldBuilder } from './utils';
|
9 | import { validators, InputValidator, InputsValidator } from './utils/validate';
|
10 | export interface Message {
|
11 | ns?: string;
|
12 | message: string;
|
13 | |
14 |
|
15 |
|
16 | props?: any;
|
17 | }
|
18 | export interface EventField<V = value> {
|
19 | target: {
|
20 | name: string;
|
21 | value: V;
|
22 | type?: string;
|
23 | };
|
24 | }
|
25 | export declare type changeField<V = value> = (e: (EventField<V> | React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) & {
|
26 | field?: FieldBuilder<V>;
|
27 | }, callback?: () => void) => void | (() => void);
|
28 | export declare type onSetValue<V = value> = (e: {
|
29 | lastValue: V;
|
30 | newValue: V;
|
31 | field: FieldBuilder<V>;
|
32 | }) => void;
|
33 | export interface ChangeField<V = value> {
|
34 | changeField?: changeField<V>;
|
35 | }
|
36 | export declare type value = any;
|
37 | export declare type GlobalProps = () => {
|
38 | [key: string]: any;
|
39 | };
|
40 | export declare type transPosition = string | boolean;
|
41 | export declare type activeStep = number;
|
42 | export interface InitialState {
|
43 | ns?: string;
|
44 | }
|
45 | interface GlobalPropsInterface {
|
46 | globalProps?: GlobalProps;
|
47 | }
|
48 | export 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 | }
|
59 | export declare function buildFields(a: PropsField[]): PropsField[];
|
60 | export declare type FieldsAll = PropsField[];
|
61 | export interface InitialStateFields extends InitialState, GlobalPropsInterface {
|
62 | validate?: boolean | ((inputsValidator: InputsValidator) => boolean);
|
63 | fields: PropsField[];
|
64 | }
|
65 | export interface ChangeValueField<V = value> {
|
66 | field: FieldBuilder;
|
67 | action: EventField<V>['target'];
|
68 | }
|
69 | export interface ChangeValueFields<V = value> {
|
70 | fieldsBuilder: FieldsBuilder;
|
71 | action: EventField<V>['target'];
|
72 | }
|
73 | export interface ChangeValueSteps {
|
74 | activeStep: activeStep;
|
75 | steps: StepValidator[];
|
76 | action: ChangeValueFields['action'];
|
77 | }
|
78 | export declare type ValidateInputsValidator = ValidationsFields['validate'];
|
79 | interface GridRender {
|
80 | /**
|
81 | * @default true
|
82 | */
|
83 | grid?: boolean;
|
84 | }
|
85 | export interface FieldsProps extends InitialState, GlobalPropsInterface, ValidationsFields, GridRender {
|
86 | fields: PropsField[];
|
87 | }
|
88 | export interface StepProps extends FieldsProps {
|
89 | label: Message | string;
|
90 | stepper?: boolean;
|
91 | elevation?: number;
|
92 | }
|
93 | export 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 | }
|
108 | export declare type Rules = keyof typeof validators;
|
109 | export interface Validation extends Message {
|
110 | rule: Rules;
|
111 | args?: any;
|
112 | }
|
113 | export interface AllPropsValidationFunction<V = value> extends Partial<Validate<V>> {
|
114 | fieldsBuilder?: FieldsBuilder;
|
115 | field: FieldBuilder<V>;
|
116 | stepsBuilder?: StepsBuilder;
|
117 | activeStep?: activeStep;
|
118 | }
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | export declare type ValidationError = string | React.ReactElement<any> | Message;
|
126 | export declare type ValidationErrors = ValidationError[];
|
127 | export declare type ReturnValidationError = undefined | void | ValidationError;
|
128 | export declare type ValidationFunction<V = value> = (all: AllPropsValidationFunction<V>) => ReturnValidationError | Promise<ReturnValidationError>;
|
129 | export interface Validations<V = value> {
|
130 | validate?: boolean | ((arg: any) => boolean);
|
131 | value: V;
|
132 | validations?: (Validation | ValidationFunction<V>)[];
|
133 | }
|
134 | export interface ValidationsField<V = value> extends Validations<V> {
|
135 | validate?: boolean | ((inputValidator: InputValidator<V>) => boolean);
|
136 | }
|
137 | export interface ValidationsFields {
|
138 | validate?: boolean | ((inputsValidator: InputsValidator) => boolean);
|
139 | }
|
140 | export 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 | }
|
162 | export declare type ChildrenRender = React.ReactElement<FieldProps, JSXElementConstructor<FieldProps>>;
|
163 | export declare type RenderField = (element: {
|
164 | children: ChildrenRender;
|
165 | props: FieldProps;
|
166 | }) => React.CElement<any, any>;
|
167 | export declare type ComponentField = React.ElementType<FieldProps>;
|
168 | export interface ComponentErrorsProps<V = any> {
|
169 | errors: ValidationErrors;
|
170 | field?: FieldBuilder<V>;
|
171 | }
|
172 | export declare type ComponentErrors<V = any> = React.ElementType<ComponentErrorsProps<V>>;
|
173 | export declare type TypeTextField = 'date' | 'email' | 'number' | 'password' | 'search' | 'tel' | 'text' | 'time' | 'url' | 'week' | 'datetime-local';
|
174 | export declare type TypeField = 'component' | 'file' | TypeTextField;
|
175 | export declare function createField<V = value>(params: PropsField<V>): PropsField<V>;
|
176 | export 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'>;
|
177 | export declare type LabelPropsField = string | React.ReactElement<any> | Message;
|
178 | export declare type InputPropsField = ((a: {
|
179 | type: InputProps['type'];
|
180 | changeType: (type: InputProps['type'], callback?: () => void) => void;
|
181 | } & BaseRender) => Partial<OutlinedInputProps>) | Partial<OutlinedInputProps>;
|
182 | export declare type BreakpointsField = Partial<Record<Breakpoint, boolean | GridSize>>;
|
183 | export declare enum StatusField {
|
184 | 'VALID' = "VALID",
|
185 | 'INVALID' = "INVALID",
|
186 | 'PENDING' = "PENDING",
|
187 | 'DISABLED' = "DISABLED"
|
188 | }
|
189 | export interface PropsFieldBase<V = value> {
|
190 | type?: TypeField;
|
191 | name: string;
|
192 | alias?: string[];
|
193 | value: V;
|
194 | disabled?: boolean;
|
195 | defaultInputValue?: V;
|
196 | label?: LabelPropsField;
|
197 | onChange?: changeField<V>;
|
198 | onSetValue?: onSetValue<V>;
|
199 | }
|
200 | export interface PropsField<V = value> extends PropsFieldBase<V>, ValidationsField<V>, InitialState, GridRender {
|
201 | extraProps?: ExtraProps;
|
202 | render?: RenderField;
|
203 | fullWidth?: boolean;
|
204 | errors?: ValidationErrors;
|
205 | autoComplete?: string;
|
206 | InputProps?: InputPropsField;
|
207 | textFieldProps?: TextFieldPropsField;
|
208 | breakpoints?: BreakpointsField;
|
209 | component?: ComponentField;
|
210 | renderErrors?: ComponentErrors<V>;
|
211 | }
|
212 | export interface Validate<V = value> extends Validations<V> {
|
213 | state?: boolean;
|
214 | }
|
215 | export interface BaseRender<V = value> {
|
216 | field: FieldBuilder<V>;
|
217 | }
|
218 | export interface FieldProps<V = value> extends BaseRender<V>, ChangeField, GridRender {
|
219 | }
|
220 | export interface InputProps extends FieldProps {
|
221 | type?: TypeTextField;
|
222 | }
|
223 | export interface BaseBuilder<V = value> extends ChangeField<V> {
|
224 | getSteps?: () => StepProps[];
|
225 | activeStep?: activeStep;
|
226 | getFields?: () => PropsField[];
|
227 | }
|
228 | export declare type FieldRenderProps<V = value> = BaseBuilder<V> & BaseRender<V>;
|
229 | export declare type FieldsRenderProps = FieldsProps & BaseBuilder;
|
230 | export declare type FieldRenderComponentProps<V = value> = FieldRenderProps<V>;
|
231 | export {};
|