gform-react 2.7.2 → 2.7.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/README.md +108 -31
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,42 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
https://gform-react
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://gform-react.onrender.com" title="GForm React – A lightweight React form library built for performance, validation, and clean form logic">
|
|
3
|
+
<img src="https://gform-react.onrender.com/gform-logo.png" alt="gform-react logo" />
|
|
4
|
+
</a>
|
|
5
|
+
<h1>gform-react</h1>
|
|
6
|
+
<p>A lightweight React form library built for <b>performance</b>, <b>validation</b>, and clean <b>form logic</b></p>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Lightweight**
|
|
12
|
+
- **Tree‑shakeable**
|
|
13
|
+
- **Minimal re-renders** — only updates fields that change
|
|
14
|
+
- **Native HTML Constraint Validations**
|
|
15
|
+
- **Custom Validations**
|
|
16
|
+
- **Custom Async Validations**
|
|
17
|
+
- **Supports Yup, Zod, and more**
|
|
18
|
+
- **Dynamic forms** — add/remove fields on the fly
|
|
19
|
+
- **Accessibility‑friendly**
|
|
20
|
+
Automatically sets `aria-required` and `aria-invalid`
|
|
21
|
+
- **React Native support**
|
|
22
|
+
|
|
23
|
+
<br/>
|
|
24
|
+
<div align="center">
|
|
25
|
+
<a href="https://bundlephobia.com/package/gform-react">
|
|
26
|
+
<img src="https://img.shields.io/bundlephobia/min/gform-react?label=minified%20size&color=darkergreen" alt="Minified size">
|
|
27
|
+
</a>
|
|
28
|
+
|
|
29
|
+
<a href="https://bundlephobia.com/package/gform-react">
|
|
30
|
+
<img src="https://img.shields.io/bundlephobia/minzip/gform-react?label=gzip%20size&color=darkergreen" alt="Gzip size">
|
|
31
|
+
</a>
|
|
32
|
+
|
|
33
|
+
<img src="https://img.shields.io/npm/dm/gform-react" alt="npm downloads">
|
|
34
|
+
|
|
35
|
+
<img src="https://img.shields.io/npm/dependency-version/gform-react/peer/react" alt="React peer dependency">
|
|
36
|
+
|
|
37
|
+
<img src="https://img.shields.io/npm/dependency-version/gform-react/peer/react-dom" alt="React DOM peer dependency">
|
|
38
|
+
|
|
39
|
+
<a href="https://unpkg.com/gform-react@latest/LICENSE.md">
|
|
40
|
+
<img src="https://img.shields.io/npm/l/gform-react" alt="MIT License">
|
|
41
|
+
</a>
|
|
42
|
+
</div>
|
|
43
|
+
<br/>
|
|
44
|
+
|
|
45
|
+
## QuickStart
|
|
46
|
+
```tsx
|
|
47
|
+
import {GForm, GInput, GValidator, type GValidators} from "gform-react";
|
|
26
48
|
|
|
27
|
-
|
|
28
|
-
|
|
49
|
+
interface SignInForm {
|
|
50
|
+
username: string;
|
|
51
|
+
password: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const baseValidator = new GValidator().withRequiredMessage('this field is required');
|
|
55
|
+
|
|
56
|
+
const validators: GValidators<SignInForm> = {
|
|
57
|
+
'*': baseValidator, // a default validator for all other fields in the form
|
|
58
|
+
|
|
59
|
+
password: new GValidator(baseValidator)
|
|
60
|
+
.withMinLengthMessage((input) => `${input.formKey} must contain atleast ${input.minLength} chars`),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const App: FC = () => {
|
|
64
|
+
return (
|
|
65
|
+
<GForm<SignInForm> className='some-class'
|
|
66
|
+
validators={validators}
|
|
67
|
+
onSubmit={(formState, e) => { //can be used with native `action` or with Next.js `server actions`
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
console.log(formState);
|
|
70
|
+
}}>
|
|
71
|
+
<GInput formKey='username'
|
|
72
|
+
required
|
|
73
|
+
element={(input, props) => <div>
|
|
74
|
+
<input {...props} placeholder='username'/>
|
|
75
|
+
{input.error && <small className="p-error">{input.errorText}</small>}
|
|
76
|
+
</div>}
|
|
77
|
+
/>
|
|
78
|
+
<GInput formKey='password'
|
|
79
|
+
type='password'
|
|
80
|
+
required
|
|
81
|
+
minLength={5}
|
|
82
|
+
element={(input, props) => <div>
|
|
83
|
+
<input {...props} placeholder='password'/>
|
|
84
|
+
{input.error && <small className="p-error">{input.errorText}</small>}
|
|
85
|
+
</div>}
|
|
86
|
+
/>
|
|
87
|
+
<button>Submit</button>
|
|
88
|
+
</GForm>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Documentation
|
|
94
|
+
|
|
95
|
+
Full documentation, examples, and API reference:
|
|
96
|
+
|
|
97
|
+
https://gform-react.onrender.com
|
|
29
98
|
|
|
30
99
|
## Installation
|
|
100
|
+
|
|
31
101
|
npm:
|
|
32
|
-
|
|
102
|
+
|
|
103
|
+
```sh
|
|
33
104
|
npm install gform-react
|
|
34
105
|
```
|
|
35
106
|
|
|
36
107
|
yarn:
|
|
37
|
-
|
|
108
|
+
|
|
109
|
+
```sh
|
|
38
110
|
yarn add gform-react
|
|
39
111
|
```
|
|
40
112
|
|
|
41
|
-
|
|
42
|
-
react >=16.8.0, react-dom >=16.8.0 are peer dependencies
|
|
113
|
+
## Peer dependencies
|
|
114
|
+
react >=16.8.0, react-dom >=16.8.0 are peer dependencies
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
MIT © Tal
|
|
119
|
+
https://www.npmjs.com/package/gform-react
|
package/dist/index.d.ts
CHANGED