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 CHANGED
@@ -1,42 +1,119 @@
1
- # GForm
2
-
3
- ![gform-react](https://gform-react.onrender.com/gform-logo.png)
4
-
5
- ![npm bundle size](https://img.shields.io/bundlephobia/min/gform-react?label=minified%20size&color=darkergreen)
6
- ![npm bundle size](https://img.shields.io/bundlephobia/minzip/gform-react?label=gzip%20size&color=darkergreen)
7
- ![npm peer dependency version](https://img.shields.io/npm/dependency-version/gform-react/peer/react)
8
- ![npm peer dependency version](https://img.shields.io/npm/dependency-version/gform-react/peer/react-dom)
9
- [![NPM](https://img.shields.io/npm/l/gform-react)](https://unpkg.com/gform-react@latest/LICENSE.md)
10
-
11
- #### build generic forms with validations for react-based applications.
12
- it doesn't matter which UI library you're using,
13
- it only cares about the form and the inputs inside.
14
-
15
- ## Pros
16
- * Lightweight
17
- * Based on native form and constraint validations (can also add custom and async validations)
18
- * Can be used with any UI library that preserves native form controls (input, button, etc. can also be adjusted to non-native controls)
19
- * Tree shakeable
20
- * Accessibility semi-automatic (required inputs and invalid inputs automatically sets aria-required and aria-invalid)
21
- * React Native support
22
- * Supports React 19, Next.js 15
23
-
24
- ## Docs
25
- https://gform-react.onrender.com
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
- ## Demo:
28
- https://codesandbox.io/p/sandbox/gifted-elbakyan-fs5g2c
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
- ```shell
102
+
103
+ ```sh
33
104
  npm install gform-react
34
105
  ```
35
106
 
36
107
  yarn:
37
- ```shell
108
+
109
+ ```sh
38
110
  yarn add gform-react
39
111
  ```
40
112
 
41
- #### NOTE:
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
@@ -254,3 +254,4 @@ declare const GForm: <T>(props: GFormProps<T> & {
254
254
  declare const useFormSelector: <T extends any>(selector: (state: InitialState) => T) => T;
255
255
 
256
256
  export { GForm, GInput, GValidator, useFormSelector };
257
+ export type { GValidators };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gform-react",
3
- "version": "2.7.2",
3
+ "version": "2.7.5",
4
4
  "description": "Build generic forms with validations for React-based applications",
5
5
  "author": "Tal Maman, Arkady Birko",
6
6
  "license": "MIT",