@simpleform/form 1.0.6 → 1.0.8

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.
Files changed (2) hide show
  1. package/README.md +214 -214
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -1,215 +1,215 @@
1
- # `@simpleform/form`
2
- English | [中文说明](./README_CN.md)
3
-
4
- [![](https://img.shields.io/badge/version-1.0.1-green)](https://www.npmjs.com/package/@simpleform/form)
5
-
6
- > The underlying form component automatically injects `value` and `onChange` into the target control to display and update the form values.
7
-
8
- # Matters
9
- - The css style file needs to be introduced before it can be used, for example: `import '@simpleform/form/lib/css/main.css'`;
10
-
11
- # Form.Item
12
-
13
- The smallest unit of a component in a form, and nodes as an object can be nested within each other.
14
-
15
- - Provides styles, as well as `value` (or set via `valueProp`) and `onChange` two-way bindings.
16
- - You can customize `onChange` in outside, but you can only set the form value via an instance method such as `form.setFieldValue`.
17
- - Custom form validation rules can be provided with the form validation rules property `rules`.
18
- - When a non-form component or node is added outside the input form control, bind the target control by adding `data-type="ignore"` to filter the non-target node or by setting `data-name` to mark the target input form.
19
-
20
- # Form.List
21
-
22
- The `Form.Item` component acts as an item in the `Form.List` array type and is combined to form an array
23
-
24
- - Only `Form.Item` items are recognised in `Form.List`, The `name` field of `Form.Item`, if set, is the field property in the array, if not, it defaults to the array serial number.
25
- - The `rules` provided by `Form.List` are valid for all input items in the array, but have a lower priority than the `rules` of the `Form.Item` in the array
26
-
27
- ## install
28
- - [Node.js](https://nodejs.org/en/) Version >= 14.0.0
29
- - [react](https://react.docschina.org/) Version >= 16.8.0
30
- ```bash
31
- npm install @simpleform/form --save
32
- # or
33
- yarn add @simpleform/form
34
- ```
35
-
36
- ## base
37
-
38
- ```javascript
39
- import React from "react";
40
- import { Form, useSimpleForm, useFormValues } from "@simpleform/form";
41
- import '@simpleform/form/lib/css/main.css';
42
- import { Input, Select } from "antd";
43
-
44
- export default function Demo() {
45
-
46
- const form = useSimpleForm();
47
- const formvalues = useFormValues(form, ['name1', 'name2'])
48
- console.log(formvalues, 'formvalues')
49
-
50
- const onSubmit = async (e) => {
51
- e.preventDefault();
52
- const { error, values } = await form.validate();
53
- console.log(error, values, 'error ang values');
54
- };
55
-
56
- const validator = (value) => {
57
- if (value?.length < 2) {
58
- return Promise.reject(new Error('length is < 2'));
59
- }
60
- }
61
-
62
- return (
63
- <Form initialValues={{ name1: 1111 }} form={form} onSubmit={onSubmit}>
64
- <Form.Item label="Name1" name="name1" rules={[{ required: true, message: 'name1 is Empty' }, { validator: validator, message: 'validator error' }]}>
65
- <div data-type="ignore">
66
- <input />
67
- </div>
68
- </Form.Item>
69
- <Form.Item label="object" name="name2.a" rules={[{ required: true, message: 'name2.a is empty' }]}>
70
- <input />
71
- </Form.Item>
72
- <Form.Item label="list" name="name3[0]" rules={[{ required: true, message: 'name3[0] is empty' }]}>
73
- <input />
74
- </Form.Item>
75
- <Form.Item label="">
76
- <button>Submit</button>
77
- </Form.Item>
78
- </Form>
79
- );
80
- };
81
- ```
82
- ## Form.List
83
-
84
- ```javascript
85
- import React from "react";
86
- import { Form, useSimpleForm } from "@simpleform/form";
87
- import '@simpleform/form/lib/css/main.css';
88
- import { Input, Select } from "antd";
89
-
90
- export default function Demo() {
91
-
92
- const form = useSimpleForm();
93
-
94
- const onSubmit = async (e) => {
95
- e.preventDefault();
96
- const { error, values } = await form.validate();
97
- console.log(error, values, 'error ang values');
98
- };
99
-
100
- const validator = async (value) => {
101
- if (value?.length < 2) {
102
- return Promise.reject(new Error('length is < 2'));
103
- }
104
- }
105
-
106
- return (
107
- <Form form={form} onSubmit={onSubmit}>
108
- <Form.List name="list">
109
- <Form.Item
110
- rules={[
111
- { required: true, message: "list's one is Empty" },
112
- { validator: validator, message: "custome tips" },
113
- ]}
114
- >
115
- <Input />
116
- </Form.Item>
117
- <Form.Item
118
- rules={[{ required: true, message: "list's two is Empty" }]}
119
- >
120
- <Input />
121
- </Form.Item>
122
- </Form.List>
123
- <Form.Item label="">
124
- <button>Submit</button>
125
- </Form.Item>
126
- </Form>
127
- );
128
- };
129
-
130
- ```
131
-
132
- ## APIs
133
-
134
- ### Default field display component
135
-
136
- - `className` `string` class name, `optional`.
137
- - `label` `string` label, `optional`.
138
- - `labelStyle` `CSSProperties` custom label's style, `optional`.
139
- - `labelWidth` `CSSProperties['width']`, the width of the label label.
140
- - `labelAlign` `CSSProperties['textAlign']`, the label label's textAlign property.
141
- - `inline` `boolea`, Whether or not field display components have inline layout.
142
- - `layout` `'horizontal'|'vertical'` field’s display components set the layout type, the default value is `horizontal`.
143
- - `colon` `boolean` whether add colon
144
- - `required` `boolean` Indicates that the value of the field is required `optional`。
145
- - `gutter` `number` The distance between field's display component custom labels and form components, `optional`.
146
- - `error` `string` form field displays the component's error message field.
147
- - `suffix` `React.ReactNode` Suffix node, `optional`.
148
- - `footer` `React.ReactNode` bootom node, `optional`.
149
- - `tooltip` `string` Tip icon to prompt for information. `optional`.
150
- - `compact` `boolean` Whether or not compact, will remove the component's `margin-bottom`. `optional`.
151
-
152
- ### Form Props
153
- Inherited field display component
154
-
155
- - `className` The class name of the form element, `optional`.
156
- - `form` The form data store, `required`.
157
- - `tagName` Replace the element tag name of the form, default `form` tag
158
- - `initialValues` The initial value of the form, which is overridden by the `initialValue` of the form field, Note that this value can only initialise the form `optional`.
159
- - `onSubmit` `form` tag triggers the reset default event, only `button` tags that provide `htmlType=submit` can trigger `optional`.
160
- - `onReset` `form` tag triggers the reset default event, only `button` tags that provide `htmlType=reset` can trigger `optional`.
161
- - `onFieldsChange` The event function when a form changes onChange will only be triggered by the control's active `onChange`, not by `form.setFieldValue` and `form.setFieldsValue`, avoiding circular calls。`optional`.
162
- - `onValuesChange` Listening for changes in form values.`optional`.
163
- - `watch` Listens for changes in the value of any field.
164
-
165
- ### Form.Item Props
166
- Inherited field display component
167
-
168
- - `className` Form field class name, `optional`.
169
- - `component` field display component.
170
- - `name` Form field name, `optional`.
171
- - `trigger` Sets the event name of the form field to collect form values, default `onChange`.
172
- - `validateTrigger` Sets the event for trigger form field validation, default `onChange`.
173
- - `valueProp` The field name of the value in the callback function object, the default value is `'value'`.
174
- - `valueGetter` A function to format the output form value, used with `valueSetter`, `optional`.
175
- - `valueSetter` function to format input form value, used with `valueGetter`, `optional`.
176
- - `rules` Checksum rules for form fields `optional`.
177
- - `initialValue` The initial value of the form field, note that this value is different from `value` when the form is rendered for the first time.
178
- - `onFieldsChange` The event function when the value of the control changes will only be triggered by the control's active `onChange`, not by `form.setFieldValue` and `form.setFieldsValue`, avoiding circular calls. `optional`.
179
- - `onValuesChange` Listening for changes in form values.`optional`。
180
- - `errorClassName` add a custom class name when there is an error message, `optional`.
181
-
182
- ### Form.List Props
183
- Inherited field display component
184
-
185
- - `className` Form field class name, `optional`.
186
- - `component` field display component.
187
- - `name` Form field name, `optional`.
188
- - `initialValue` Form field initial value, Note that this value can only initialise the form `optional`.
189
- - `rules` Checksum rules for form fields `optional`.
190
-
191
- ### rules
192
- The rules in the fields of the values in `rules` perform the checks in order, and only one rule can be set for each item in `rules`.
193
- - `validateTrigger` `string` Event to trigger validate form rules, default `onChange`.
194
- - `message` `string` Default error message when a check rule reports an error `optional`。
195
- - `required` `boolean` The required symbol is marked, and a `required` attribute of `true` in `rules` also automatically adds the required symbol `optional`。
196
- - `validator` `(value) => void | boolean` Custom check function, `value` is the current control value `optional`.
197
- - `pattern` `RegExp | string` Expression check, error if does not match `optional`.
198
- - `whitespace` `boolean` space check `optional`.
199
- - `max` `number` Maximum length for string type; maximum length for number type; maximum length for array type `optional`.
200
- - `min` `number` minimum length for `string` type; minimum value for `number` type; minimum length for `array` type. `optional`.
201
-
202
- ### SimpleForm
203
- To create an instance of `form` via `useSimpleForm`, use the following:
204
- - `form.getFieldValue(path?: string)` Returns the value of the form field for which `path` is specified, or the value of the whole form without `name`.
205
- - `form.setFieldValue(path, value)` Update the value of a form field
206
- - `form.setFieldsValue(obj: Partial<T>)` Set the value of the form field (override).
207
- - `form.reset(values?: Partial<T>)` Reset the form.The value can be passed to reset to the target value.
208
- - `form.validate(path?: string)` Checks form and returns error messages and form values.
209
- - `form.getFieldError(path?: string)` Returns the target's error message or all error messages.
210
-
211
- ### Hooks
212
-
213
- - `useSimpleForm(defaultValues)` create `new SimpleForm()`
214
- - `useFormError(form: SimpleForm, path?: string)` Use hooks to get the specified form error.
1
+ # `@simpleform/form`
2
+ English | [中文说明](./README_CN.md)
3
+
4
+ [![](https://img.shields.io/badge/version-1.0.1-green)](https://www.npmjs.com/package/@simpleform/form)
5
+
6
+ > The underlying form component automatically injects `value` and `onChange` into the target control to display and update the form values.
7
+
8
+ # Matters
9
+ - The css style file needs to be introduced before it can be used, for example: `import '@simpleform/form/lib/css/main.css'`;
10
+
11
+ # Form.Item
12
+
13
+ The smallest unit of a component in a form, and nodes as an object can be nested within each other.
14
+
15
+ - Provides styles, as well as `value` (or set via `valueProp`) and `onChange` two-way bindings.
16
+ - You can customize `onChange` in outside, but you can only set the form value via an instance method such as `form.setFieldValue`.
17
+ - Custom form validation rules can be provided with the form validation rules property `rules`.
18
+ - When a non-form component or node is added outside the input form control, bind the target control by adding `data-type="ignore"` to filter the non-target node or by setting `data-name` to mark the target input form.
19
+
20
+ # Form.List
21
+
22
+ The `Form.Item` component acts as an item in the `Form.List` array type and is combined to form an array
23
+
24
+ - Only `Form.Item` items are recognised in `Form.List`, The `name` field of `Form.Item`, if set, is the field property in the array, if not, it defaults to the array serial number.
25
+ - The `rules` provided by `Form.List` are valid for all input items in the array, but have a lower priority than the `rules` of the `Form.Item` in the array
26
+
27
+ ## install
28
+ - [Node.js](https://nodejs.org/en/) Version >= 14.0.0
29
+ - [react](https://react.docschina.org/) Version >= 16.8.0
30
+ ```bash
31
+ npm install @simpleform/form --save
32
+ # or
33
+ yarn add @simpleform/form
34
+ ```
35
+
36
+ ## base
37
+
38
+ ```javascript
39
+ import React from "react";
40
+ import { Form, useSimpleForm, useFormValues } from "@simpleform/form";
41
+ import '@simpleform/form/lib/css/main.css';
42
+ import { Input, Select } from "antd";
43
+
44
+ export default function Demo() {
45
+
46
+ const form = useSimpleForm();
47
+ const formvalues = useFormValues(form, ['name1', 'name2'])
48
+ console.log(formvalues, 'formvalues')
49
+
50
+ const onSubmit = async (e) => {
51
+ e.preventDefault();
52
+ const { error, values } = await form.validate();
53
+ console.log(error, values, 'error ang values');
54
+ };
55
+
56
+ const validator = (value) => {
57
+ if (value?.length < 2) {
58
+ return Promise.reject(new Error('length is < 2'));
59
+ }
60
+ }
61
+
62
+ return (
63
+ <Form initialValues={{ name1: 1111 }} form={form} onSubmit={onSubmit}>
64
+ <Form.Item label="Name1" name="name1" rules={[{ required: true, message: 'name1 is Empty' }, { validator: validator, message: 'validator error' }]}>
65
+ <div data-type="ignore">
66
+ <input />
67
+ </div>
68
+ </Form.Item>
69
+ <Form.Item label="object" name="name2.a" rules={[{ required: true, message: 'name2.a is empty' }]}>
70
+ <input />
71
+ </Form.Item>
72
+ <Form.Item label="list" name="name3[0]" rules={[{ required: true, message: 'name3[0] is empty' }]}>
73
+ <input />
74
+ </Form.Item>
75
+ <Form.Item label="">
76
+ <button>Submit</button>
77
+ </Form.Item>
78
+ </Form>
79
+ );
80
+ };
81
+ ```
82
+ ## Form.List
83
+
84
+ ```javascript
85
+ import React from "react";
86
+ import { Form, useSimpleForm } from "@simpleform/form";
87
+ import '@simpleform/form/lib/css/main.css';
88
+ import { Input, Select } from "antd";
89
+
90
+ export default function Demo() {
91
+
92
+ const form = useSimpleForm();
93
+
94
+ const onSubmit = async (e) => {
95
+ e.preventDefault();
96
+ const { error, values } = await form.validate();
97
+ console.log(error, values, 'error ang values');
98
+ };
99
+
100
+ const validator = async (value) => {
101
+ if (value?.length < 2) {
102
+ return Promise.reject(new Error('length is < 2'));
103
+ }
104
+ }
105
+
106
+ return (
107
+ <Form form={form} onSubmit={onSubmit}>
108
+ <Form.List name="list">
109
+ <Form.Item
110
+ rules={[
111
+ { required: true, message: "list's one is Empty" },
112
+ { validator: validator, message: "custome tips" },
113
+ ]}
114
+ >
115
+ <Input />
116
+ </Form.Item>
117
+ <Form.Item
118
+ rules={[{ required: true, message: "list's two is Empty" }]}
119
+ >
120
+ <Input />
121
+ </Form.Item>
122
+ </Form.List>
123
+ <Form.Item label="">
124
+ <button>Submit</button>
125
+ </Form.Item>
126
+ </Form>
127
+ );
128
+ };
129
+
130
+ ```
131
+
132
+ ## APIs
133
+
134
+ ### Default field display component
135
+
136
+ - `className` `string` class name, `optional`.
137
+ - `label` `string` label, `optional`.
138
+ - `labelStyle` `CSSProperties` custom label's style, `optional`.
139
+ - `labelWidth` `CSSProperties['width']`, the width of the label label.
140
+ - `labelAlign` `CSSProperties['textAlign']`, the label label's textAlign property.
141
+ - `inline` `boolea`, Whether or not field display components have inline layout.
142
+ - `layout` `'horizontal'|'vertical'` field’s display components set the layout type, the default value is `horizontal`.
143
+ - `colon` `boolean` whether add colon
144
+ - `required` `boolean` Indicates that the value of the field is required `optional`。
145
+ - `gutter` `number` The distance between field's display component custom labels and form components, `optional`.
146
+ - `error` `string` form field displays the component's error message field.
147
+ - `suffix` `React.ReactNode` Suffix node, `optional`.
148
+ - `footer` `React.ReactNode` bootom node, `optional`.
149
+ - `tooltip` `string` Tip icon to prompt for information. `optional`.
150
+ - `compact` `boolean` Whether or not compact, will remove the component's `margin-bottom`. `optional`.
151
+
152
+ ### Form Props
153
+ Inherited field display component
154
+
155
+ - `className` The class name of the form element, `optional`.
156
+ - `form` The form data store, `required`.
157
+ - `tagName` Replace the element tag name of the form, default `form` tag
158
+ - `initialValues` The initial value of the form, which is overridden by the `initialValue` of the form field, Note that this value can only initialise the form `optional`.
159
+ - `onSubmit` `form` tag triggers the reset default event, only `button` tags that provide `htmlType=submit` can trigger `optional`.
160
+ - `onReset` `form` tag triggers the reset default event, only `button` tags that provide `htmlType=reset` can trigger `optional`.
161
+ - `onFieldsChange` The event function when a form changes onChange will only be triggered by the control's active `onChange`, not by `form.setFieldValue` and `form.setFieldsValue`, avoiding circular calls。`optional`.
162
+ - `onValuesChange` Listening for changes in form values.`optional`.
163
+ - `watch` Listens for changes in the value of any field.
164
+
165
+ ### Form.Item Props
166
+ Inherited field display component
167
+
168
+ - `className` Form field class name, `optional`.
169
+ - `component` field display component.
170
+ - `name` Form field name, `optional`.
171
+ - `trigger` Sets the event name of the form field to collect form values, default `onChange`.
172
+ - `validateTrigger` Sets the event for trigger form field validation, default `onChange`.
173
+ - `valueProp` The field name of the value in the callback function object, the default value is `'value'`.
174
+ - `valueGetter` A function to format the output form value, used with `valueSetter`, `optional`.
175
+ - `valueSetter` function to format input form value, used with `valueGetter`, `optional`.
176
+ - `rules` Checksum rules for form fields `optional`.
177
+ - `initialValue` The initial value of the form field, note that this value is different from `value` when the form is rendered for the first time.
178
+ - `onFieldsChange` The event function when the value of the control changes will only be triggered by the control's active `onChange`, not by `form.setFieldValue` and `form.setFieldsValue`, avoiding circular calls. `optional`.
179
+ - `onValuesChange` Listening for changes in form values.`optional`。
180
+ - `errorClassName` add a custom class name when there is an error message, `optional`.
181
+
182
+ ### Form.List Props
183
+ Inherited field display component
184
+
185
+ - `className` Form field class name, `optional`.
186
+ - `component` field display component.
187
+ - `name` Form field name, `optional`.
188
+ - `initialValue` Form field initial value, Note that this value can only initialise the form `optional`.
189
+ - `rules` Checksum rules for form fields `optional`.
190
+
191
+ ### rules
192
+ The rules in the fields of the values in `rules` perform the checks in order, and only one rule can be set for each item in `rules`.
193
+ - `validateTrigger` `string` Event to trigger validate form rules, default `onChange`.
194
+ - `message` `string` Default error message when a check rule reports an error `optional`。
195
+ - `required` `boolean` The required symbol is marked, and a `required` attribute of `true` in `rules` also automatically adds the required symbol `optional`。
196
+ - `validator` `(value) => void | boolean` Custom check function, `value` is the current control value `optional`.
197
+ - `pattern` `RegExp | string` Expression check, error if does not match `optional`.
198
+ - `whitespace` `boolean` space check `optional`.
199
+ - `max` `number` Maximum length for string type; maximum length for number type; maximum length for array type `optional`.
200
+ - `min` `number` minimum length for `string` type; minimum value for `number` type; minimum length for `array` type. `optional`.
201
+
202
+ ### SimpleForm
203
+ To create an instance of `form` via `useSimpleForm`, use the following:
204
+ - `form.getFieldValue(path?: string)` Returns the value of the form field for which `path` is specified, or the value of the whole form without `name`.
205
+ - `form.setFieldValue(path, value)` Update the value of a form field
206
+ - `form.setFieldsValue(obj: Partial<T>)` Set the value of the form field (override).
207
+ - `form.reset(values?: Partial<T>)` Reset the form.The value can be passed to reset to the target value.
208
+ - `form.validate(path?: string)` Checks form and returns error messages and form values.
209
+ - `form.getFieldError(path?: string)` Returns the target's error message or all error messages.
210
+
211
+ ### Hooks
212
+
213
+ - `useSimpleForm(defaultValues)` create `new SimpleForm()`
214
+ - `useFormError(form: SimpleForm, path?: string)` Use hooks to get the specified form error.
215
215
  - 3.0.12 `useFormValues(form: SimpleForm, path?: string | string[])` Use hooks to get the specified form values.
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@simpleform/form",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "simple form component",
5
5
  "author": "mezhanglei <496623925@qq.com>",
6
6
  "homepage": "https://github.com/mezhanglei/simpleform#readme",
7
7
  "license": "ISC",
8
8
  "main": "lib/index.js",
9
- "module": "es/index.js",
10
9
  "types": "./lib/index.d.ts",
11
10
  "directories": {
12
11
  "lib": "lib",
@@ -27,6 +26,7 @@
27
26
  "registry": "https://registry.npmjs.org/"
28
27
  },
29
28
  "scripts": {
29
+ "build:dist": "cross-env NODE_ENV=dist webpack --progress --config ./webpack/webpack.prod.js",
30
30
  "build": "cross-env NODE_ENV=prod webpack --progress --config ./webpack/webpack.prod.js && tsc -d",
31
31
  "stats": "cross-env NODE_ENV=prod webpack --progress --config ./webpack/webpack.prod.js --json > stats.json",
32
32
  "start": "cross-env NODE_ENV=dev webpack serve --config ./webpack/webpack.dev.js",
@@ -47,9 +47,9 @@
47
47
  "react-tooltip": "^5.23.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "antd": "4.0.0",
51
- "react": "^16.8.0",
52
- "react-dom": "^16.8.0",
53
- "react-router-dom": "^5.0.0"
50
+ "antd": ">=4.0.0",
51
+ "react": ">=16.8.0",
52
+ "react-dom": ">=16.8.0",
53
+ "react-router-dom": ">=5.0.0"
54
54
  }
55
- }
55
+ }