@carefrees/form-utils-react-taro 0.0.5 → 0.0.6
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 +232 -9
- package/esm/index.js +1 -1
- package/lib/index.js +1 -1
- package/package.json +3 -3
- package/src/index.tsx +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,232 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
# taro中使用
|
|
2
|
+
|
|
3
|
+
## 安装
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @carefrees/form-utils-react-taro # yarn add @carefrees/form-utils-react-taro # pnpm add @carefrees/form-utils-react-taro
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## 使用
|
|
10
|
+
|
|
11
|
+
### 基本使用
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Form, FormItem } from '@carefrees/form-utils-react-taro';
|
|
15
|
+
import React ,{ useState } from 'react';
|
|
16
|
+
import { View, Button, Input } from '@tarojs/components';
|
|
17
|
+
|
|
18
|
+
const Demo = ()=>{
|
|
19
|
+
const [formData]= useState({ name: '张三', age: 18 })
|
|
20
|
+
const form = useForm();
|
|
21
|
+
|
|
22
|
+
const onSubmit = async () =>{
|
|
23
|
+
try {
|
|
24
|
+
console.log(form);
|
|
25
|
+
const result = await form.validate();
|
|
26
|
+
console.log(result);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.log(error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return (<Form formData={formData} form={form} >
|
|
33
|
+
<FormItem trigger="onInput" rules={[{ required: true, message: '必填' }]} name="name" label="name">
|
|
34
|
+
<Input style={{ width: '100%' }} placeholder="请输入" />
|
|
35
|
+
</FormItem>
|
|
36
|
+
<FormItem trigger="onInput" name="age" label="age">
|
|
37
|
+
<Input style={{ width: '100%' }} placeholder="请输入" />
|
|
38
|
+
</FormItem>
|
|
39
|
+
<Button onClick={onSubmit}>
|
|
40
|
+
验😁😝证
|
|
41
|
+
</Button>
|
|
42
|
+
</Form>)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 控制隐藏
|
|
48
|
+
|
|
49
|
+
### 表单字段监听
|
|
50
|
+
|
|
51
|
+
### list表单项
|
|
52
|
+
|
|
53
|
+
### 表单项之间联动校验
|
|
54
|
+
|
|
55
|
+
### 表单输入框属性联动设置
|
|
56
|
+
|
|
57
|
+
### 布局组件
|
|
58
|
+
|
|
59
|
+
## 类型
|
|
60
|
+
|
|
61
|
+
### Form表单
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import React from 'react';
|
|
65
|
+
import { FormInstanceBase, ValidateErrorEntity } from '@carefrees/form-utils';
|
|
66
|
+
import { FormLayoutProps } from '@carefrees/form-utils-react-taro/esm/layout';
|
|
67
|
+
export interface FormProps<T = any> extends FormLayoutProps {
|
|
68
|
+
children?: React.ReactNode;
|
|
69
|
+
form?: FormInstanceBase;
|
|
70
|
+
style?: React.CSSProperties;
|
|
71
|
+
className?: string;
|
|
72
|
+
layoutClassName?: string;
|
|
73
|
+
layoutStyle?: React.CSSProperties;
|
|
74
|
+
/**表单数据*/
|
|
75
|
+
formData?: any;
|
|
76
|
+
/**值更新触发*/
|
|
77
|
+
onValuesChange?: (changedValues: Partial<T>, values: T) => void;
|
|
78
|
+
/**提交保存 验证成功*/
|
|
79
|
+
onFinish?: (values: T) => void;
|
|
80
|
+
/**提交保存 验证失败*/
|
|
81
|
+
onFinishFailed?: (errorInfo: ValidateErrorEntity<T>) => void;
|
|
82
|
+
/**隐藏表单项初始值*/
|
|
83
|
+
hideData?: Record<string, boolean>;
|
|
84
|
+
/**表单名称*/
|
|
85
|
+
name?: string;
|
|
86
|
+
/**隐藏规则校验*/
|
|
87
|
+
hideRuleData?: Record<string, boolean>;
|
|
88
|
+
/**自动重置更新formData数据*/
|
|
89
|
+
isAutoUpdatedFormData?: boolean;
|
|
90
|
+
}
|
|
91
|
+
export declare function Form<T = any>(props: FormProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### FormItem表单项
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { LayoutFormItemProps } from '@carefrees/form-utils-react-taro/esm/layout/layout.formItem';
|
|
99
|
+
import { FormItemAttrOptions } from '@carefrees/form-utils-react-taro/esm/hooks/attr/attr.FormItem';
|
|
100
|
+
export interface FormItemProps extends FormItemAttrOptions, LayoutFormItemProps {
|
|
101
|
+
/**不进行样式渲染*/
|
|
102
|
+
noStyle?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**表单项*/
|
|
105
|
+
export declare const FormItem: import("react").MemoExoticComponent<(props: Partial<FormItemProps>) => import("react/jsx-runtime").JSX.Element>;
|
|
106
|
+
/**隐藏表单项*/
|
|
107
|
+
export declare const FormHideItem: import("react").MemoExoticComponent<(props: FormItemProps) => import("react/jsx-runtime").JSX.Element>;
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### FormList表单List
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { RuleInstanceBase, FormItemInstanceBase, FormListInstanceBase } from '@carefrees/form-utils';
|
|
115
|
+
import React from 'react';
|
|
116
|
+
import { RegisterFormListOptions } from '@carefrees/form-utils-react-hooks';
|
|
117
|
+
export interface FormListChildrenProps {
|
|
118
|
+
/**数据集合*/
|
|
119
|
+
fields: {
|
|
120
|
+
name: number;
|
|
121
|
+
key: number;
|
|
122
|
+
}[];
|
|
123
|
+
/**添加*/
|
|
124
|
+
onAdd: (initialValue?: Object) => void;
|
|
125
|
+
/**删除*/
|
|
126
|
+
onDelete: (index: number | number[]) => void;
|
|
127
|
+
/**移动*/
|
|
128
|
+
onMove: (from: number, to: number) => void;
|
|
129
|
+
}
|
|
130
|
+
export interface FormListProps extends RegisterFormListOptions {
|
|
131
|
+
children: (options: FormListChildrenProps, instances: {
|
|
132
|
+
ruleInstance: RuleInstanceBase;
|
|
133
|
+
formItemInstance: FormItemInstanceBase;
|
|
134
|
+
formListInstance: FormListInstanceBase;
|
|
135
|
+
}) => React.ReactNode;
|
|
136
|
+
}
|
|
137
|
+
/**form list 组件*/
|
|
138
|
+
export declare const FormList: React.MemoExoticComponent<(props: FormListProps) => import("react/jsx-runtime").JSX.Element>;
|
|
139
|
+
/**隐藏 form list item 组件*/
|
|
140
|
+
export declare const FormHideList: React.MemoExoticComponent<(props: FormListProps) => import("react/jsx-runtime").JSX.Element>;
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### 布局组件 类型
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
import React from 'react';
|
|
148
|
+
import { ViewProps } from '@tarojs/components';
|
|
149
|
+
import { AttrsOptions } from '@carefrees/form-utils-react-hooks';
|
|
150
|
+
export interface FormLayoutProps extends AttrsOptions {
|
|
151
|
+
/**标题*/
|
|
152
|
+
title?: React.ReactNode;
|
|
153
|
+
/**额外内容*/
|
|
154
|
+
extra?: React.ReactNode;
|
|
155
|
+
/**内容*/
|
|
156
|
+
children?: React.ReactNode;
|
|
157
|
+
/**是否占据整行*/
|
|
158
|
+
isAllColSpan?: boolean;
|
|
159
|
+
className?: string;
|
|
160
|
+
/**头部ClassName*/
|
|
161
|
+
headerClassName?: string;
|
|
162
|
+
/**内容ClassName*/
|
|
163
|
+
bodyClassName?: string;
|
|
164
|
+
style?: React.CSSProperties;
|
|
165
|
+
/**头部样式*/
|
|
166
|
+
headerStyle?: React.CSSProperties;
|
|
167
|
+
/**内容样式*/
|
|
168
|
+
bodyStyle?: React.CSSProperties;
|
|
169
|
+
/**是否添加边框*/
|
|
170
|
+
bordered?: boolean;
|
|
171
|
+
/**列数据*/
|
|
172
|
+
colCount?: number;
|
|
173
|
+
/**
|
|
174
|
+
* @description gap 属性是用来设置网格行与列之间的间隙,该属性是row-gap and column-gap的简写形式。
|
|
175
|
+
*/
|
|
176
|
+
gap?: string | number;
|
|
177
|
+
}
|
|
178
|
+
/**布局组件*/
|
|
179
|
+
export declare const FormLayout: React.MemoExoticComponent<(props: FormLayoutProps) => import("react/jsx-runtime").JSX.Element>;
|
|
180
|
+
/**布局组件 占据一整行*/
|
|
181
|
+
export declare const FormLayoutRows: (props: ViewProps) => import("react/jsx-runtime").JSX.Element;
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 表单项布局组件类型
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
import React from 'react';
|
|
188
|
+
export interface LayoutFormItemProps {
|
|
189
|
+
/**规则校验失败错误提示位置*/
|
|
190
|
+
errorLayout?: 'left-bottom' | 'right-bottom' | 'top-right' | 'top-left';
|
|
191
|
+
/**必填样式*/
|
|
192
|
+
required?: boolean;
|
|
193
|
+
/**label显示模式*/
|
|
194
|
+
labelMode?: 'left' | 'top' | 'between' | 'hide';
|
|
195
|
+
/**内容*/
|
|
196
|
+
children?: React.ReactNode;
|
|
197
|
+
/**只进行规则样式*/
|
|
198
|
+
onlyRuleStyle?: boolean;
|
|
199
|
+
label?: React.ReactNode;
|
|
200
|
+
/**底部提示内容*/
|
|
201
|
+
helpText?: React.ReactNode;
|
|
202
|
+
/**额外内容*/
|
|
203
|
+
extra?: React.ReactNode;
|
|
204
|
+
/**是否显示label后的冒号*/
|
|
205
|
+
showColon?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* 表单项占据列数
|
|
208
|
+
* @default 1
|
|
209
|
+
*/
|
|
210
|
+
colSpan?: number;
|
|
211
|
+
/**
|
|
212
|
+
* 表单项占据行数
|
|
213
|
+
* @default 1
|
|
214
|
+
*/
|
|
215
|
+
rowSpan?: number;
|
|
216
|
+
htmlFor?: string;
|
|
217
|
+
/**规则验证结果*/
|
|
218
|
+
validateResult?: {
|
|
219
|
+
tip: string | (string | undefined)[];
|
|
220
|
+
isInvalid: boolean;
|
|
221
|
+
};
|
|
222
|
+
style?: React.CSSProperties;
|
|
223
|
+
className?: string;
|
|
224
|
+
labelStyle?: React.CSSProperties;
|
|
225
|
+
labelClassName?: string;
|
|
226
|
+
/**底部边框*/
|
|
227
|
+
inputBordered?: boolean;
|
|
228
|
+
}
|
|
229
|
+
/**布局组件 表单项*/
|
|
230
|
+
export declare const LayoutFormItem: React.MemoExoticComponent<(props: LayoutFormItemProps) => import("react/jsx-runtime").JSX.Element>;
|
|
231
|
+
|
|
232
|
+
```
|
package/esm/index.js
CHANGED
|
@@ -21,7 +21,7 @@ function Form(props) {
|
|
|
21
21
|
formInstance.onValuesChange = onValuesChange;
|
|
22
22
|
formInstance.onFinishFailed = onFinishFailed;
|
|
23
23
|
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
24
|
-
if (isAutoUpdatedFormData) formInstance.
|
|
24
|
+
if (isAutoUpdatedFormData) formInstance.resetFormValues(formData);
|
|
25
25
|
}, [
|
|
26
26
|
isAutoUpdatedFormData,
|
|
27
27
|
formData
|
package/lib/index.js
CHANGED
|
@@ -150,7 +150,7 @@ var __webpack_exports__ = {};
|
|
|
150
150
|
formInstance.onValuesChange = onValuesChange;
|
|
151
151
|
formInstance.onFinishFailed = onFinishFailed;
|
|
152
152
|
(0, react__WEBPACK_IMPORTED_MODULE_1__.useEffect)(()=>{
|
|
153
|
-
if (isAutoUpdatedFormData) formInstance.
|
|
153
|
+
if (isAutoUpdatedFormData) formInstance.resetFormValues(formData);
|
|
154
154
|
}, [
|
|
155
155
|
isAutoUpdatedFormData,
|
|
156
156
|
formData
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "SunLxy <1011771396@qq.com>",
|
|
4
4
|
"description": "taro react 表单组件",
|
|
5
5
|
"homepage": "https://github.com/SunLxy/carefrees-form-utils",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.6",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"types": "lib/index.d.ts",
|
|
9
9
|
"module": "esm/index.js",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"esm"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@carefrees/form-utils": "^0.0.
|
|
25
|
-
"@carefrees/form-utils-react-hooks": "^0.0.
|
|
24
|
+
"@carefrees/form-utils": "^0.0.6",
|
|
25
|
+
"@carefrees/form-utils-react-hooks": "^0.0.6",
|
|
26
26
|
"classnames": "2.5.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
package/src/index.tsx
CHANGED