├── .all-contributorsrc
├── .babelrc
├── .github
├── pull_request_template.md
├── release-drafter.yml
└── workflows
│ ├── draft-release.yml
│ ├── publish.yml
│ └── test.yml
├── .gitignore
├── .npmignore
├── .vscode
├── extensions.json
└── settings.json
├── LICENSE
├── README.md
├── _config.yml
├── example
├── .gitignore
├── package.json
├── public
│ ├── favicon.ico
│ ├── index.html
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── robots.txt
├── src
│ ├── App.tsx
│ ├── index.tsx
│ ├── input.js
│ ├── react-app-env.d.ts
│ └── submit.js
├── tsconfig.json
└── yarn.lock
├── package.json
├── src
├── form.tsx
├── index.ts
├── rules.ts
├── types.d.ts
├── use-field.ts
├── use-submit.ts
└── validate.ts
├── tests
├── form.test.js
└── helpers
│ ├── form.tsx
│ ├── input.tsx
│ └── submit.tsx
├── tsconfig.json
└── yarn.lock
/.all-contributorsrc:
--------------------------------------------------------------------------------
1 | {
2 | "projectName": "react-validify",
3 | "projectOwner": "navjobs",
4 | "files": [
5 | "README.md"
6 | ],
7 | "imageSize": 100,
8 | "commit": true,
9 | "contributors": [
10 | {
11 | "login": "zackify",
12 | "name": "Zach Silveira",
13 | "avatar_url": "https://avatars0.githubusercontent.com/u/449136?v=4",
14 | "profile": "https://zach.codes",
15 | "contributions": []
16 | },
17 | {
18 | "login": "audiolion",
19 | "name": "Ryan Castner",
20 | "avatar_url": "https://avatars1.githubusercontent.com/u/2430381?v=4",
21 | "profile": "http://audiolion.github.io",
22 | "contributions": []
23 | }
24 | ]
25 | }
26 |
--------------------------------------------------------------------------------
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "production": {
4 | "presets": ["@babel/preset-react", "@babel/preset-typescript"]
5 | },
6 | "test": {
7 | "presets": [
8 | ["@babel/preset-env", { "targets": { "node": "current" } }],
9 | "@babel/preset-typescript",
10 | "@babel/preset-react"
11 | ]
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | - Bump the version in package.json (minor bump if adding features, major if breaking changes)
2 | - Ensure tests are passing (these are ran automatically when you commit)
3 |
--------------------------------------------------------------------------------
/.github/release-drafter.yml:
--------------------------------------------------------------------------------
1 | branches:
2 | - master
3 | name-template: '$NEXT_PATCH_VERSION'
4 | tag-template: '$NEXT_PATCH_VERSION'
5 | change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
6 | template: |
7 | ## Changes
8 | $CHANGES
9 |
--------------------------------------------------------------------------------
/.github/workflows/draft-release.yml:
--------------------------------------------------------------------------------
1 | name: Draft Package Release
2 | on:
3 | push:
4 | branches:
5 | - master
6 | jobs:
7 | update_release_draft:
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: release-drafter/release-drafter@v5
11 | env:
12 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish to npm
2 |
3 | on:
4 | release:
5 | types: [published]
6 |
7 | jobs:
8 | publish-npm:
9 | runs-on: ubuntu-latest
10 | steps:
11 | - uses: actions/checkout@v1
12 | - uses: actions/setup-node@v1
13 | with:
14 | node-version: 12
15 | registry-url: https://registry.npmjs.org/
16 | - name: Cache NPM dependencies
17 | uses: actions/cache@v1
18 | with:
19 | path: node_modules
20 | key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/yarn.lock') }}
21 | restore-keys: |
22 | ${{ runner.OS }}-npm-cache-
23 | - run: yarn --frozen-lockfile
24 | - run: yarn build
25 | - run: yarn export-types
26 | - run: yarn publish --new-version ${GITHUB_REF:10} --no-git-tag-version
27 | env:
28 | NODE_AUTH_TOKEN: ${{secrets.npm_token}}
29 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Test and Build
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 |
9 | strategy:
10 | matrix:
11 | node-version: [10.x, 12.x]
12 |
13 | steps:
14 | - uses: actions/checkout@v1
15 | - name: Use Node.js ${{ matrix.node-version }}
16 | uses: actions/setup-node@v1
17 | with:
18 | node-version: ${{ matrix.node-version }}
19 | - name: Cache NPM dependencies
20 | uses: actions/cache@v1
21 | with:
22 | path: node_modules
23 | key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/yarn.lock') }}
24 | restore-keys: |
25 | ${{ runner.OS }}-npm-cache-
26 | - name: yarn install, build, and test
27 | run: |
28 | yarn --frozen-lockfile
29 | yarn build
30 | yarn test --coverage
31 | yarn check-types
32 | env:
33 | CI: true
34 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | lib
2 | dist
3 | coverage
4 | node_modules
5 | yarn-error.log
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | example
2 | .babelrc
3 | src
4 | .all-contributorsrc
5 | README.md
6 | coverage
7 | tests
8 | .github
9 | tsconfig.json
10 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": [
3 | "esbenp.prettier-vscode",
4 | "prisma.prisma",
5 | "golang.go",
6 | "ms-azuretools.vscode-docker",
7 | "s3gf4ult.monokai-vibrant",
8 | "svelte.svelte-vscode",
9 | "bradlc.vscode-tailwindcss",
10 | "zxh404.vscode-proto3"
11 | ]
12 | }
13 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "workbench.colorTheme": "Monokai Vibrant",
3 | "explorer.confirmDelete": false,
4 | "explorer.confirmDragAndDrop": false,
5 | "terminal.integrated.shell.osx": "/bin/zsh",
6 | "tailwindCSS.includeLanguages": {
7 | "plaintext": "html",
8 | "typescript": "javascript",
9 | "typescriptreact": "javascript"
10 | },
11 | "editor.fontFamily": "Cascadia Code",
12 | "window.zoomLevel": 0,
13 | "typescript.updateImportsOnFileMove.enabled": "always",
14 | "[typescript]": {
15 | "editor.defaultFormatter": "esbenp.prettier-vscode"
16 | },
17 | "[json]": {
18 | "editor.defaultFormatter": "esbenp.prettier-vscode"
19 | },
20 | "javascript.updateImportsOnFileMove.enabled": "always",
21 | "[typescriptreact]": {
22 | "editor.defaultFormatter": "esbenp.prettier-vscode"
23 | },
24 | "[javascript]": {
25 | "editor.defaultFormatter": "esbenp.prettier-vscode"
26 | },
27 | "[html]": {
28 | "editor.defaultFormatter": "esbenp.prettier-vscode"
29 | },
30 | "editor.tabSize": 2,
31 | "editor.insertSpaces": true,
32 | "[jsonc]": {
33 | "editor.defaultFormatter": "esbenp.prettier-vscode"
34 | },
35 | "go.useLanguageServer": true,
36 | "editor.formatOnSave": true,
37 | "workbench.editorAssociations": [
38 | {
39 | "viewType": "jupyter.notebook.ipynb",
40 | "filenamePattern": "*.ipynb"
41 | }
42 | ]
43 | }
44 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 NavJobs
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 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## React Validify
2 |
3 | single dependency, simplest way to validate and manage form state with hooks in React + React Native! With full test coverage and TS support.
4 |
5 | ## Contents
6 |
7 | - [Install](#install)
8 | - [Getting Started](#getting-started)
9 | - [TypeScript Support](#typescript-support)
10 | - [Contributors](#contributors)
11 |
12 | ## Install
13 |
14 | ```
15 | npm install react-validify lodash
16 | ```
17 |
18 | ## Getting Started
19 |
20 | This api has been carefully thought out over the past year. It's been in use on multiple React websites and React Native mobile applications. Using the library is simple. Include the `Form` component, and wrap your `input`'s and `submit` buttons.
21 |
22 | ```js
23 | import Input from "./input";
24 | import Submit from "./submit";
25 | import { Form, rules } from "react-validify";
26 |
27 | const { required, email } = rules;
28 |
29 | const App = () => {
30 | let [values, setValues] = React.useState({
31 | email: "test",
32 | nested: { test: "this is nested" },
33 | });
34 |
35 | return (
36 |
44 | );
45 | };
46 | ```
47 |
48 | Add `useField` to your own inputs inside the Form wrapper. This allows you to use the library with any type of input field.
49 | It just needs to support a `handleChange` `handleBlur` and `value` prop. This is the `Input` component you see in the first example. Don't forget to pass the field `name` to the hook.
50 |
51 | ```js
52 | import React from "react";
53 | import { useField, FieldProps } from "react-validify";
54 |
55 | type Props = { placeholder: string } & FieldProps;
56 |
57 | const Input = ({ name, rules, placeholder }: Props) => {
58 | let { handleChange, handleBlur, value, errors } = useField({ name, rules });
59 |
60 | return (
61 |