@fairys/rn-valtio-form-basic 0.0.13 → 1.0.1

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.
@@ -4,23 +4,20 @@ import { ViewProps } from 'react-native';
4
4
  import type { MObject, FairysValtioFormItemAttrsProps as _FairysValtioFormItemAttrsProps } from '@fairys/valtio-form-basic';
5
5
  import { FairysValtioFormInstance, FairysValtioFormParentAttrs } from '@fairys/valtio-form-basic/esm/common';
6
6
  import { FairysValtioFormLayoutContextOptions } from './layout';
7
- export interface FairysValtioFormItemAttrsProps<T extends MObject<T> = object> extends Omit<_FairysValtioFormItemAttrsProps<T>, 'style' | 'labelStyle' | 'bodyStyle' | 'rowSpan' | 'className' | 'labelClassName' | 'bodyClassName'> {
7
+ export interface FairysValtioFormItemAttrsProps<T extends MObject<T> = Record<string, any>> extends Omit<_FairysValtioFormItemAttrsProps<T>, 'style' | 'labelStyle' | 'bodyStyle' | 'rowSpan' | 'className' | 'labelClassName' | 'bodyClassName'> {
8
+ /**表单项样式*/
8
9
  style?: ViewProps['style'];
10
+ /**表单项标签样式*/
9
11
  labelStyle?: ViewProps['style'];
12
+ /**表单项主体样式*/
10
13
  bodyStyle?: ViewProps['style'];
11
14
  }
12
15
  /**
13
16
  * 处理表单表单项属性
14
17
  *
15
- * @example
16
- *
17
- * ```tsx
18
-
19
- * ```
20
- *
21
- */
22
- export declare function useFairysValtioFormItemAttrs<T extends MObject<T> = object>(props: FairysValtioFormItemAttrsProps<T>): FairysValtioFormItemAttrsReturn<T>;
23
- export interface FairysValtioFormItemAttrsReturn<T extends MObject<T> = object> {
18
+ */
19
+ export declare function useFairysValtioFormItemAttrs<T extends MObject<T> = Record<string, any>>(props: FairysValtioFormItemAttrsProps<T>): FairysValtioFormItemAttrsReturn<T>;
20
+ export interface FairysValtioFormItemAttrsReturn<T extends MObject<T> = Record<string, any>> {
24
21
  /**表单项值*/
25
22
  value?: any;
26
23
  /**是否校验错误*/
@@ -61,30 +58,34 @@ export interface FairysValtioFormItemAttrsReturn<T extends MObject<T> = object>
61
58
  formAttrsNameInstance: FairysValtioFormParentAttrs;
62
59
  /**是否显示冒号*/
63
60
  showColon: boolean;
61
+ /**表单项样式*/
64
62
  itemStyle: ViewProps['style'];
63
+ /**表单项容器样式*/
65
64
  itemContainerStyle: ViewProps['style'];
65
+ /**表单项标签样式*/
66
66
  itemLabelStyle: ViewProps['style'];
67
+ /**表单项标签文本样式*/
67
68
  itemLabelTextStyle: ViewProps['style'];
69
+ /**表单项标签显示冒号样式*/
68
70
  itemLabelShowColonStyle: ViewProps['style'];
71
+ /**表单项主体样式*/
69
72
  itemBodyStyle: ViewProps['style'];
73
+ /**表单项输入样式*/
70
74
  itemInputStyle: ViewProps['style'];
75
+ /**表单项额外样式*/
71
76
  itemExtraStyle: ViewProps['style'];
77
+ /**错误样式*/
72
78
  errorStyle: ViewProps['style'];
79
+ /**帮助样式*/
73
80
  helpStyle: ViewProps['style'];
74
81
  /**子元素*/
75
82
  children?: React.ReactNode;
76
83
  }
77
84
  /**
78
85
  * 没有样式的表单项属性,仅返回基础输入组件参数
79
- *
80
- * @example
81
- *
82
- *```tsx
83
-
84
- * ```
85
- */
86
- export declare function useFairysValtioFormItemNoStyleAttrs<T extends MObject<T> = object>(props: FairysValtioFormItemAttrsProps<T>): FairysValtioFormItemNoStyleAttrsReturn<T>;
87
- export interface FairysValtioFormItemNoStyleAttrsReturn<T extends MObject<T> = object> {
86
+ */
87
+ export declare function useFairysValtioFormItemNoStyleAttrs<T extends MObject<T> = Record<string, any>>(props: FairysValtioFormItemAttrsProps<T>): FairysValtioFormItemNoStyleAttrsReturn<T>;
88
+ export interface FairysValtioFormItemNoStyleAttrsReturn<T extends MObject<T> = Record<string, any>> {
88
89
  /**表单项值*/
89
90
  value?: any;
90
91
  /**是否校验错误*/
@@ -16,7 +16,7 @@ function useFairysValtioFormItemAttrs(props) {
16
16
  const parent_isInvalidBorderRed = layoutAttrs.isInvalidBorderRed;
17
17
  const parent_isInvalidTextRed = layoutAttrs.isInvalidTextRed;
18
18
  const parent_showColon = layoutAttrs.showColon;
19
- const { name, valuePropName = 'value', getValuePath = 'text', getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', style, labelStyle, bodyStyle, children, labelMode = parent_labelMode, errorLayout = parent_errorLayout, colSpan = 1, isRequired: _isRequired, itemBorderType = parent_borderedType, attrs = {}, showColon = parent_showColon, itemBorderColor = parent_itemBorderColor, isInvalidBorderRed = parent_isInvalidBorderRed, isInvalidTextRed = parent_isInvalidTextRed, isJoinParentField = true, rules } = props;
19
+ const { name, valuePropName = 'value', getValuePath = 'text', getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', style, labelStyle, bodyStyle, children, labelMode = parent_labelMode, errorLayout = parent_errorLayout, colSpan = 1, isRequired: _isRequired, itemBorderType = parent_borderedType, attrs = {}, showColon = parent_showColon, itemBorderColor = parent_itemBorderColor, isInvalidBorderRed = parent_isInvalidBorderRed, isInvalidTextRed = parent_isInvalidTextRed, isJoinParentField = true, rules, isRemoveValueOnUnmount = true } = props;
20
20
  const { name: _name, paths, parentName, formAttrsNameInstance } = useFairysValtioFormAttrsName({
21
21
  name,
22
22
  isJoinParentField
@@ -50,6 +50,9 @@ function useFairysValtioFormItemAttrs(props) {
50
50
  _name,
51
51
  rules
52
52
  ]);
53
+ useEffect(()=>()=>{
54
+ if (isRemoveValueOnUnmount) formInstance.removeValueByPaths(_name);
55
+ }, []);
53
56
  const onValueChange = (event)=>{
54
57
  let newValue = event;
55
58
  const target = event?.nativeEvent;
@@ -213,7 +216,7 @@ function useFairysValtioFormItemAttrs(props) {
213
216
  };
214
217
  }
215
218
  function useFairysValtioFormItemNoStyleAttrs(props) {
216
- const { name, valuePropName = 'value', getValuePath = 'text', getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', children, attrs = {}, isJoinParentField = true, rules, isRequired: _isRequired } = props;
219
+ const { name, valuePropName = 'value', getValuePath = 'text', getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', children, attrs = {}, isJoinParentField = true, rules, isRequired: _isRequired, isRemoveValueOnUnmount = true } = props;
217
220
  const [state, errorState, formInstance] = useFairysValtioFormInstanceContextState();
218
221
  const { name: _name, paths, parentName, formAttrsNameInstance } = useFairysValtioFormAttrsName({
219
222
  name,
@@ -236,6 +239,9 @@ function useFairysValtioFormItemNoStyleAttrs(props) {
236
239
  _name,
237
240
  rules
238
241
  ]);
242
+ useEffect(()=>()=>{
243
+ if (isRemoveValueOnUnmount) formInstance.removeValueByPaths(_name);
244
+ }, []);
239
245
  const onValueChange = (event)=>{
240
246
  let newValue = event;
241
247
  const target = event?.nativeEvent;
package/esm/hooks/form.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { useFairysValtioFormInstance } from "@fairys/valtio-form-basic/esm/common";
2
2
  import { useEffect, useImperativeHandle, useMemo } from "react";
3
3
  function useFairysValtioForm(props, ref) {
4
- const { form, rules, formData, hideState, initFormDataType = 'deepCopy', ...rest } = props;
4
+ const { form, rules, formData, hideState, initFormDataType = 'deepCopy', onValuesChange, ...rest } = props;
5
5
  const formInstance = useFairysValtioFormInstance(form);
6
6
  formInstance.rules = rules;
7
+ formInstance.onValuesChange = onValuesChange;
7
8
  useMemo(()=>formInstance.ctor({
8
9
  formData,
9
10
  hideState,