react-form-manage 1.0.0 → 1.0.2
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 +36 -24
- package/dist/index.cjs +6 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +13 -0
- package/dist/index.esm.js +7 -21
- package/dist/index.esm.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -33,7 +33,12 @@ Thư viện cung cấp (named/default exports):
|
|
|
33
33
|
Ví dụ import:
|
|
34
34
|
|
|
35
35
|
```javascript
|
|
36
|
-
import Form, {
|
|
36
|
+
import Form, {
|
|
37
|
+
FormItem,
|
|
38
|
+
FormList,
|
|
39
|
+
Input,
|
|
40
|
+
InputWrapper,
|
|
41
|
+
} from "react-form-manage";
|
|
37
42
|
```
|
|
38
43
|
|
|
39
44
|
---
|
|
@@ -43,13 +48,17 @@ import Form, { FormItem, FormList, Input, InputWrapper } from 'react-form-manage
|
|
|
43
48
|
Ví dụ form đơn giản:
|
|
44
49
|
|
|
45
50
|
```jsx
|
|
46
|
-
import React from
|
|
47
|
-
import Form, { FormItem } from
|
|
48
|
-
import Input from
|
|
51
|
+
import React from "react";
|
|
52
|
+
import Form, { FormItem } from "react-form-manage";
|
|
53
|
+
import Input from "./path-to-package/Input";
|
|
49
54
|
|
|
50
55
|
function Example() {
|
|
51
56
|
return (
|
|
52
|
-
<Form
|
|
57
|
+
<Form
|
|
58
|
+
formName="myForm"
|
|
59
|
+
initialValues={{ name: "" }}
|
|
60
|
+
onFinish={(values) => console.log("submit", values)}
|
|
61
|
+
>
|
|
53
62
|
<FormItem name="name">
|
|
54
63
|
<Input />
|
|
55
64
|
</FormItem>
|
|
@@ -72,11 +81,11 @@ Bạn có thể lấy instance form để gọi phương thức chương trình
|
|
|
72
81
|
Ví dụ sử dụng hook attached trên `Form`:
|
|
73
82
|
|
|
74
83
|
```jsx
|
|
75
|
-
import React from
|
|
76
|
-
import Form from
|
|
84
|
+
import React from "react";
|
|
85
|
+
import Form from "react-form-manage";
|
|
77
86
|
|
|
78
87
|
function CtrlExample() {
|
|
79
|
-
const [form] = Form.useForm(
|
|
88
|
+
const [form] = Form.useForm("myForm"); // hoặc useForm('myForm')
|
|
80
89
|
|
|
81
90
|
return (
|
|
82
91
|
<div>
|
|
@@ -106,26 +115,28 @@ Methods available on the form instance (populated by `Form` provider):
|
|
|
106
115
|
Ví dụ:
|
|
107
116
|
|
|
108
117
|
```jsx
|
|
109
|
-
import React from
|
|
110
|
-
import Form, { FormList, FormItem } from
|
|
111
|
-
import Input from
|
|
118
|
+
import React from "react";
|
|
119
|
+
import Form, { FormList, FormItem } from "react-form-manage";
|
|
120
|
+
import Input from "./Input";
|
|
112
121
|
|
|
113
122
|
function ListExample() {
|
|
114
123
|
return (
|
|
115
124
|
<Form formName="listForm">
|
|
116
|
-
<FormList name="items">
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
<
|
|
121
|
-
<
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
<FormList name="items">
|
|
126
|
+
{(fields, { add, remove }) => (
|
|
127
|
+
<div>
|
|
128
|
+
{fields.map((f, i) => (
|
|
129
|
+
<div key={f.key}>
|
|
130
|
+
<FormItem name={f.name}>
|
|
131
|
+
<Input />
|
|
132
|
+
</FormItem>
|
|
133
|
+
<button onClick={() => remove({ index: i })}>Remove</button>
|
|
134
|
+
</div>
|
|
135
|
+
))}
|
|
136
|
+
<button onClick={() => add()}>Add</button>
|
|
137
|
+
</div>
|
|
138
|
+
)}
|
|
139
|
+
</FormList>
|
|
129
140
|
</Form>
|
|
130
141
|
);
|
|
131
142
|
}
|
|
@@ -175,6 +186,7 @@ Nếu bạn muốn tự sinh `.d.ts` từ JS, có thể thêm `tsconfig.types.js
|
|
|
175
186
|
## License
|
|
176
187
|
|
|
177
188
|
Mặc định chưa thêm license — nếu muốn public, hãy thêm `LICENSE` (ví dụ MIT).
|
|
189
|
+
|
|
178
190
|
# React + Vite
|
|
179
191
|
|
|
180
192
|
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,6 @@ var shallow = require('zustand/react/shallow');
|
|
|
6
6
|
var immer = require('immer');
|
|
7
7
|
var uuid = require('uuid');
|
|
8
8
|
var zustand = require('zustand');
|
|
9
|
-
var antd = require('antd');
|
|
10
9
|
|
|
11
10
|
function _extends() {
|
|
12
11
|
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
@@ -459,7 +458,7 @@ var FormCleanUp = function FormCleanUp() {
|
|
|
459
458
|
return h(Fragment, null);
|
|
460
459
|
};
|
|
461
460
|
|
|
462
|
-
var _excluded$
|
|
461
|
+
var _excluded$3 = ["children", "formName", "initialValues", "onFinish", "onReject", "onFinally", "FormElement"];
|
|
463
462
|
function _catch(body, recover) {
|
|
464
463
|
try {
|
|
465
464
|
var result = body();
|
|
@@ -480,7 +479,7 @@ function Form(_ref) {
|
|
|
480
479
|
onReject = _ref.onReject,
|
|
481
480
|
onFinally = _ref.onFinally,
|
|
482
481
|
FormElement = _ref.FormElement,
|
|
483
|
-
props = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
482
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
484
483
|
var _useFormStore = useFormStore(shallow.useShallow(function (state) {
|
|
485
484
|
var _state$formStates;
|
|
486
485
|
return {
|
|
@@ -1879,7 +1878,7 @@ function useFormListControl(_ref) {
|
|
|
1879
1878
|
};
|
|
1880
1879
|
}
|
|
1881
1880
|
|
|
1882
|
-
var _excluded$
|
|
1881
|
+
var _excluded$2 = ["listFields"];
|
|
1883
1882
|
var FormList = function FormList(_ref) {
|
|
1884
1883
|
var name = _ref.name,
|
|
1885
1884
|
initialValues = _ref.initialValues,
|
|
@@ -1893,15 +1892,15 @@ var FormList = function FormList(_ref) {
|
|
|
1893
1892
|
formName: formName
|
|
1894
1893
|
}),
|
|
1895
1894
|
listFields = _useTestRrenderListCo.listFields,
|
|
1896
|
-
actions = _objectWithoutPropertiesLoose(_useTestRrenderListCo, _excluded$
|
|
1895
|
+
actions = _objectWithoutPropertiesLoose(_useTestRrenderListCo, _excluded$2);
|
|
1897
1896
|
return children(listFields, _extends({}, actions));
|
|
1898
1897
|
};
|
|
1899
1898
|
|
|
1900
|
-
var _excluded$
|
|
1899
|
+
var _excluded$1 = ["onChange", "ref"];
|
|
1901
1900
|
var Input = function Input(_ref) {
|
|
1902
1901
|
var _onChange = _ref.onChange,
|
|
1903
1902
|
ref = _ref.ref,
|
|
1904
|
-
props = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
1903
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
1905
1904
|
return h("input", _extends({
|
|
1906
1905
|
ref: ref,
|
|
1907
1906
|
onChange: function onChange(e) {
|
|
@@ -1910,19 +1909,6 @@ var Input = function Input(_ref) {
|
|
|
1910
1909
|
}, props));
|
|
1911
1910
|
};
|
|
1912
1911
|
|
|
1913
|
-
var _excluded$1 = ["onChange", "isValidating"];
|
|
1914
|
-
var AntInput = function AntInput(_ref) {
|
|
1915
|
-
var _onChange = _ref.onChange,
|
|
1916
|
-
isValidating = _ref.isValidating,
|
|
1917
|
-
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
1918
|
-
return h(antd.Input, _extends({}, props, {
|
|
1919
|
-
onChange: function onChange(e) {
|
|
1920
|
-
_onChange && _onChange(e.target.value);
|
|
1921
|
-
},
|
|
1922
|
-
disabled: isValidating
|
|
1923
|
-
}));
|
|
1924
|
-
};
|
|
1925
|
-
|
|
1926
1912
|
var _excluded = ["children", "errors"];
|
|
1927
1913
|
var InputWrapper = function InputWrapper(_ref) {
|
|
1928
1914
|
var children = _ref.children,
|
|
@@ -1936,7 +1922,6 @@ var InputWrapper = function InputWrapper(_ref) {
|
|
|
1936
1922
|
})));
|
|
1937
1923
|
};
|
|
1938
1924
|
|
|
1939
|
-
exports.AntInput = AntInput;
|
|
1940
1925
|
exports.FormItem = FormItem;
|
|
1941
1926
|
exports.FormList = FormList;
|
|
1942
1927
|
exports.Input = Input;
|