Skip to content

Commit 9d3756d

Browse files
committed
First npm release
1 parent 6c36936 commit 9d3756d

17 files changed

+2824
-165
lines changed

.babelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"presets": [
3+
["es2015"],
4+
"react"
5+
],
6+
"plugins": [
7+
"transform-object-rest-spread",
8+
]
9+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
example
2+
.babelrc
3+
form.js
4+
README.md

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## React Validify
2+
3+
`npm install react-validify`
4+
5+
```js
6+
import Form from 'react-validify'
7+
8+
<Form rules={{ email: 'email|required', password: 'required|min:8' }}>
9+
<Input name="email" />
10+
<Input name="password" type="password" />
11+
12+
<div
13+
submit
14+
onClick={values =>
15+
console.log('this will be called if validation passes', values)}
16+
>
17+
Submit!
18+
</div>
19+
</Form>
20+
```
21+
22+
## Usage
23+
24+
This component is the simplest way to validate form inputs in React. There's two things to learn. The Form accepts a prop called `rules`. This is an object with the names of all yours inputs and the rules for them. Rules can be found [here](https://github.com/skaterdav85/validatorjs#available-rules). Place the `submit` prop on any element that you want to trigger the validation. The onClick will not be triggered until the rules pass. If validation fails, error messages will be passed to the inputs as an error prop.
25+
26+
27+
Workflow:
28+
29+
1. Import `Form`
30+
2. Build a wrapper around inputs. It needs to handle when there's an error passed in:
31+
32+
```js
33+
export default ({ error, ...props }) => {
34+
return (
35+
<div>
36+
<p>{error}</p>
37+
<input {...props} />
38+
</div>
39+
);
40+
};
41+
42+
```
43+
3. Add a submit button inside the form with the `submit` prop.
44+
4. That's it!

example/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
},
88
"dependencies": {
99
"react": "^15.6.1",
10-
"react-dom": "^15.6.1"
10+
"react-dom": "^15.6.1",
11+
"react-validify": "0.0.1",
12+
"validatorjs": "^3.13.3"
1113
},
1214
"scripts": {
1315
"start": "react-scripts start",

example/src/App.css

Lines changed: 0 additions & 24 deletions
This file was deleted.

example/src/App.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import React, { Component } from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
2+
3+
import Input from './input';
4+
import Form from 'react-validify';
45

56
class App extends Component {
67
render() {
78
return (
89
<div className="App">
9-
<div className="App-header">
10-
<img src={logo} className="App-logo" alt="logo" />
11-
<h2>Welcome to React</h2>
12-
</div>
13-
<p className="App-intro">
14-
To get started, edit <code>src/App.js</code> and save to reload.
15-
</p>
10+
<Form rules={{ email: 'email|required', password: 'required|min:8' }}>
11+
<Input name="email" />
12+
<Input name="password" type="password" />
13+
14+
<div
15+
submit
16+
onClick={values =>
17+
console.log('this will be called if validation passes', values)}
18+
>
19+
Submit!
20+
</div>
21+
</Form>
1622
</div>
1723
);
1824
}

example/src/App.test.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

example/src/index.css

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)