react-mui-form-validator 1.1.2 → 1.1.5
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.
- package/LICENSE +20 -20
- package/Readme.md +219 -144
- package/package.json +5 -4
- package/tsconfig.json +25 -25
- /package/{dist → lib}/index.d.ts +0 -0
- /package/{dist → lib}/index.js +0 -0
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 blencm
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 blencm
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/Readme.md
CHANGED
|
@@ -1,144 +1,219 @@
|
|
|
1
|
-
## Validation component for material-ui forms
|
|
2
|
-
|
|
3
|
-
[](https://opensource.org/licenses/MIT)
|
|
4
|
-
|
|
5
|
-
### Installation
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
npm install react-mui-form-validator
|
|
9
|
-
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
### Info
|
|
13
|
-
|
|
14
|
-
Some rules can accept extra parameter, example:
|
|
15
|
-
|
|
16
|
-
TextField
|
|
17
|
-
```javascript
|
|
18
|
-
<MuiTextField
|
|
19
|
-
{...someProps}
|
|
20
|
-
validators={["minNumber:0", "maxNumber:255", "matchRegexp:^[0-9]$"]}
|
|
21
|
-
/>
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### Usage Example
|
|
25
|
-
|
|
26
|
-
You can pass any props of field components, but note that `errorText` prop will be replaced when validation errors occurred.
|
|
27
|
-
Your component must [provide a theme](http://www.material-ui.com/#/get-started/usage).
|
|
28
|
-
|
|
29
|
-
```javascript
|
|
30
|
-
|
|
31
|
-
import
|
|
32
|
-
import
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
1
|
+
## Validation component for material-ui forms
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
|
|
5
|
+
### Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install react-mui-form-validator
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### Info
|
|
13
|
+
|
|
14
|
+
Some rules can accept extra parameter, example:
|
|
15
|
+
|
|
16
|
+
TextField
|
|
17
|
+
```javascript
|
|
18
|
+
<MuiTextField
|
|
19
|
+
{...someProps}
|
|
20
|
+
validators={["minNumber:0", "maxNumber:255", "matchRegexp:^[0-9]$"]}
|
|
21
|
+
/>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Usage Example
|
|
25
|
+
|
|
26
|
+
You can pass any props of field components, but note that `errorText` prop will be replaced when validation errors occurred.
|
|
27
|
+
Your component must [provide a theme](http://www.material-ui.com/#/get-started/usage).
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
|
|
31
|
+
import { useState } from "react";
|
|
32
|
+
import "./App.css";
|
|
33
|
+
import { MuiForm, MuiTextField } from "react-mui-form-validator";
|
|
34
|
+
import { Button, IconButton, InputAdornment, Paper } from "@mui/material";
|
|
35
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
36
|
+
import {
|
|
37
|
+
faEnvelope,
|
|
38
|
+
faEye,
|
|
39
|
+
faEyeSlash,
|
|
40
|
+
} from "@fortawesome/free-solid-svg-icons";
|
|
41
|
+
|
|
42
|
+
export default function App(props: any) {
|
|
43
|
+
const [name, setName] = useState();
|
|
44
|
+
const [email, setEmail] = useState();
|
|
45
|
+
const [password, setPassword] = useState();
|
|
46
|
+
const [showPassword, setShowPassword] = useState(false);
|
|
47
|
+
|
|
48
|
+
const changeName = (event: any) => {
|
|
49
|
+
const name = event.target.value;
|
|
50
|
+
setName(name);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const changeEmail = (event: any) => {
|
|
54
|
+
const email = event.target.value;
|
|
55
|
+
setEmail(email);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const changePassword = (event: any) => {
|
|
59
|
+
const password = event.target.value;
|
|
60
|
+
setPassword(password);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const handleSubmit = () => {
|
|
64
|
+
// your submit logic
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div className="App">
|
|
69
|
+
<center>
|
|
70
|
+
<Paper className="container">
|
|
71
|
+
<h3>Example Sign In</h3>
|
|
72
|
+
<MuiForm
|
|
73
|
+
onSubmit={handleSubmit}
|
|
74
|
+
onError={(errors: any) => console.log(errors)}
|
|
75
|
+
>
|
|
76
|
+
<MuiTextField
|
|
77
|
+
name="name"
|
|
78
|
+
//className="css-style-name" add your css style
|
|
79
|
+
//classes={classes.emailInput} //add your js or ts style
|
|
80
|
+
label="Name"
|
|
81
|
+
placeholder="Name"
|
|
82
|
+
onChange={changeName}
|
|
83
|
+
value={name}
|
|
84
|
+
validators={["required"]}
|
|
85
|
+
errorMessages={["this field is required"]}
|
|
86
|
+
fullWidth
|
|
87
|
+
/>
|
|
88
|
+
<br />
|
|
89
|
+
<MuiTextField
|
|
90
|
+
name="email"
|
|
91
|
+
//className="css-style-name" add your css style
|
|
92
|
+
//classes={classes.emailInput} //add your js or ts style
|
|
93
|
+
label="Email"
|
|
94
|
+
placeholder="Email"
|
|
95
|
+
onChange={changeEmail}
|
|
96
|
+
value={email}
|
|
97
|
+
validators={["required", "isEmail"]}
|
|
98
|
+
errorMessages={["this field is required", "email is not valid"]}
|
|
99
|
+
InputProps={{
|
|
100
|
+
startAdornment: (
|
|
101
|
+
<InputAdornment position="start">
|
|
102
|
+
<FontAwesomeIcon icon={faEnvelope} />
|
|
103
|
+
</InputAdornment>
|
|
104
|
+
),
|
|
105
|
+
}}
|
|
106
|
+
fullWidth
|
|
107
|
+
/>
|
|
108
|
+
<br />
|
|
109
|
+
<MuiTextField
|
|
110
|
+
type={showPassword ? "text" : "password"}
|
|
111
|
+
style={{ marginBottom: 0 }}
|
|
112
|
+
name="password"
|
|
113
|
+
label="Password"
|
|
114
|
+
//InputLabelProps={{ shrink: true }}
|
|
115
|
+
placeholder="Password"
|
|
116
|
+
value={password}
|
|
117
|
+
onChange={changePassword}
|
|
118
|
+
InputProps={{
|
|
119
|
+
startAdornment: (
|
|
120
|
+
<InputAdornment position="start">
|
|
121
|
+
<FontAwesomeIcon icon={faEnvelope} />
|
|
122
|
+
</InputAdornment>
|
|
123
|
+
),
|
|
124
|
+
endAdornment: (
|
|
125
|
+
<InputAdornment position="end">
|
|
126
|
+
<IconButton
|
|
127
|
+
aria-label="toggle password visibility"
|
|
128
|
+
onClick={() => setShowPassword(!showPassword)}
|
|
129
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
130
|
+
edge="end"
|
|
131
|
+
>
|
|
132
|
+
<FontAwesomeIcon
|
|
133
|
+
icon={showPassword ? faEyeSlash : faEye}
|
|
134
|
+
/>
|
|
135
|
+
</IconButton>
|
|
136
|
+
</InputAdornment>
|
|
137
|
+
),
|
|
138
|
+
}}
|
|
139
|
+
validators={["required"]}
|
|
140
|
+
errorMessages={["Password is required"]}
|
|
141
|
+
variant="outlined"
|
|
142
|
+
fullWidth
|
|
143
|
+
/>
|
|
144
|
+
<br />
|
|
145
|
+
<Button type="submit" variant="outlined">
|
|
146
|
+
Sign In
|
|
147
|
+
</Button>
|
|
148
|
+
</MuiForm>
|
|
149
|
+
</Paper>
|
|
150
|
+
</center>
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
css style example:
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
.App {
|
|
160
|
+
text-align: center;
|
|
161
|
+
width: 100%;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.container {
|
|
165
|
+
width: 500px;
|
|
166
|
+
height: auto;
|
|
167
|
+
background: #FFFFFF;
|
|
168
|
+
box-shadow: 0px 20px 56px rgba(0, 0, 0, 0.1);
|
|
169
|
+
border-radius: 16px;
|
|
170
|
+
padding: 15px;
|
|
171
|
+
margin: 20px;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Class component example:
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
|
|
180
|
+
import React from "react";
|
|
181
|
+
import Button from "@mui/material/Button";
|
|
182
|
+
import { MuiForm, MuiTextField } from "react-mui-form-validator";
|
|
183
|
+
|
|
184
|
+
class MyForm extends React.Component {
|
|
185
|
+
state = {
|
|
186
|
+
email: "",
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
handleChange = (event) => {
|
|
190
|
+
const email = event.target.value;
|
|
191
|
+
this.setState({ email });
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
handleSubmit = () => {
|
|
195
|
+
// your submit logic
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
render() {
|
|
199
|
+
const { email } = this.state;
|
|
200
|
+
return (
|
|
201
|
+
<MuiForm
|
|
202
|
+
onSubmit={this.handleSubmit}
|
|
203
|
+
onError={(errors) => console.log(errors)}
|
|
204
|
+
>
|
|
205
|
+
<MuiTextField
|
|
206
|
+
label="Email"
|
|
207
|
+
onChange={this.handleChange}
|
|
208
|
+
name="email"
|
|
209
|
+
value={email}
|
|
210
|
+
validators={["required", "isEmail"]}
|
|
211
|
+
errorMessages={["this field is required", "email is not valid"]}
|
|
212
|
+
/>
|
|
213
|
+
<Button type="submit">Submit</Button>
|
|
214
|
+
</MuiForm>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
```
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-mui-form-validator",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Validator for forms designed with material-ui components.",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "tsup src/index.ts --dts"
|
|
8
|
+
"build": "tsup src/index.ts --dts --outDir=lib"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"keywords": [
|
|
15
15
|
"react",
|
|
16
16
|
"mui",
|
|
17
|
+
"material-ui",
|
|
17
18
|
"form",
|
|
18
19
|
"form-validator",
|
|
19
20
|
"validator"
|
package/tsconfig.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"target": "es2022",
|
|
5
|
-
|
|
6
|
-
"strict": true,
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
"forceConsistentCasingInFileNames": true,
|
|
10
|
-
|
|
11
|
-
"lib": ["es2022", "dom", "dom.iterable", "esnext"],
|
|
12
|
-
"allowJs": true,
|
|
13
|
-
"allowSyntheticDefaultImports": true,
|
|
14
|
-
"noFallthroughCasesInSwitch": true,
|
|
15
|
-
|
|
16
|
-
"outDir": "
|
|
17
|
-
"declaration": true,
|
|
18
|
-
"moduleResolution": "node",
|
|
19
|
-
"resolveJsonModule": true,
|
|
20
|
-
"isolatedModules": true,
|
|
21
|
-
"noEmit": true,
|
|
22
|
-
"jsx": "react"
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
"include": ["src/**/*"]
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"target": "es2022",
|
|
5
|
+
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
|
|
11
|
+
"lib": ["es2022", "dom", "dom.iterable", "esnext"],
|
|
12
|
+
"allowJs": true,
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
"noFallthroughCasesInSwitch": true,
|
|
15
|
+
|
|
16
|
+
"outDir": "lib",
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"moduleResolution": "node",
|
|
19
|
+
"resolveJsonModule": true,
|
|
20
|
+
"isolatedModules": true,
|
|
21
|
+
"noEmit": true,
|
|
22
|
+
"jsx": "react"
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
"include": ["src/**/*"]
|
|
26
26
|
}
|
/package/{dist → lib}/index.d.ts
RENAMED
|
File without changes
|
/package/{dist → lib}/index.js
RENAMED
|
File without changes
|