@fairys/valtio-form-basic 0.0.12 → 1.0.0
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 +935 -2
- package/esm/{form → common}/hooks/index.d.ts +1 -0
- package/esm/{form → common}/hooks/index.js +9 -1
- package/esm/common/index.d.ts +4 -0
- package/esm/common/index.js +4 -0
- package/esm/{form → common}/instance/index.d.ts +34 -7
- package/esm/{form → common}/instance/index.js +45 -11
- package/esm/{form → common}/utils/index.d.ts +7 -0
- package/esm/{form → common}/utils/index.js +11 -1
- package/esm/form/form.d.ts +14 -8
- package/esm/form/form.item.d.ts +18 -7
- package/esm/form/form.item.js +56 -32
- package/esm/form/form.js +7 -4
- package/esm/form/layout.d.ts +4 -2591
- package/esm/form/layout.js +7 -4
- package/esm/index.d.ts +1 -2
- package/esm/index.js +1 -2
- package/esm/styles/index.css +20 -4
- package/lib/common/hooks/index.d.ts +35 -0
- package/lib/common/hooks/index.js +117 -0
- package/lib/common/index.d.ts +4 -0
- package/lib/common/index.js +87 -0
- package/lib/common/instance/index.d.ts +108 -0
- package/lib/common/instance/index.js +269 -0
- package/lib/common/interface.d.ts +4 -0
- package/lib/common/interface.js +18 -0
- package/lib/common/utils/index.d.ts +31 -0
- package/lib/common/utils/index.js +119 -0
- package/lib/form/form.d.ts +82 -0
- package/lib/form/form.item.d.ts +228 -0
- package/lib/form/form.item.js +327 -0
- package/lib/form/form.js +54 -0
- package/lib/form/layout.d.ts +153 -0
- package/lib/form/layout.js +196 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +18 -27
- package/lib/styles/index.css +308 -0
- package/package.json +5 -5
- package/src/{form → common}/hooks/index.tsx +9 -1
- package/src/common/index.ts +4 -0
- package/src/{form → common}/instance/index.ts +110 -21
- package/src/{form → common}/utils/index.ts +21 -0
- package/src/form/form.item.tsx +87 -40
- package/src/form/form.tsx +23 -9
- package/src/form/layout.tsx +9 -3
- package/src/index.tsx +4 -5
- /package/esm/{interface.d.ts → common/interface.d.ts} +0 -0
- /package/esm/{interface.js → common/interface.js} +0 -0
- /package/src/{interface.ts → common/interface.ts} +0 -0
package/src/form/form.item.tsx
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/**表单项*/
|
|
2
2
|
|
|
3
|
-
import { MObject } from 'interface';
|
|
3
|
+
import { MObject } from 'common/interface';
|
|
4
4
|
import React, { useEffect, useMemo } from 'react';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
|
-
import { useFairysValtioFormInstanceContextState, FairysValtioFormInstance } from '
|
|
6
|
+
import { useFairysValtioFormInstanceContextState, FairysValtioFormInstance } from 'common/instance';
|
|
7
7
|
import { useFairysValtioFormLayoutContext, FairysValtioFormLayoutContextOptions } from './layout';
|
|
8
|
-
import { FairysValtioFormParentAttrs, useFairysValtioFormAttrsName } from '
|
|
9
|
-
import { get } from '
|
|
8
|
+
import { FairysValtioFormParentAttrs, useFairysValtioFormAttrsName, useId } from 'common/hooks';
|
|
9
|
+
import { formatePath, get } from 'common/utils';
|
|
10
10
|
import { RuleItem } from 'async-validator';
|
|
11
11
|
|
|
12
|
-
export interface FairysValtioFormItemAttrsProps<T extends MObject<T> =
|
|
12
|
+
export interface FairysValtioFormItemAttrsProps<T extends MObject<T> = Record<string, any>> {
|
|
13
|
+
/**平台*/
|
|
14
|
+
platform?: 'pc' | 'rn' | 'taro';
|
|
13
15
|
/**
|
|
14
16
|
* 表单项名称 ,字段需要和存储的字段路径一致
|
|
15
17
|
*
|
|
@@ -26,6 +28,8 @@ export interface FairysValtioFormItemAttrsProps<T extends MObject<T> = object> {
|
|
|
26
28
|
label?: string;
|
|
27
29
|
/**传递组件字段*/
|
|
28
30
|
valuePropName?: string;
|
|
31
|
+
/**取值字段(默认 valuePropName字段值)*/
|
|
32
|
+
getValuePath?: string;
|
|
29
33
|
/**自定义获取值*/
|
|
30
34
|
getValueFromEvent?: (event: any, form: FairysValtioFormInstance<T>) => any;
|
|
31
35
|
/**值格式化*/
|
|
@@ -77,6 +81,11 @@ export interface FairysValtioFormItemAttrsProps<T extends MObject<T> = object> {
|
|
|
77
81
|
isJoinParentField?: boolean;
|
|
78
82
|
/**校验规则*/
|
|
79
83
|
rules?: RuleItem[];
|
|
84
|
+
|
|
85
|
+
/**卸载移除数据值
|
|
86
|
+
* @default true
|
|
87
|
+
*/
|
|
88
|
+
isRemoveValueOnUnmount?: boolean;
|
|
80
89
|
}
|
|
81
90
|
|
|
82
91
|
/**
|
|
@@ -122,7 +131,9 @@ export const FormItem = (props: FormItemProps) => {
|
|
|
122
131
|
* ```
|
|
123
132
|
*
|
|
124
133
|
*/
|
|
125
|
-
export function useFairysValtioFormItemAttrs<T extends MObject<T> =
|
|
134
|
+
export function useFairysValtioFormItemAttrs<T extends MObject<T> = Record<string, any>>(
|
|
135
|
+
props: FairysValtioFormItemAttrsProps<T>,
|
|
136
|
+
) {
|
|
126
137
|
const [layoutAttrs] = useFairysValtioFormLayoutContext();
|
|
127
138
|
const colCount = layoutAttrs.colCount || 1;
|
|
128
139
|
const parent_borderedType = layoutAttrs.itemBorderType || 'bottom';
|
|
@@ -138,10 +149,12 @@ export function useFairysValtioFormItemAttrs<T extends MObject<T> = object>(prop
|
|
|
138
149
|
const parent_isInvalidBorderRed = layoutAttrs.isInvalidBorderRed;
|
|
139
150
|
const parent_isInvalidTextRed = layoutAttrs.isInvalidTextRed;
|
|
140
151
|
const parent_showColon = layoutAttrs.showColon;
|
|
152
|
+
const parent_platform = layoutAttrs.platform;
|
|
141
153
|
|
|
142
154
|
const {
|
|
143
155
|
name,
|
|
144
156
|
valuePropName = 'value',
|
|
157
|
+
getValuePath = valuePropName,
|
|
145
158
|
getValueFromEvent,
|
|
146
159
|
formatValue,
|
|
147
160
|
onAfterUpdate,
|
|
@@ -166,6 +179,8 @@ export function useFairysValtioFormItemAttrs<T extends MObject<T> = object>(prop
|
|
|
166
179
|
isInvalidTextRed = parent_isInvalidTextRed,
|
|
167
180
|
isJoinParentField = true,
|
|
168
181
|
rules,
|
|
182
|
+
platform = parent_platform,
|
|
183
|
+
isRemoveValueOnUnmount = true,
|
|
169
184
|
} = props;
|
|
170
185
|
|
|
171
186
|
const {
|
|
@@ -179,39 +194,50 @@ export function useFairysValtioFormItemAttrs<T extends MObject<T> = object>(prop
|
|
|
179
194
|
const error = errorState[_name];
|
|
180
195
|
// 使用从 Form 中设置的规则
|
|
181
196
|
const _formItemRules = formInstance.rules?.[_name];
|
|
182
|
-
|
|
197
|
+
const id = useId(_name);
|
|
183
198
|
formInstance.nameToPaths[_name] = paths;
|
|
184
|
-
/**挂载校验规则*/
|
|
185
|
-
if (Array.isArray(rules) && rules.length) {
|
|
186
|
-
formInstance.mountRules[_name] = rules;
|
|
187
|
-
}
|
|
188
199
|
useEffect(() => {
|
|
200
|
+
if (Array.isArray(rules) && rules.length) {
|
|
201
|
+
formInstance.mountRules[_name] = rules;
|
|
202
|
+
}
|
|
189
203
|
return () => {
|
|
190
204
|
formInstance.removeRules(_name);
|
|
191
205
|
};
|
|
192
|
-
}, [_name]);
|
|
206
|
+
}, [_name, rules]);
|
|
193
207
|
|
|
194
208
|
const onValueChange = (event: any) => {
|
|
195
|
-
let
|
|
209
|
+
let _value = event;
|
|
196
210
|
const target = event?.detail || event?.target;
|
|
197
211
|
if (typeof getValueFromEvent === 'function') {
|
|
198
|
-
|
|
199
|
-
} else if (event && target && typeof target === 'object' &&
|
|
200
|
-
|
|
212
|
+
_value = getValueFromEvent(event, formInstance);
|
|
213
|
+
} else if (event && target && typeof target === 'object' && getValuePath in target) {
|
|
214
|
+
_value = get(target, formatePath(getValuePath));
|
|
201
215
|
}
|
|
202
216
|
if (typeof formatValue === 'function') {
|
|
203
|
-
|
|
217
|
+
_value = formatValue(_value, formInstance, event);
|
|
204
218
|
}
|
|
205
|
-
|
|
219
|
+
// 校验值是否有变化
|
|
220
|
+
if (value === _value) return;
|
|
221
|
+
|
|
222
|
+
formInstance.updatedValueByPaths(_name, _value);
|
|
206
223
|
if (typeof onAfterUpdate === 'function') {
|
|
207
|
-
onAfterUpdate(
|
|
224
|
+
onAfterUpdate(_value, formInstance, event);
|
|
208
225
|
}
|
|
209
226
|
};
|
|
210
227
|
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
return () => {
|
|
230
|
+
if (isRemoveValueOnUnmount) {
|
|
231
|
+
formInstance.removeValueByPaths(_name);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}, []);
|
|
235
|
+
|
|
211
236
|
/**基础组件参数*/
|
|
212
237
|
const baseControl = {
|
|
213
238
|
...attrs,
|
|
214
239
|
name,
|
|
240
|
+
id,
|
|
215
241
|
[valuePropName]: value,
|
|
216
242
|
[trigger]: onValueChange,
|
|
217
243
|
};
|
|
@@ -288,11 +314,10 @@ export function useFairysValtioFormItemAttrs<T extends MObject<T> = object>(prop
|
|
|
288
314
|
const itemBody_cls = useMemo(() => {
|
|
289
315
|
// 默认两端显示
|
|
290
316
|
return clsx(
|
|
291
|
-
'fairys-valtio-form-item-body fairystaroform__transition-all fairystaroform__duration-300 fairystaroform__relative fairystaroform__flex-1 fairystaroform__flex fairystaroform__box-border',
|
|
317
|
+
'fairys-valtio-form-item-body fairystaroform__transition-all fairystaroform__duration-300 fairystaroform__relative fairystaroform__flex-1 fairystaroform__flex fairystaroform__box-border fairystaroform__items-start',
|
|
292
318
|
{
|
|
293
319
|
'fairystaroform__flex-row fairystaroform__justify-start': labelMode === 'left',
|
|
294
320
|
'fairystaroform__flex-row fairystaroform__justify-end': labelMode === 'between' || labelMode === 'top',
|
|
295
|
-
'fairystaroform__flex-row': labelMode === 'top',
|
|
296
321
|
'fairystaroform__border-b fairystaroform__border-b-solid fairystaroform__border-b-gray-200 ':
|
|
297
322
|
itemBorderType === 'body',
|
|
298
323
|
'fairys-valtio-form-item-invalid-border-red': isInvalid && isInvalidBorderRed && itemBorderType === 'body',
|
|
@@ -333,20 +358,25 @@ export function useFairysValtioFormItemAttrs<T extends MObject<T> = object>(prop
|
|
|
333
358
|
'fairys-valtio-form-item-body-error fairystaroform__transition-all fairystaroform__duration-300 fairystaroform__w-full fairystaroform__flex fairystaroform__flex-row fairystaroform__box-border fairystaroform__text-red fairystaroform__absolute fairystaroform__text-[10px] fairystaroform__z-10',
|
|
334
359
|
{
|
|
335
360
|
'fairystaroform__bottom-[-14px] fairystaroform__left-0 fairystaroform__justify-start':
|
|
336
|
-
errorLayout === 'bottom-left',
|
|
361
|
+
errorLayout === 'bottom-left' && platform !== 'pc',
|
|
362
|
+
'fairystaroform__bottom-[-10px] fairystaroform__left-0 fairystaroform__justify-start':
|
|
363
|
+
errorLayout === 'bottom-left' && platform === 'pc',
|
|
337
364
|
'fairystaroform__bottom-[-14px] fairystaroform__right-0 fairystaroform__justify-end':
|
|
338
|
-
errorLayout === 'bottom-right',
|
|
365
|
+
errorLayout === 'bottom-right' && platform !== 'pc',
|
|
366
|
+
'fairystaroform__bottom-[-10px] fairystaroform__right-0 fairystaroform__justify-end':
|
|
367
|
+
errorLayout === 'bottom-right' && platform === 'pc',
|
|
339
368
|
'fairystaroform__top-[-4px] fairystaroform__right-0 fairystaroform__justify-end': errorLayout === 'top-right',
|
|
340
369
|
'fairystaroform__top-[-4px] fairystaroform__left-0 fairystaroform__justify-start': errorLayout === 'top-left',
|
|
341
370
|
/**边框底部提示*/
|
|
342
|
-
'fairystaroform__left-0
|
|
371
|
+
'fairystaroform__left-0 fairystaroform__bottom-[-2px] fairystaroform__justify-start':
|
|
343
372
|
errorLayout === 'left-border-top',
|
|
344
373
|
/**边框顶部提示*/
|
|
345
|
-
'fairystaroform__right-0
|
|
374
|
+
'fairystaroform__right-0 fairystaroform__bottom-[-2px] fairystaroform__justify-end':
|
|
346
375
|
errorLayout === 'right-border-top',
|
|
376
|
+
'fairystaroform__px-[4px]': platform === 'pc',
|
|
347
377
|
},
|
|
348
378
|
);
|
|
349
|
-
}, [errorLayout]);
|
|
379
|
+
}, [errorLayout, platform]);
|
|
350
380
|
|
|
351
381
|
const styleBase = useMemo(() => {
|
|
352
382
|
const css: React.CSSProperties = {};
|
|
@@ -377,6 +407,7 @@ export function useFairysValtioFormItemAttrs<T extends MObject<T> = object>(prop
|
|
|
377
407
|
error,
|
|
378
408
|
_name,
|
|
379
409
|
name,
|
|
410
|
+
id,
|
|
380
411
|
paths,
|
|
381
412
|
parentName,
|
|
382
413
|
formAttrsNameInstance,
|
|
@@ -405,7 +436,7 @@ export function useFairysValtioFormItemAttrs<T extends MObject<T> = object>(prop
|
|
|
405
436
|
} as FairysValtioFormItemAttrsReturn<T>;
|
|
406
437
|
}
|
|
407
438
|
|
|
408
|
-
export interface FairysValtioFormItemAttrsReturn<T extends MObject<T> =
|
|
439
|
+
export interface FairysValtioFormItemAttrsReturn<T extends MObject<T> = Record<string, any>> {
|
|
409
440
|
/**表单项值*/
|
|
410
441
|
value?: any;
|
|
411
442
|
/**是否校验错误*/
|
|
@@ -438,6 +469,8 @@ export interface FairysValtioFormItemAttrsReturn<T extends MObject<T> = object>
|
|
|
438
469
|
_name?: string;
|
|
439
470
|
/**表单项名称*/
|
|
440
471
|
name?: string;
|
|
472
|
+
/**表单项ID*/
|
|
473
|
+
id?: string;
|
|
441
474
|
/**表单项路径*/
|
|
442
475
|
paths?: (string | number)[];
|
|
443
476
|
/**父级字段名*/
|
|
@@ -490,12 +523,13 @@ export const FormItem = (props: FormItemProps) => {
|
|
|
490
523
|
}
|
|
491
524
|
* ```
|
|
492
525
|
*/
|
|
493
|
-
export function useFairysValtioFormItemNoStyleAttrs<T extends MObject<T> =
|
|
526
|
+
export function useFairysValtioFormItemNoStyleAttrs<T extends MObject<T> = Record<string, any>>(
|
|
494
527
|
props: FairysValtioFormItemAttrsProps<T>,
|
|
495
528
|
) {
|
|
496
529
|
const {
|
|
497
530
|
name,
|
|
498
531
|
valuePropName = 'value',
|
|
532
|
+
getValuePath = valuePropName,
|
|
499
533
|
getValueFromEvent,
|
|
500
534
|
formatValue,
|
|
501
535
|
onAfterUpdate,
|
|
@@ -504,6 +538,7 @@ export function useFairysValtioFormItemNoStyleAttrs<T extends MObject<T> = objec
|
|
|
504
538
|
attrs = {},
|
|
505
539
|
isJoinParentField = true,
|
|
506
540
|
rules,
|
|
541
|
+
isRemoveValueOnUnmount = true,
|
|
507
542
|
} = props;
|
|
508
543
|
const [state, errorState, formInstance] = useFairysValtioFormInstanceContextState<T>();
|
|
509
544
|
const {
|
|
@@ -512,40 +547,51 @@ export function useFairysValtioFormItemNoStyleAttrs<T extends MObject<T> = objec
|
|
|
512
547
|
parentName,
|
|
513
548
|
formAttrsNameInstance,
|
|
514
549
|
} = useFairysValtioFormAttrsName({ name, isJoinParentField });
|
|
550
|
+
const id = useId(_name);
|
|
515
551
|
const value = useMemo(() => get(state, paths), [state, paths]);
|
|
516
552
|
const error = errorState[_name];
|
|
517
553
|
formInstance.nameToPaths[_name] = paths;
|
|
518
|
-
/**挂载校验规则*/
|
|
519
|
-
if (Array.isArray(rules) && rules.length) {
|
|
520
|
-
formInstance.mountRules[_name] = rules;
|
|
521
|
-
}
|
|
522
554
|
|
|
523
555
|
useEffect(() => {
|
|
556
|
+
if (Array.isArray(rules) && rules.length) {
|
|
557
|
+
formInstance.mountRules[_name] = rules;
|
|
558
|
+
}
|
|
524
559
|
return () => {
|
|
525
560
|
formInstance.removeRules(_name);
|
|
526
561
|
};
|
|
527
|
-
}, [_name]);
|
|
562
|
+
}, [_name, rules]);
|
|
528
563
|
|
|
529
564
|
const onValueChange = (event: any) => {
|
|
530
|
-
let
|
|
565
|
+
let _value = event;
|
|
531
566
|
const target = event?.detail || event?.target;
|
|
532
567
|
if (typeof getValueFromEvent === 'function') {
|
|
533
|
-
|
|
534
|
-
} else if (event && target && typeof target === 'object' &&
|
|
535
|
-
|
|
568
|
+
_value = getValueFromEvent(event, formInstance);
|
|
569
|
+
} else if (event && target && typeof target === 'object' && getValuePath in target) {
|
|
570
|
+
_value = get(target, formatePath(getValuePath));
|
|
536
571
|
}
|
|
537
572
|
if (typeof formatValue === 'function') {
|
|
538
|
-
|
|
573
|
+
_value = formatValue(_value, formInstance, event);
|
|
539
574
|
}
|
|
540
|
-
|
|
575
|
+
// 校验值是否有变化
|
|
576
|
+
if (value === _value) return;
|
|
577
|
+
|
|
578
|
+
formInstance.updatedValueByPaths(_name, _value);
|
|
541
579
|
if (typeof onAfterUpdate === 'function') {
|
|
542
|
-
onAfterUpdate(
|
|
580
|
+
onAfterUpdate(_value, formInstance, event);
|
|
543
581
|
}
|
|
544
582
|
};
|
|
583
|
+
useEffect(() => {
|
|
584
|
+
return () => {
|
|
585
|
+
if (isRemoveValueOnUnmount) {
|
|
586
|
+
formInstance.removeValueByPaths(_name);
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
}, []);
|
|
545
590
|
/**基础组件参数*/
|
|
546
591
|
const baseControl = {
|
|
547
592
|
...attrs,
|
|
548
593
|
name,
|
|
594
|
+
id,
|
|
549
595
|
[valuePropName]: value,
|
|
550
596
|
[trigger]: onValueChange,
|
|
551
597
|
};
|
|
@@ -558,6 +604,7 @@ export function useFairysValtioFormItemNoStyleAttrs<T extends MObject<T> = objec
|
|
|
558
604
|
formInstance,
|
|
559
605
|
_name,
|
|
560
606
|
name,
|
|
607
|
+
id,
|
|
561
608
|
paths,
|
|
562
609
|
parentName,
|
|
563
610
|
formAttrsNameInstance,
|
package/src/form/form.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { MObject } from 'interface';
|
|
2
|
-
import { FairysValtioFormInstance, useFairysValtioFormInstance } from '
|
|
3
|
-
import { useMemo, type ReactNode } from 'react';
|
|
1
|
+
import { MObject } from 'common/interface';
|
|
2
|
+
import { FairysValtioFormInstance, useFairysValtioFormInstance } from 'common/instance';
|
|
3
|
+
import { useImperativeHandle, useMemo, type ReactNode, useEffect } from 'react';
|
|
4
4
|
import { FairysValtioFormLayoutAttrsProps } from './layout';
|
|
5
5
|
import { RuleItem } from 'async-validator';
|
|
6
6
|
|
|
7
|
-
export interface FairysValtioFormAttrsProps<T extends MObject<T> =
|
|
7
|
+
export interface FairysValtioFormAttrsProps<T extends MObject<T> = Record<string, any>>
|
|
8
|
+
extends FairysValtioFormLayoutAttrsProps {
|
|
8
9
|
/**表单实例*/
|
|
9
10
|
form?: FairysValtioFormInstance<T>;
|
|
10
11
|
/**子元素*/
|
|
@@ -18,10 +19,15 @@ export interface FairysValtioFormAttrsProps<T extends MObject<T> = object> exten
|
|
|
18
19
|
/**
|
|
19
20
|
* 初始化表单数据类型,默认值为 deepCopy
|
|
20
21
|
* - deepCopy:使用深度拷贝初始化表单数据
|
|
21
|
-
* - proxy
|
|
22
|
-
* - immutable:直接使用对象,不进行任何处理,注意,这个使用必须是`valtio`中的`proxy`声明的对象数据,否则表单项更新数据不会同步
|
|
22
|
+
* - immutable:直接使用对象(注意:当传递的不是`valtio`的`proxy`对象时,会使用`valtio`中的`proxy`声明)
|
|
23
23
|
*/
|
|
24
|
-
initFormDataType?: 'deepCopy' | '
|
|
24
|
+
initFormDataType?: 'deepCopy' | 'immutable';
|
|
25
|
+
/**
|
|
26
|
+
* 表单值改变时回调
|
|
27
|
+
* @param path 表单项路径
|
|
28
|
+
* @param value 表单项值
|
|
29
|
+
*/
|
|
30
|
+
onValuesChange?: (path: PropertyKey, value: any) => void;
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
/**
|
|
@@ -44,13 +50,21 @@ export const Form = (props: FormProps) => {
|
|
|
44
50
|
}
|
|
45
51
|
* ```
|
|
46
52
|
*/
|
|
47
|
-
export function useFairysValtioForm<T extends MObject<T> =
|
|
48
|
-
|
|
53
|
+
export function useFairysValtioForm<T extends MObject<T> = Record<string, any>>(
|
|
54
|
+
props: FairysValtioFormAttrsProps<T>,
|
|
55
|
+
ref: React.Ref<FairysValtioFormInstance<T>>,
|
|
56
|
+
) {
|
|
57
|
+
const { form, rules, formData, hideState, initFormDataType = 'deepCopy', onValuesChange, ...rest } = props;
|
|
49
58
|
const formInstance = useFairysValtioFormInstance(form);
|
|
50
59
|
/**表单规则*/
|
|
51
60
|
formInstance.rules = rules;
|
|
61
|
+
/**表单值改变时回调*/
|
|
62
|
+
formInstance.onValuesChange = onValuesChange;
|
|
52
63
|
/**初始化表单值*/
|
|
53
64
|
useMemo(() => formInstance.ctor({ formData, hideState, initFormDataType }), []);
|
|
65
|
+
useImperativeHandle(ref, () => formInstance);
|
|
66
|
+
/**卸载清空所有数据*/
|
|
67
|
+
useEffect(() => () => formInstance.clear(), []);
|
|
54
68
|
return {
|
|
55
69
|
...rest,
|
|
56
70
|
formInstance,
|
package/src/form/layout.tsx
CHANGED
|
@@ -3,6 +3,8 @@ import clsx from 'clsx';
|
|
|
3
3
|
import { proxy, useSnapshot } from 'valtio';
|
|
4
4
|
|
|
5
5
|
export interface FairysValtioFormLayoutContextOptions {
|
|
6
|
+
/**平台*/
|
|
7
|
+
platform?: 'pc' | 'rn' | 'taro';
|
|
6
8
|
/**列数据*/
|
|
7
9
|
colCount?: number;
|
|
8
10
|
/**规则校验失败错误提示位置*/
|
|
@@ -27,7 +29,7 @@ export interface FairysValtioFormLayoutContextOptions {
|
|
|
27
29
|
/**
|
|
28
30
|
* 底部边框类型
|
|
29
31
|
*/
|
|
30
|
-
itemBorderType?: 'bottom' | 'body';
|
|
32
|
+
itemBorderType?: 'bottom' | 'body' | 'none';
|
|
31
33
|
/**边框颜色*/
|
|
32
34
|
itemBorderColor?: React.CSSProperties['borderColor'];
|
|
33
35
|
/**是否校验失败时显示红色边框*/
|
|
@@ -104,7 +106,7 @@ export const FairysValtioFormLayoutContext = createContext<FairysValtioFormLayou
|
|
|
104
106
|
export const useFairysValtioFormLayoutContext = () => {
|
|
105
107
|
const instance = useContext(FairysValtioFormLayoutContext);
|
|
106
108
|
const state = useSnapshot(instance.state);
|
|
107
|
-
return [state, instance] as
|
|
109
|
+
return [state, instance] as [FairysValtioFormLayoutContextOptions, FairysValtioFormLayoutInstance];
|
|
108
110
|
};
|
|
109
111
|
|
|
110
112
|
/**
|
|
@@ -169,6 +171,7 @@ export function useFairysValtioFormLayoutAttrs(props: FairysValtioFormLayoutAttr
|
|
|
169
171
|
const parent_isInvalidBorderRed = state.isInvalidBorderRed;
|
|
170
172
|
const parent_isInvalidTextRed = state.isInvalidTextRed;
|
|
171
173
|
const parent_showColon = state.showColon;
|
|
174
|
+
const parent_platform = state.platform;
|
|
172
175
|
|
|
173
176
|
const {
|
|
174
177
|
colCount = parent_colCount,
|
|
@@ -186,6 +189,7 @@ export function useFairysValtioFormLayoutAttrs(props: FairysValtioFormLayoutAttr
|
|
|
186
189
|
isInvalidBorderRed = parent_isInvalidBorderRed,
|
|
187
190
|
isInvalidTextRed = parent_isInvalidTextRed,
|
|
188
191
|
showColon = parent_showColon,
|
|
192
|
+
platform = parent_platform,
|
|
189
193
|
gap,
|
|
190
194
|
isAllColSpan = false,
|
|
191
195
|
className,
|
|
@@ -215,6 +219,7 @@ export function useFairysValtioFormLayoutAttrs(props: FairysValtioFormLayoutAttr
|
|
|
215
219
|
isInvalidBorderRed,
|
|
216
220
|
isInvalidTextRed,
|
|
217
221
|
showColon,
|
|
222
|
+
platform,
|
|
218
223
|
}),
|
|
219
224
|
[
|
|
220
225
|
colCount,
|
|
@@ -231,6 +236,7 @@ export function useFairysValtioFormLayoutAttrs(props: FairysValtioFormLayoutAttr
|
|
|
231
236
|
isInvalidBorderRed,
|
|
232
237
|
isInvalidTextRed,
|
|
233
238
|
showColon,
|
|
239
|
+
platform,
|
|
234
240
|
],
|
|
235
241
|
);
|
|
236
242
|
|
|
@@ -277,7 +283,7 @@ export function useFairysValtioFormLayoutAttrs(props: FairysValtioFormLayoutAttr
|
|
|
277
283
|
|
|
278
284
|
const body_base = useMemo(() => {
|
|
279
285
|
return clsx(
|
|
280
|
-
'fairys-valtio-form-layout-body fairystaroform__transition-all fairystaroform__duration-300 fairystaroform__px-[8px] fairystaroform__w-full fairystaroform__grid
|
|
286
|
+
'fairys-valtio-form-layout-body fairystaroform__transition-all fairystaroform__duration-300 fairystaroform__px-[8px] fairystaroform__w-full fairystaroform__grid fairystaroform__box-border fairystaroform__pt-[8px] fairystaroform__pb-[12px] fairystaroform__gap-[6px]',
|
|
281
287
|
bodyClassName,
|
|
282
288
|
);
|
|
283
289
|
}, [bodyClassName]);
|
package/src/index.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from '
|
|
3
|
-
export * from '
|
|
4
|
-
export * from '
|
|
5
|
-
export * from './form/form.item';
|
|
1
|
+
export * from 'common';
|
|
2
|
+
export * from 'form/layout';
|
|
3
|
+
export * from 'form/form';
|
|
4
|
+
export * from 'form/form.item';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|