@carefrees/form-utils-react-hooks 0.0.6 → 0.0.7
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 +264 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,9 +1,264 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
# 公共hooks
|
|
2
|
+
|
|
3
|
+
## 安装
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @carefrees/form-utils-react-hooks # yarn add @carefrees/form-utils-react-hooks # pnpm add @carefrees/form-utils-react-hooks
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Form表单
|
|
10
|
+
|
|
11
|
+
- useForm: 初始化表单实例
|
|
12
|
+
- useFormInstance: 子项中获取表单实例
|
|
13
|
+
- useFormItem: 初始化表单项实例
|
|
14
|
+
- useFormItemInstance: 子项中获取表单项实例
|
|
15
|
+
- useFormList: 初始化表单List实例
|
|
16
|
+
- useFormListInstance: 子项中获取表单List实例
|
|
17
|
+
- useMultipleForm: 初始化 多表单收集 实例
|
|
18
|
+
- useMultipleFormInstance: 子项中获取 多表单收集 实例
|
|
19
|
+
- useWatch: 监听表单某个值变化
|
|
20
|
+
- useAttrs: 获取布局公共属性
|
|
21
|
+
- useFormItemParentName: 获取表单父级name
|
|
22
|
+
- useHtmlFor: 生成label标签的for属性
|
|
23
|
+
|
|
24
|
+
### 注册
|
|
25
|
+
|
|
26
|
+
- useRegisterForm: 注册表单实例到多表单收集实例中
|
|
27
|
+
- useRegisterFormHideItem: 注册表单隐藏表单项到表单实例中
|
|
28
|
+
- useRegisterFormItem: 注册表单项到表单实例中
|
|
29
|
+
- useRegisterFormList: 注册表单List到表单实例中
|
|
30
|
+
|
|
31
|
+
### Context
|
|
32
|
+
|
|
33
|
+
- FormInstanceContext: 表单实例
|
|
34
|
+
- FormItemInstanceContext: 表单项实例
|
|
35
|
+
- FormListInstanceContext: 表单List实例
|
|
36
|
+
- MultipleFormInstanceContext: 多表单收集实例
|
|
37
|
+
- FormItemParentNameContext: 表单父级name
|
|
38
|
+
- AttrsContext: 布局公共属性
|
|
39
|
+
|
|
40
|
+
### Provider
|
|
41
|
+
|
|
42
|
+
- MultipleFormProvider: 多表单收集 Provider
|
|
43
|
+
|
|
44
|
+
## 类型
|
|
45
|
+
|
|
46
|
+
### useForm
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { FormInstanceBase } from '@carefrees/form-utils';
|
|
50
|
+
/**表单实例 Context */
|
|
51
|
+
export declare const FormInstanceContext: import("react").Context<FormInstanceBase<any>>;
|
|
52
|
+
/**子项中获取表单实例*/
|
|
53
|
+
export declare function useFormInstance<T = any>(): FormInstanceBase<T>;
|
|
54
|
+
/**初始化表单实例*/
|
|
55
|
+
export declare function useForm<T = any>(form?: FormInstanceBase<T>): FormInstanceBase<T>;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### useFormItem
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { FormItemInstanceBase } from '@carefrees/form-utils';
|
|
62
|
+
/**表单项实例 Context */
|
|
63
|
+
export declare const FormItemInstanceContext: import("react").Context<FormItemInstanceBase>;
|
|
64
|
+
/**子项中获取表单项实例*/
|
|
65
|
+
export declare const useFormItemInstance: () => FormItemInstanceBase;
|
|
66
|
+
/**s初始化 表单项实例*/
|
|
67
|
+
export declare const useFormItem: (formItem?: FormItemInstanceBase) => FormItemInstanceBase;
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### useFormList
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { FormListInstanceBase } from '@carefrees/form-utils';
|
|
74
|
+
/**表单List实例 Context */
|
|
75
|
+
export declare const FormListInstanceContext: import("react").Context<FormListInstanceBase>;
|
|
76
|
+
/**子项中获取表单List实例*/
|
|
77
|
+
export declare const useFormListInstance: () => FormListInstanceBase;
|
|
78
|
+
/**初始化 表单List实例*/
|
|
79
|
+
export declare const useFormList: (formList?: FormListInstanceBase) => FormListInstanceBase;
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### useMultipleForm
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { MultipleInstanceBase } from '@carefrees/form-utils';
|
|
87
|
+
/**多表单收集 Context */
|
|
88
|
+
export declare const MultipleFormInstanceContext: import("react").Context<MultipleInstanceBase>;
|
|
89
|
+
/**子项中获取 多表单收集 实例*/
|
|
90
|
+
export declare const useMultipleFormInstance: () => MultipleInstanceBase;
|
|
91
|
+
/**初始化 多表单收集 实例*/
|
|
92
|
+
export declare const useMultipleForm: (multipleForm?: MultipleInstanceBase) => MultipleInstanceBase;
|
|
93
|
+
export interface MultipleFormProviderProps {
|
|
94
|
+
children: React.ReactNode;
|
|
95
|
+
multipleForm?: MultipleInstanceBase;
|
|
96
|
+
}
|
|
97
|
+
/**多表单收集 Provider */
|
|
98
|
+
export declare const MultipleFormProvider: (props: MultipleFormProviderProps) => import("react").FunctionComponentElement<import("react").ProviderProps<MultipleInstanceBase>>;
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### useWatch
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { FormInstanceBase } from '@carefrees/form-utils';
|
|
105
|
+
export declare class WatchInstanceBase {
|
|
106
|
+
/**监听字段*/
|
|
107
|
+
name: string;
|
|
108
|
+
/**表单实例*/
|
|
109
|
+
form: FormInstanceBase;
|
|
110
|
+
/**老值*/
|
|
111
|
+
oldValue: any;
|
|
112
|
+
/**更新值*/
|
|
113
|
+
dispatch: (value: any) => void;
|
|
114
|
+
/**回调*/
|
|
115
|
+
callBack?: (value: any, form: FormInstanceBase) => void;
|
|
116
|
+
/**更新*/
|
|
117
|
+
updated: () => void;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 字段监听
|
|
121
|
+
*/
|
|
122
|
+
export declare const useWatch: (name: string, form: FormInstanceBase, callBack?: (value: any, form: FormInstanceBase) => void) => [any, FormInstanceBase, WatchInstanceBase];
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### useAttrs
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
export interface AttrsOptions {
|
|
130
|
+
/**列数据*/
|
|
131
|
+
colCount?: number;
|
|
132
|
+
/**规则校验失败错误提示位置*/
|
|
133
|
+
errorLayout?: 'left-bottom' | 'right-bottom' | 'top-right' | 'top-left';
|
|
134
|
+
/**
|
|
135
|
+
* label显示模式
|
|
136
|
+
* @platform taro 支持 between
|
|
137
|
+
*/
|
|
138
|
+
labelMode?: 'left' | 'top' | 'between' | 'hide';
|
|
139
|
+
/**是否显示label后的冒号*/
|
|
140
|
+
showColon?: boolean;
|
|
141
|
+
/**表单项 className*/
|
|
142
|
+
formItemClassName?: string;
|
|
143
|
+
/**表单项 style*/
|
|
144
|
+
formItemStyle?: React.CSSProperties;
|
|
145
|
+
/**表单项 label className*/
|
|
146
|
+
formItemLabelClassName?: string;
|
|
147
|
+
/**表单项 label style*/
|
|
148
|
+
formItemLabelStyle?: React.CSSProperties;
|
|
149
|
+
/**
|
|
150
|
+
* 输入框底部边框
|
|
151
|
+
* @platform taro
|
|
152
|
+
*/
|
|
153
|
+
inputBordered?: boolean;
|
|
154
|
+
}
|
|
155
|
+
/**公共属性 Context */
|
|
156
|
+
export declare const AttrsContext: import("react").Context<AttrsOptions>;
|
|
157
|
+
/**子项中获取公共属性*/
|
|
158
|
+
export declare const useAttrs: () => AttrsOptions;
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### useFormItemParentName
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
export declare const FormItemParentNameContext: import("react").Context<{
|
|
165
|
+
name: string;
|
|
166
|
+
sort: string;
|
|
167
|
+
}>;
|
|
168
|
+
export interface FormItemParentNamOptions {
|
|
169
|
+
/**字段*/
|
|
170
|
+
name: string;
|
|
171
|
+
/**排序*/
|
|
172
|
+
sort?: string;
|
|
173
|
+
/**是否拼接父级字段*/
|
|
174
|
+
isJoinParentField?: boolean;
|
|
175
|
+
}
|
|
176
|
+
interface FormItemParentNameProviderProps extends Omit<FormItemParentNamOptions, 'isJoinParentField'> {
|
|
177
|
+
children?: React.ReactNode;
|
|
178
|
+
}
|
|
179
|
+
export declare const FormItemParentNameProvider: (props: FormItemParentNameProviderProps) => import("react").FunctionComponentElement<import("react").ProviderProps<{
|
|
180
|
+
name: string;
|
|
181
|
+
sort: string;
|
|
182
|
+
}>>;
|
|
183
|
+
/**表单项获取父级字段*/
|
|
184
|
+
export declare const useFormItemParentName: (options: FormItemParentNamOptions) => {
|
|
185
|
+
newName: string;
|
|
186
|
+
newSort: string;
|
|
187
|
+
parentItem: {
|
|
188
|
+
name: string;
|
|
189
|
+
sort: string;
|
|
190
|
+
};
|
|
191
|
+
parentName: string;
|
|
192
|
+
};
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### useHtmlFor
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
export declare const useHtmlFor: (suffix: string) => string;
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### useRegisterForm
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
import { FormInstanceBase } from '@carefrees/form-utils';
|
|
205
|
+
/**注册表单实例到多表单收集实例中*/
|
|
206
|
+
export declare const useRegisterForm: (form: FormInstanceBase, name?: string) => import("@carefrees/form-utils").MultipleInstanceBase;
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### useRegisterFormHideItem
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
import { RegisterFormItemOptions } from './register.FormItem';
|
|
214
|
+
interface RegisterFormHideItemOptions extends Omit<RegisterFormItemOptions, 'rules'> {
|
|
215
|
+
}
|
|
216
|
+
/**注册表单隐藏表单项到表单实例中*/
|
|
217
|
+
export declare const useRegisterFormHideItem: (options: RegisterFormHideItemOptions) => {
|
|
218
|
+
form: import("@carefrees/form-utils").FormInstanceBase<any>;
|
|
219
|
+
isHide: any;
|
|
220
|
+
};
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### useRegisterFormItem
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
/**
|
|
227
|
+
* @description 注册组件
|
|
228
|
+
*/
|
|
229
|
+
import { RuleInstanceBase } from '@carefrees/form-utils';
|
|
230
|
+
import type { RuleItem } from 'async-validator';
|
|
231
|
+
export interface RegisterFormItemOptions {
|
|
232
|
+
/**字段*/
|
|
233
|
+
name: string;
|
|
234
|
+
/**规则*/
|
|
235
|
+
rules?: RuleItem[];
|
|
236
|
+
/**排序值*/
|
|
237
|
+
sort?: string;
|
|
238
|
+
/**是否拼接父级字段*/
|
|
239
|
+
isJoinParentField?: boolean;
|
|
240
|
+
}
|
|
241
|
+
/**注册表单项到表单实例中*/
|
|
242
|
+
export declare const useRegisterFormItem: (options: RegisterFormItemOptions) => {
|
|
243
|
+
ruleInstance: RuleInstanceBase;
|
|
244
|
+
formItemInstance: import("@carefrees/form-utils").FormItemInstanceBase;
|
|
245
|
+
form: import("@carefrees/form-utils").FormInstanceBase<any>;
|
|
246
|
+
parentName: string;
|
|
247
|
+
newName: string;
|
|
248
|
+
};
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### useRegisterFormList
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
import { RegisterFormItemOptions } from './register.FormItem';
|
|
255
|
+
export interface RegisterFormListOptions extends RegisterFormItemOptions {
|
|
256
|
+
}
|
|
257
|
+
/**注册表单List到表单实例中*/
|
|
258
|
+
export declare const useRegisterFormList: (options: RegisterFormListOptions) => {
|
|
259
|
+
ruleInstance: import("@carefrees/form-utils").RuleInstanceBase;
|
|
260
|
+
formItemInstance: import("@carefrees/form-utils").FormItemInstanceBase;
|
|
261
|
+
formListInstance: import("@carefrees/form-utils").FormListInstanceBase;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
```
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "SunLxy <1011771396@qq.com>",
|
|
4
4
|
"description": "表单组件公共hooks",
|
|
5
5
|
"homepage": "https://github.com/SunLxy/carefrees-form-utils",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.7",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"types": "lib/index.d.ts",
|
|
9
9
|
"module": "esm/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"esm"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@carefrees/form-utils": "^0.0.
|
|
24
|
+
"@carefrees/form-utils": "^0.0.7"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/react": "18.2.21",
|