react-mui-form-validator 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,169 @@
1
+ import * as React$1 from 'react';
2
+ import React__default from 'react';
3
+ import { FilledTextFieldProps, OutlinedTextFieldProps, StandardTextFieldProps, BoxProps } from '@mui/material';
4
+ import { MuiTelInputInfo } from 'mui-tel-input';
5
+
6
+ interface required {
7
+ validator: "required";
8
+ }
9
+ interface matchRegexp {
10
+ validator: "matchRegexp";
11
+ regexp: RegExp | string;
12
+ }
13
+ interface isEmail {
14
+ validator: "isEmail";
15
+ }
16
+ interface isEmpty {
17
+ validator: "isEmpty";
18
+ }
19
+ interface trim {
20
+ validator: "trim";
21
+ }
22
+ interface isNumber {
23
+ validator: "isNumber";
24
+ }
25
+ interface isFloat {
26
+ validator: "isFloat";
27
+ }
28
+ interface isPositive {
29
+ validator: "isPositive";
30
+ }
31
+ interface maxNumber {
32
+ validator: "maxNumber";
33
+ max: number;
34
+ }
35
+ interface minNumber {
36
+ validator: "minNumber";
37
+ min: number;
38
+ }
39
+ interface maxFloat {
40
+ validator: "maxFloat";
41
+ max: number;
42
+ }
43
+ interface minFloat {
44
+ validator: "minFloat";
45
+ min: number;
46
+ }
47
+ interface isString {
48
+ validator: "isString";
49
+ }
50
+ interface minStringLength {
51
+ validator: "minStringLength";
52
+ min: number;
53
+ }
54
+ interface maxStringLength {
55
+ validator: "maxStringLength";
56
+ max: number;
57
+ }
58
+ interface isFile {
59
+ validator: "isFile";
60
+ }
61
+ interface maxFileSize {
62
+ validator: "maxFileSize";
63
+ max: number;
64
+ }
65
+ interface allowedExtensions {
66
+ validator: "allowedExtensions";
67
+ fileTypes: string;
68
+ }
69
+ type Validator = required | matchRegexp | isEmail | isEmpty | trim | isNumber | isFloat | isPositive | maxNumber | minNumber | maxFloat | minFloat | isString | minStringLength | maxStringLength | isFile | maxFileSize | allowedExtensions;
70
+
71
+ type ComponentProps = {
72
+ errorMessages?: string | string[];
73
+ validators?: Validator[];
74
+ value: any;
75
+ validatorListener?: (value: boolean) => void;
76
+ withRequiredValidator?: boolean;
77
+ containerProps?: object;
78
+ onChangeTel: (value: string, info: MuiTelInputInfo) => void;
79
+ };
80
+ type ValidatorComponentProps = (FilledTextFieldProps | OutlinedTextFieldProps | StandardTextFieldProps) & ComponentProps;
81
+ interface ValidatorComponentState {
82
+ isValid?: boolean;
83
+ value: any;
84
+ errorMessages?: string | string[];
85
+ validators?: Validator[];
86
+ }
87
+ interface ValidatorFormProps {
88
+ children: React.ReactNode;
89
+ onSubmit: () => void;
90
+ instantValidate?: boolean;
91
+ onError?: (errors: any) => void;
92
+ debounceTime?: number;
93
+ }
94
+
95
+ declare class ValidatorForm extends React$1.Component<ValidatorFormProps & BoxProps> {
96
+ static getValidator: (validator: Validator, value: any, includeRequired: boolean) => boolean;
97
+ getFormHelpers: () => {
98
+ form: {
99
+ attachToForm: (component: any) => void;
100
+ detachFromForm: (component: any) => void;
101
+ instantValidate: boolean;
102
+ debounceTime: number;
103
+ };
104
+ };
105
+ instantValidate: boolean;
106
+ childs: any[];
107
+ errors: any[];
108
+ debounceTime: number;
109
+ attachToForm: (component: any) => void;
110
+ detachFromForm: (component: any) => void;
111
+ submit: (event: React$1.FormEvent<HTMLFormElement>) => void;
112
+ walk: (children: any[], dryRun?: boolean) => Promise<boolean>;
113
+ checkInput: (input: any, dryRun?: boolean) => Promise<boolean>;
114
+ validate: (input: any, includeRequired: boolean, dryRun?: boolean) => Promise<boolean>;
115
+ find: (collection: any[], fn: (item: any) => boolean) => any;
116
+ resetValidations: () => void;
117
+ isFormValid: (dryRun?: boolean) => Promise<boolean>;
118
+ render(): React$1.JSX.Element;
119
+ }
120
+
121
+ declare class ValidatorComponent extends React$1.Component<ValidatorComponentProps, ValidatorComponentState> {
122
+ renderValidatorComponent(): React$1.ReactNode;
123
+ validateDebounced: any;
124
+ form: any;
125
+ debounceTime: any;
126
+ getSnapshotBeforeUpdate(nextProps: ValidatorComponentProps, prevState: ValidatorComponentState): {
127
+ value: any;
128
+ validators: Validator[];
129
+ errorMessages: string | string[];
130
+ } | {
131
+ value: any;
132
+ validators?: undefined;
133
+ errorMessages?: undefined;
134
+ };
135
+ state: {
136
+ isValid: boolean;
137
+ value: any;
138
+ errorMessages: string | string[] | undefined;
139
+ validators: Validator[] | undefined;
140
+ };
141
+ componentDidMount(): void;
142
+ shouldComponentUpdate(nextProps: ValidatorComponentProps, nextState: ValidatorComponentState): boolean;
143
+ componentDidUpdate(prevProps: ValidatorComponentProps, prevState: ValidatorComponentState): void;
144
+ componentWillUnmount(): void;
145
+ getErrorMessage: () => string | boolean | string[];
146
+ instantValidate: boolean;
147
+ invalid: number[];
148
+ configure: () => void;
149
+ validate: (value: any, includeRequired?: boolean, dryRun?: boolean) => Promise<boolean>;
150
+ isValid: () => boolean;
151
+ makeInvalid: () => void;
152
+ makeValid: () => void;
153
+ renderComponent: (form: ValidatorForm) => React$1.ReactNode;
154
+ render(): React$1.JSX.Element;
155
+ }
156
+
157
+ declare class MuiSelect extends ValidatorComponent {
158
+ renderValidatorComponent(): React$1.JSX.Element;
159
+ }
160
+
161
+ declare class MuiTextField extends ValidatorComponent {
162
+ renderValidatorComponent(): React__default.JSX.Element;
163
+ }
164
+
165
+ declare class MuiTelInputDefault extends ValidatorComponent {
166
+ renderValidatorComponent(): React__default.JSX.Element;
167
+ }
168
+
169
+ export { ValidatorComponent as MuiComponent, ValidatorForm as MuiForm, MuiTelInputDefault as MuiPhoneNumber, MuiSelect, MuiTextField, type Validator as MuiValidator };
package/lib/index.d.ts CHANGED
@@ -1,179 +1,169 @@
1
1
  import * as React$1 from 'react';
2
2
  import React__default from 'react';
3
3
  import { FilledTextFieldProps, OutlinedTextFieldProps, StandardTextFieldProps, BoxProps } from '@mui/material';
4
- import { CountryCode, NumberType } from 'libphonenumber-js';
4
+ import { MuiTelInputInfo } from 'mui-tel-input';
5
5
 
6
- interface required {
7
- validator: "required";
8
- }
9
- interface matchRegexp {
10
- validator: "matchRegexp";
11
- regexp: RegExp | string;
12
- }
13
- interface isEmail {
14
- validator: "isEmail";
15
- }
16
- interface isEmpty {
17
- validator: "isEmpty";
18
- }
19
- interface trim {
20
- validator: "trim";
21
- }
22
- interface isNumber {
23
- validator: "isNumber";
24
- }
25
- interface isFloat {
26
- validator: "isFloat";
27
- }
28
- interface isPositive {
29
- validator: "isPositive";
30
- }
31
- interface maxNumber {
32
- validator: "maxNumber";
33
- max: number;
34
- }
35
- interface minNumber {
36
- validator: "minNumber";
37
- min: number;
38
- }
39
- interface maxFloat {
40
- validator: "maxFloat";
41
- max: number;
42
- }
43
- interface minFloat {
44
- validator: "minFloat";
45
- min: number;
46
- }
47
- interface isString {
48
- validator: "isString";
49
- }
50
- interface minStringLength {
51
- validator: "minStringLength";
52
- min: number;
53
- }
54
- interface maxStringLength {
55
- validator: "maxStringLength";
56
- max: number;
57
- }
58
- interface isFile {
59
- validator: "isFile";
60
- }
61
- interface maxFileSize {
62
- validator: "maxFileSize";
63
- max: number;
64
- }
65
- interface allowedExtensions {
66
- validator: "allowedExtensions";
67
- fileTypes: string;
68
- }
6
+ interface required {
7
+ validator: "required";
8
+ }
9
+ interface matchRegexp {
10
+ validator: "matchRegexp";
11
+ regexp: RegExp | string;
12
+ }
13
+ interface isEmail {
14
+ validator: "isEmail";
15
+ }
16
+ interface isEmpty {
17
+ validator: "isEmpty";
18
+ }
19
+ interface trim {
20
+ validator: "trim";
21
+ }
22
+ interface isNumber {
23
+ validator: "isNumber";
24
+ }
25
+ interface isFloat {
26
+ validator: "isFloat";
27
+ }
28
+ interface isPositive {
29
+ validator: "isPositive";
30
+ }
31
+ interface maxNumber {
32
+ validator: "maxNumber";
33
+ max: number;
34
+ }
35
+ interface minNumber {
36
+ validator: "minNumber";
37
+ min: number;
38
+ }
39
+ interface maxFloat {
40
+ validator: "maxFloat";
41
+ max: number;
42
+ }
43
+ interface minFloat {
44
+ validator: "minFloat";
45
+ min: number;
46
+ }
47
+ interface isString {
48
+ validator: "isString";
49
+ }
50
+ interface minStringLength {
51
+ validator: "minStringLength";
52
+ min: number;
53
+ }
54
+ interface maxStringLength {
55
+ validator: "maxStringLength";
56
+ max: number;
57
+ }
58
+ interface isFile {
59
+ validator: "isFile";
60
+ }
61
+ interface maxFileSize {
62
+ validator: "maxFileSize";
63
+ max: number;
64
+ }
65
+ interface allowedExtensions {
66
+ validator: "allowedExtensions";
67
+ fileTypes: string;
68
+ }
69
69
  type Validator = required | matchRegexp | isEmail | isEmpty | trim | isNumber | isFloat | isPositive | maxNumber | minNumber | maxFloat | minFloat | isString | minStringLength | maxStringLength | isFile | maxFileSize | allowedExtensions;
70
70
 
71
- type MuiTelInputReason = 'country' | 'input';
72
- interface MuiTelInputInfo {
73
- countryCode: CountryCode | null;
74
- countryCallingCode: string | null;
75
- nationalNumber: string | null;
76
- numberType: Exclude<NumberType, undefined> | null;
77
- numberValue: string | null;
78
- reason: MuiTelInputReason;
71
+ type ComponentProps = {
72
+ errorMessages?: string | string[];
73
+ validators?: Validator[];
74
+ value: any;
75
+ validatorListener?: (value: boolean) => void;
76
+ withRequiredValidator?: boolean;
77
+ containerProps?: object;
78
+ onChangeTel: (value: string, info: MuiTelInputInfo) => void;
79
+ };
80
+ type ValidatorComponentProps = (FilledTextFieldProps | OutlinedTextFieldProps | StandardTextFieldProps) & ComponentProps;
81
+ interface ValidatorComponentState {
82
+ isValid?: boolean;
83
+ value: any;
84
+ errorMessages?: string | string[];
85
+ validators?: Validator[];
79
86
  }
80
-
81
- type ComponentProps = {
82
- errorMessages?: string | string[];
83
- validators?: Validator[];
84
- value: any;
85
- validatorListener?: (value: boolean) => void;
86
- withRequiredValidator?: boolean;
87
- containerProps?: object;
88
- onChangeTel?: (value: string, info: MuiTelInputInfo) => void;
89
- };
90
- type ValidatorComponentProps = (FilledTextFieldProps | OutlinedTextFieldProps | StandardTextFieldProps) & ComponentProps;
91
- interface ValidatorComponentState {
92
- isValid?: boolean;
93
- value: any;
94
- errorMessages?: string | string[];
95
- validators?: Validator[];
96
- }
97
- interface ValidatorFormProps {
98
- children: React.ReactNode;
99
- onSubmit: () => void;
100
- instantValidate?: boolean;
101
- onError?: (errors: any) => void;
102
- debounceTime?: number;
87
+ interface ValidatorFormProps {
88
+ children: React.ReactNode;
89
+ onSubmit: () => void;
90
+ instantValidate?: boolean;
91
+ onError?: (errors: any) => void;
92
+ debounceTime?: number;
103
93
  }
104
94
 
105
- declare class ValidatorForm extends React$1.Component<ValidatorFormProps & BoxProps> {
106
- static getValidator: (validator: Validator, value: any, includeRequired: boolean) => boolean;
107
- getFormHelpers: () => {
108
- form: {
109
- attachToForm: (component: any) => void;
110
- detachFromForm: (component: any) => void;
111
- instantValidate: boolean;
112
- debounceTime: number;
113
- };
114
- };
115
- instantValidate: boolean;
116
- childs: any[];
117
- errors: any[];
118
- debounceTime: number;
119
- attachToForm: (component: any) => void;
120
- detachFromForm: (component: any) => void;
121
- submit: (event: React$1.FormEvent<HTMLFormElement>) => void;
122
- walk: (children: any[], dryRun?: boolean) => Promise<boolean>;
123
- checkInput: (input: any, dryRun?: boolean) => Promise<boolean>;
124
- validate: (input: any, includeRequired: boolean, dryRun?: boolean) => Promise<boolean>;
125
- find: (collection: any[], fn: (item: any) => boolean) => any;
126
- resetValidations: () => void;
127
- isFormValid: (dryRun?: boolean) => Promise<boolean>;
128
- render(): React$1.JSX.Element;
95
+ declare class ValidatorForm extends React$1.Component<ValidatorFormProps & BoxProps> {
96
+ static getValidator: (validator: Validator, value: any, includeRequired: boolean) => boolean;
97
+ getFormHelpers: () => {
98
+ form: {
99
+ attachToForm: (component: any) => void;
100
+ detachFromForm: (component: any) => void;
101
+ instantValidate: boolean;
102
+ debounceTime: number;
103
+ };
104
+ };
105
+ instantValidate: boolean;
106
+ childs: any[];
107
+ errors: any[];
108
+ debounceTime: number;
109
+ attachToForm: (component: any) => void;
110
+ detachFromForm: (component: any) => void;
111
+ submit: (event: React$1.FormEvent<HTMLFormElement>) => void;
112
+ walk: (children: any[], dryRun?: boolean) => Promise<boolean>;
113
+ checkInput: (input: any, dryRun?: boolean) => Promise<boolean>;
114
+ validate: (input: any, includeRequired: boolean, dryRun?: boolean) => Promise<boolean>;
115
+ find: (collection: any[], fn: (item: any) => boolean) => any;
116
+ resetValidations: () => void;
117
+ isFormValid: (dryRun?: boolean) => Promise<boolean>;
118
+ render(): React$1.JSX.Element;
129
119
  }
130
120
 
131
- declare class ValidatorComponent extends React$1.Component<ValidatorComponentProps, ValidatorComponentState> {
132
- renderValidatorComponent(): React$1.ReactNode;
133
- validateDebounced: any;
134
- form: any;
135
- debounceTime: any;
136
- getSnapshotBeforeUpdate(nextProps: ValidatorComponentProps, prevState: ValidatorComponentState): {
137
- value: any;
138
- validators: Validator[];
139
- errorMessages: string | string[];
140
- } | {
141
- value: any;
142
- validators?: undefined;
143
- errorMessages?: undefined;
144
- };
145
- state: {
146
- isValid: boolean;
147
- value: any;
148
- errorMessages: string | string[] | undefined;
149
- validators: Validator[] | undefined;
150
- };
151
- componentDidMount(): void;
152
- shouldComponentUpdate(nextProps: ValidatorComponentProps, nextState: ValidatorComponentState): boolean;
153
- componentDidUpdate(prevProps: ValidatorComponentProps, prevState: ValidatorComponentState): void;
154
- componentWillUnmount(): void;
155
- getErrorMessage: () => string | boolean | string[];
156
- instantValidate: boolean;
157
- invalid: number[];
158
- configure: () => void;
159
- validate: (value: any, includeRequired?: boolean, dryRun?: boolean) => Promise<boolean>;
160
- isValid: () => boolean;
161
- makeInvalid: () => void;
162
- makeValid: () => void;
163
- renderComponent: (form: ValidatorForm) => React$1.ReactNode;
164
- render(): React$1.JSX.Element;
121
+ declare class ValidatorComponent extends React$1.Component<ValidatorComponentProps, ValidatorComponentState> {
122
+ renderValidatorComponent(): React$1.ReactNode;
123
+ validateDebounced: any;
124
+ form: any;
125
+ debounceTime: any;
126
+ getSnapshotBeforeUpdate(nextProps: ValidatorComponentProps, prevState: ValidatorComponentState): {
127
+ value: any;
128
+ validators: Validator[];
129
+ errorMessages: string | string[];
130
+ } | {
131
+ value: any;
132
+ validators?: undefined;
133
+ errorMessages?: undefined;
134
+ };
135
+ state: {
136
+ isValid: boolean;
137
+ value: any;
138
+ errorMessages: string | string[] | undefined;
139
+ validators: Validator[] | undefined;
140
+ };
141
+ componentDidMount(): void;
142
+ shouldComponentUpdate(nextProps: ValidatorComponentProps, nextState: ValidatorComponentState): boolean;
143
+ componentDidUpdate(prevProps: ValidatorComponentProps, prevState: ValidatorComponentState): void;
144
+ componentWillUnmount(): void;
145
+ getErrorMessage: () => string | boolean | string[];
146
+ instantValidate: boolean;
147
+ invalid: number[];
148
+ configure: () => void;
149
+ validate: (value: any, includeRequired?: boolean, dryRun?: boolean) => Promise<boolean>;
150
+ isValid: () => boolean;
151
+ makeInvalid: () => void;
152
+ makeValid: () => void;
153
+ renderComponent: (form: ValidatorForm) => React$1.ReactNode;
154
+ render(): React$1.JSX.Element;
165
155
  }
166
156
 
167
- declare class MuiSelect extends ValidatorComponent {
168
- renderValidatorComponent(): React$1.JSX.Element;
157
+ declare class MuiSelect extends ValidatorComponent {
158
+ renderValidatorComponent(): React$1.JSX.Element;
169
159
  }
170
160
 
171
- declare class MuiTextField extends ValidatorComponent {
172
- renderValidatorComponent(): React__default.JSX.Element;
161
+ declare class MuiTextField extends ValidatorComponent {
162
+ renderValidatorComponent(): React__default.JSX.Element;
173
163
  }
174
164
 
175
- declare class MuiTelInputDefault extends ValidatorComponent {
176
- renderValidatorComponent(): React__default.JSX.Element;
165
+ declare class MuiTelInputDefault extends ValidatorComponent {
166
+ renderValidatorComponent(): React__default.JSX.Element;
177
167
  }
178
168
 
179
- export { ValidatorComponent as MuiComponent, ValidatorForm as MuiForm, MuiTelInputDefault as MuiPhoneNumber, MuiSelect, MuiTextField, Validator as MuiValidator };
169
+ export { ValidatorComponent as MuiComponent, ValidatorForm as MuiForm, MuiTelInputDefault as MuiPhoneNumber, MuiSelect, MuiTextField, type Validator as MuiValidator };