@carefrees/form-utils-react-native 0.0.7 → 0.0.8
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/esm/formItem/index.d.ts +10 -0
- package/esm/formItem/index.js +67 -0
- package/esm/formList/index.d.ts +27 -0
- package/esm/formList/index.js +37 -0
- package/esm/hooks/attr/attr.FormItem.d.ts +48 -0
- package/esm/hooks/attr/attr.FormItem.js +60 -0
- package/esm/hooks/useAttrs.d.ts +27 -0
- package/esm/hooks/useAttrs.js +10 -0
- package/esm/index.d.ts +34 -0
- package/esm/index.js +42 -0
- package/esm/layout/index.d.ts +30 -0
- package/esm/layout/index.js +98 -0
- package/esm/layout/layout.formItem.d.ts +38 -0
- package/esm/layout/layout.formItem.js +152 -0
- package/esm/styles/index.d.ts +201 -0
- package/esm/styles/index.js +203 -0
- package/package.json +8 -8
- package/src/formItem/index.tsx +2 -16
- package/src/hooks/useAttrs.ts +0 -4
- package/src/index.tsx +1 -5
- package/src/layout/index.tsx +1 -24
- package/src/layout/layout.formItem.tsx +0 -12
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LayoutFormItemProps } from '../layout/layout.formItem';
|
|
2
|
+
import { FormItemAttrOptions } from '../hooks/attr/attr.FormItem';
|
|
3
|
+
export interface FormItemProps extends FormItemAttrOptions, LayoutFormItemProps {
|
|
4
|
+
/**不进行样式渲染*/
|
|
5
|
+
noStyle?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**表单项*/
|
|
8
|
+
export declare const FormItem: import("react").MemoExoticComponent<(props: Partial<FormItemProps>) => import("react/jsx-runtime").JSX.Element>;
|
|
9
|
+
/**隐藏表单项*/
|
|
10
|
+
export declare const FormHideItem: import("react").MemoExoticComponent<(props: FormItemProps) => import("react/jsx-runtime").JSX.Element>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__layout_layout_formItem_js_c84059c5__ from "../layout/layout.formItem.js";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE__hooks_attr_attr_FormItem_js_9b75aef3__ from "../hooks/attr/attr.FormItem.js";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__ from "@carefrees/form-utils-react-hooks";
|
|
6
|
+
const FormItemInstance = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)((props)=>{
|
|
7
|
+
const { labelMode, noStyle, onlyRuleStyle, label, helpText, extra, errorLayout, required, showColon, colSpan, ...rest } = props;
|
|
8
|
+
const { children, ruleInstance, formItemInstance, htmlFor, validateResult } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_attr_attr_FormItem_js_9b75aef3__.useFormItemAttr)({
|
|
9
|
+
...rest
|
|
10
|
+
});
|
|
11
|
+
if (noStyle) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__.FormItemParentNameProvider, {
|
|
12
|
+
name: formItemInstance.name,
|
|
13
|
+
sort: formItemInstance.sort,
|
|
14
|
+
children: children
|
|
15
|
+
});
|
|
16
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__.FormItemParentNameProvider, {
|
|
17
|
+
name: formItemInstance.name,
|
|
18
|
+
sort: formItemInstance.sort,
|
|
19
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__layout_layout_formItem_js_c84059c5__.LayoutFormItem, {
|
|
20
|
+
labelMode: labelMode,
|
|
21
|
+
onlyRuleStyle: onlyRuleStyle,
|
|
22
|
+
required: required || ruleInstance?.isRequired?.(),
|
|
23
|
+
label: label,
|
|
24
|
+
helpText: helpText,
|
|
25
|
+
extra: extra,
|
|
26
|
+
errorLayout: errorLayout,
|
|
27
|
+
showColon: showColon,
|
|
28
|
+
colSpan: colSpan,
|
|
29
|
+
htmlFor: htmlFor,
|
|
30
|
+
validateResult: validateResult,
|
|
31
|
+
children: children
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
const FormItem = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)((props)=>{
|
|
36
|
+
const { name } = props;
|
|
37
|
+
if (name) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(FormItemInstance, {
|
|
38
|
+
...props,
|
|
39
|
+
name: name
|
|
40
|
+
});
|
|
41
|
+
const { labelMode, onlyRuleStyle, label, helpText, extra, errorLayout, required, showColon, colSpan, children } = props;
|
|
42
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__layout_layout_formItem_js_c84059c5__.LayoutFormItem, {
|
|
43
|
+
labelMode: labelMode,
|
|
44
|
+
onlyRuleStyle: onlyRuleStyle,
|
|
45
|
+
required: required,
|
|
46
|
+
label: label,
|
|
47
|
+
helpText: helpText,
|
|
48
|
+
extra: extra,
|
|
49
|
+
errorLayout: errorLayout,
|
|
50
|
+
showColon: showColon,
|
|
51
|
+
colSpan: colSpan,
|
|
52
|
+
children: children
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
const FormHideItem = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)((props)=>{
|
|
56
|
+
const { name, sort, isJoinParentField } = props;
|
|
57
|
+
const { isHide } = (0, __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__.useRegisterFormHideItem)({
|
|
58
|
+
name,
|
|
59
|
+
sort: sort,
|
|
60
|
+
isJoinParentField
|
|
61
|
+
});
|
|
62
|
+
if (isHide) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react__.Fragment, {});
|
|
63
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(FormItemInstance, {
|
|
64
|
+
...props
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
export { FormHideItem, FormItem };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { RuleInstanceBase, FormItemInstanceBase, FormListInstanceBase } from '@carefrees/form-utils';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { RegisterFormListOptions } from '@carefrees/form-utils-react-hooks';
|
|
4
|
+
export interface FormListChildrenProps {
|
|
5
|
+
/**数据集合*/
|
|
6
|
+
fields: {
|
|
7
|
+
name: number;
|
|
8
|
+
key: number;
|
|
9
|
+
}[];
|
|
10
|
+
/**添加*/
|
|
11
|
+
onAdd: (initialValue?: Object) => void;
|
|
12
|
+
/**删除*/
|
|
13
|
+
onDelete: (index: number | number[]) => void;
|
|
14
|
+
/**移动*/
|
|
15
|
+
onMove: (from: number, to: number) => void;
|
|
16
|
+
}
|
|
17
|
+
export interface FormListProps extends RegisterFormListOptions {
|
|
18
|
+
children: (options: FormListChildrenProps, instances: {
|
|
19
|
+
ruleInstance: RuleInstanceBase;
|
|
20
|
+
formItemInstance: FormItemInstanceBase;
|
|
21
|
+
formListInstance: FormListInstanceBase;
|
|
22
|
+
}) => React.ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/**form list 组件*/
|
|
25
|
+
export declare const FormList: React.MemoExoticComponent<(props: FormListProps) => import("react/jsx-runtime").JSX.Element>;
|
|
26
|
+
/**隐藏 form list item 组件*/
|
|
27
|
+
export declare const FormHideList: React.MemoExoticComponent<(props: FormListProps) => import("react/jsx-runtime").JSX.Element>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__ from "@carefrees/form-utils-react-hooks";
|
|
4
|
+
const FormList = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)((props)=>{
|
|
5
|
+
const { children, ...rest } = props;
|
|
6
|
+
const { formListInstance, ruleInstance, formItemInstance } = (0, __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__.useRegisterFormList)(rest);
|
|
7
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__.FormListInstanceContext.Provider, {
|
|
8
|
+
value: formListInstance,
|
|
9
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__.FormItemParentNameProvider, {
|
|
10
|
+
name: formListInstance.name,
|
|
11
|
+
sort: formListInstance.sort,
|
|
12
|
+
children: children({
|
|
13
|
+
fields: formListInstance.getFields(),
|
|
14
|
+
onAdd: formListInstance.onAdd,
|
|
15
|
+
onDelete: formListInstance.onDelete,
|
|
16
|
+
onMove: formListInstance.onMove
|
|
17
|
+
}, {
|
|
18
|
+
ruleInstance,
|
|
19
|
+
formItemInstance,
|
|
20
|
+
formListInstance
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
const FormHideList = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)((props)=>{
|
|
26
|
+
const { name, sort, isJoinParentField } = props;
|
|
27
|
+
const { isHide } = (0, __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__.useRegisterFormHideItem)({
|
|
28
|
+
name,
|
|
29
|
+
sort: sort,
|
|
30
|
+
isJoinParentField
|
|
31
|
+
});
|
|
32
|
+
if (isHide) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react__.Fragment, {});
|
|
33
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(FormList, {
|
|
34
|
+
...props
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
export { FormHideList, FormList };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { RuleInstanceBase, FormInstanceBase, FormItemInstanceBase } from '@carefrees/form-utils';
|
|
2
|
+
import { RegisterFormItemOptions } from '@carefrees/form-utils-react-hooks';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
export interface FormItemAttrOptions extends RegisterFormItemOptions {
|
|
5
|
+
/**依赖更新项*/
|
|
6
|
+
dependencies?: string[];
|
|
7
|
+
/**通知 只用于校验规则提示 字段 */
|
|
8
|
+
noticeOnlyRuleDataField?: string[];
|
|
9
|
+
/**通知父级字段监听方法更新*/
|
|
10
|
+
isNoticeParentField?: boolean;
|
|
11
|
+
/**通知watch监听方法更新*/
|
|
12
|
+
noticeWatchField?: string[];
|
|
13
|
+
/**是否保护值(不进行表单项组件卸载重置初始值)*/
|
|
14
|
+
preserve?: boolean;
|
|
15
|
+
/**重写规则*/
|
|
16
|
+
useRules?: (ruleInstance: RuleInstanceBase, form: FormInstanceBase, formItemInstance: FormItemInstanceBase) => void;
|
|
17
|
+
/**输入框属性重写*/
|
|
18
|
+
useAttrs?: (attrs: any, form: FormInstanceBase, formItemInstance: FormItemInstanceBase) => any;
|
|
19
|
+
/**输入框属性*/
|
|
20
|
+
attrs?: any;
|
|
21
|
+
/**传递组件字段*/
|
|
22
|
+
valuePropName?: string;
|
|
23
|
+
/**取值字段(默认text)*/
|
|
24
|
+
getValuePath?: string;
|
|
25
|
+
/**自定义获取值*/
|
|
26
|
+
getValueFromEvent?: (event: any, form: FormInstanceBase, formItemInstance: FormItemInstanceBase) => any;
|
|
27
|
+
/**值格式化*/
|
|
28
|
+
formatValue?: (value: any, form: FormInstanceBase, formItemInstance: FormItemInstanceBase, event: any) => any;
|
|
29
|
+
/**触发数据更新之后触发(用于数据联动之类的)*/
|
|
30
|
+
onAfterUpdate?: (value: any, form: FormInstanceBase, formItemInstance: FormItemInstanceBase, event: any) => void;
|
|
31
|
+
/**事件名称*/
|
|
32
|
+
trigger?: string;
|
|
33
|
+
/**子元素*/
|
|
34
|
+
children?: React.ReactNode;
|
|
35
|
+
}
|
|
36
|
+
/**表单项参数*/
|
|
37
|
+
export declare const useFormItemAttr: (options: FormItemAttrOptions) => {
|
|
38
|
+
children: string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode>;
|
|
39
|
+
form: FormInstanceBase<any>;
|
|
40
|
+
formItemInstance: FormItemInstanceBase;
|
|
41
|
+
ruleInstance: RuleInstanceBase;
|
|
42
|
+
onChange: (event: any) => void;
|
|
43
|
+
htmlFor: string;
|
|
44
|
+
validateResult: {
|
|
45
|
+
tip: string | (string | undefined)[];
|
|
46
|
+
isInvalid: boolean;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__ from "@carefrees/form-utils";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__ from "@carefrees/form-utils-react-hooks";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
4
|
+
const useFormItemAttr = (options)=>{
|
|
5
|
+
const { trigger = 'onChange', dependencies, noticeOnlyRuleDataField, isNoticeParentField, noticeWatchField, preserve, valuePropName = 'value', getValuePath = 'text', getValueFromEvent, formatValue, onAfterUpdate, useAttrs, useRules, attrs, children, ...rest } = options;
|
|
6
|
+
const { formItemInstance, form, ruleInstance, newName } = (0, __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__.useRegisterFormItem)({
|
|
7
|
+
...rest
|
|
8
|
+
});
|
|
9
|
+
formItemInstance.dependencies = dependencies;
|
|
10
|
+
formItemInstance.noticeOnlyRuleDataField = noticeOnlyRuleDataField;
|
|
11
|
+
formItemInstance.isNoticeParentField = isNoticeParentField;
|
|
12
|
+
formItemInstance.onAfterUpdate = onAfterUpdate;
|
|
13
|
+
formItemInstance.noticeWatchField = noticeWatchField;
|
|
14
|
+
formItemInstance.preserve = preserve;
|
|
15
|
+
const oldValue = form.getFieldValue(newName);
|
|
16
|
+
const onValueChange = (event)=>{
|
|
17
|
+
try {
|
|
18
|
+
let value = event;
|
|
19
|
+
const target = event?.nativeEvent;
|
|
20
|
+
if ('function' == typeof getValueFromEvent) value = getValueFromEvent(event, form, formItemInstance);
|
|
21
|
+
else if (event && target && 'object' == typeof target && getValuePath in target) value = (0, __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.get)(target, getValuePath);
|
|
22
|
+
if ('function' == typeof formatValue) value = formatValue(value, form, formItemInstance, event);
|
|
23
|
+
if (oldValue !== value) {
|
|
24
|
+
form.updatedFieldValue(newName, value, 'validate');
|
|
25
|
+
formItemInstance.onAfterUpdate?.(value, form, formItemInstance, event);
|
|
26
|
+
if (Array.isArray(formItemInstance.noticeWatchField) && formItemInstance.noticeWatchField.length) form.noticeWatch(formItemInstance.noticeWatchField);
|
|
27
|
+
if (Array.isArray(formItemInstance.noticeOnlyRuleDataField) && formItemInstance.noticeOnlyRuleDataField.length) form.onlyValidate(formItemInstance.noticeOnlyRuleDataField);
|
|
28
|
+
if (formItemInstance.isNoticeParentField && formItemInstance.parentDataField) form.notice(formItemInstance.parentDataField);
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.log(error);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
formItemInstance.onChange = onValueChange;
|
|
35
|
+
const htmlFor = (0, __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__.useHtmlFor)(newName);
|
|
36
|
+
formItemInstance.htmlFor = htmlFor;
|
|
37
|
+
const control = {
|
|
38
|
+
[trigger]: onValueChange,
|
|
39
|
+
...attrs,
|
|
40
|
+
name: newName,
|
|
41
|
+
id: htmlFor,
|
|
42
|
+
[valuePropName]: oldValue
|
|
43
|
+
};
|
|
44
|
+
const newControl = useAttrs?.(control, form, formItemInstance) || control;
|
|
45
|
+
formItemInstance.control = newControl;
|
|
46
|
+
useRules?.(ruleInstance, form, formItemInstance);
|
|
47
|
+
const validateResult = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>ruleInstance.getValidateResult(), [
|
|
48
|
+
ruleInstance.messages
|
|
49
|
+
]);
|
|
50
|
+
return {
|
|
51
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.isValidElement)(children) ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.cloneElement)(children, newControl) : children,
|
|
52
|
+
form,
|
|
53
|
+
formItemInstance,
|
|
54
|
+
ruleInstance,
|
|
55
|
+
onChange: onValueChange,
|
|
56
|
+
htmlFor,
|
|
57
|
+
validateResult
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export { useFormItemAttr };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ViewProps } from 'react-native';
|
|
2
|
+
export interface AttrsOptions {
|
|
3
|
+
/**列数据*/
|
|
4
|
+
colCount?: number;
|
|
5
|
+
/**规则校验失败错误提示位置*/
|
|
6
|
+
errorLayout?: 'left-bottom' | 'right-bottom' | 'top-right' | 'top-left';
|
|
7
|
+
/**
|
|
8
|
+
* label显示模式
|
|
9
|
+
* @platform taro 支持 between
|
|
10
|
+
*/
|
|
11
|
+
labelMode?: 'left' | 'top' | 'between' | 'hide';
|
|
12
|
+
/**是否显示label后的冒号*/
|
|
13
|
+
showColon?: boolean;
|
|
14
|
+
/**表单项 style*/
|
|
15
|
+
formItemStyle?: ViewProps['style'];
|
|
16
|
+
/**表单项 label style*/
|
|
17
|
+
formItemLabelStyle?: ViewProps['style'];
|
|
18
|
+
/**
|
|
19
|
+
* 输入框底部边框
|
|
20
|
+
* @platform taro
|
|
21
|
+
*/
|
|
22
|
+
inputBordered?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**公共属性 Context */
|
|
25
|
+
export declare const AttrsContext: import("react").Context<AttrsOptions>;
|
|
26
|
+
/**子项中获取公共属性*/
|
|
27
|
+
export declare const useAttrs: () => AttrsOptions;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
2
|
+
const AttrsContext = (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)({
|
|
3
|
+
colCount: 1,
|
|
4
|
+
errorLayout: 'left-bottom',
|
|
5
|
+
labelMode: 'top',
|
|
6
|
+
showColon: true,
|
|
7
|
+
inputBordered: true
|
|
8
|
+
});
|
|
9
|
+
const useAttrs = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(AttrsContext);
|
|
10
|
+
export { AttrsContext, useAttrs };
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FormInstanceBase, ValidateErrorEntity } from '@carefrees/form-utils';
|
|
3
|
+
import { FormLayoutProps } from './layout';
|
|
4
|
+
import { ViewProps } from 'react-native';
|
|
5
|
+
export * from './formItem';
|
|
6
|
+
export * from './formList';
|
|
7
|
+
export * from './layout';
|
|
8
|
+
export * from './layout/layout.formItem';
|
|
9
|
+
export * from './hooks/attr/attr.FormItem';
|
|
10
|
+
export * from '@carefrees/form-utils-react-hooks';
|
|
11
|
+
export { useAttrs, AttrsOptions, AttrsContext } from './hooks/useAttrs';
|
|
12
|
+
export interface FormProps<T = any> extends FormLayoutProps {
|
|
13
|
+
children?: React.ReactNode;
|
|
14
|
+
form?: FormInstanceBase;
|
|
15
|
+
style?: ViewProps['style'];
|
|
16
|
+
layoutStyle?: ViewProps['style'];
|
|
17
|
+
/**表单数据*/
|
|
18
|
+
formData?: any;
|
|
19
|
+
/**值更新触发*/
|
|
20
|
+
onValuesChange?: (changedValues: Partial<T>, values: T) => void;
|
|
21
|
+
/**提交保存 验证成功*/
|
|
22
|
+
onFinish?: (values: T) => void;
|
|
23
|
+
/**提交保存 验证失败*/
|
|
24
|
+
onFinishFailed?: (errorInfo: ValidateErrorEntity<T>) => void;
|
|
25
|
+
/**隐藏表单项初始值*/
|
|
26
|
+
hideData?: Record<string, boolean>;
|
|
27
|
+
/**表单名称*/
|
|
28
|
+
name?: string;
|
|
29
|
+
/**隐藏规则校验*/
|
|
30
|
+
hideRuleData?: Record<string, boolean>;
|
|
31
|
+
/**自动重置更新formData数据*/
|
|
32
|
+
isAutoUpdatedFormData?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare function Form<T = any>(props: FormProps<T>): import("react/jsx-runtime").JSX.Element;
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE__layout_index_js_0ed29524__ from "./layout/index.js";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react_native_4af9217e__ from "react-native";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__ from "@carefrees/form-utils-react-hooks";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__hooks_useAttrs_js_565efc98__ from "./hooks/useAttrs.js";
|
|
7
|
+
export * from "./formItem/index.js";
|
|
8
|
+
export * from "./formList/index.js";
|
|
9
|
+
export * from "./layout/index.js";
|
|
10
|
+
export * from "./layout/layout.formItem.js";
|
|
11
|
+
export * from "./hooks/attr/attr.FormItem.js";
|
|
12
|
+
export * from "@carefrees/form-utils-react-hooks";
|
|
13
|
+
function Form(props) {
|
|
14
|
+
const { children, form, style, formData, hideData, hideRuleData, isAutoUpdatedFormData = false, name, onFinish, onFinishFailed, onValuesChange, layoutStyle, ...rest } = props;
|
|
15
|
+
const formInstance = (0, __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__.useForm)(form);
|
|
16
|
+
(0, __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__.useRegisterForm)(formInstance, name);
|
|
17
|
+
(0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>formInstance.ctor(formData, hideData, hideRuleData), []);
|
|
18
|
+
formInstance.onFinish = onFinish;
|
|
19
|
+
formInstance.onValuesChange = onValuesChange;
|
|
20
|
+
formInstance.onFinishFailed = onFinishFailed;
|
|
21
|
+
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
22
|
+
if (isAutoUpdatedFormData) formInstance.resetFormValues(formData);
|
|
23
|
+
}, [
|
|
24
|
+
isAutoUpdatedFormData,
|
|
25
|
+
formData
|
|
26
|
+
]);
|
|
27
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_react_hooks_1966d15b__.FormInstanceContext.Provider, {
|
|
28
|
+
value: formInstance,
|
|
29
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_native_4af9217e__.View, {
|
|
30
|
+
style: style,
|
|
31
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__layout_index_js_0ed29524__.FormLayout, {
|
|
32
|
+
...rest,
|
|
33
|
+
style: layoutStyle,
|
|
34
|
+
children: children
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
var __webpack_exports__AttrsContext = __WEBPACK_EXTERNAL_MODULE__hooks_useAttrs_js_565efc98__.AttrsContext;
|
|
40
|
+
var __webpack_exports__AttrsOptions = __WEBPACK_EXTERNAL_MODULE__hooks_useAttrs_js_565efc98__.AttrsOptions;
|
|
41
|
+
var __webpack_exports__useAttrs = __WEBPACK_EXTERNAL_MODULE__hooks_useAttrs_js_565efc98__.useAttrs;
|
|
42
|
+
export { Form, __webpack_exports__AttrsContext as AttrsContext, __webpack_exports__AttrsOptions as AttrsOptions, __webpack_exports__useAttrs as useAttrs };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AttrsOptions } from './../hooks/useAttrs';
|
|
3
|
+
import { ViewProps } from 'react-native';
|
|
4
|
+
export interface FormLayoutProps extends AttrsOptions {
|
|
5
|
+
/**标题*/
|
|
6
|
+
title?: React.ReactNode;
|
|
7
|
+
/**额外内容*/
|
|
8
|
+
extra?: React.ReactNode;
|
|
9
|
+
/**内容*/
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
/**是否占据整行*/
|
|
12
|
+
isAllColSpan?: boolean;
|
|
13
|
+
style?: ViewProps['style'];
|
|
14
|
+
/**头部样式*/
|
|
15
|
+
headerStyle?: ViewProps['style'];
|
|
16
|
+
/**内容样式*/
|
|
17
|
+
bodyStyle?: ViewProps['style'];
|
|
18
|
+
/**是否添加边框*/
|
|
19
|
+
bordered?: boolean;
|
|
20
|
+
/**列数据*/
|
|
21
|
+
colCount?: number;
|
|
22
|
+
/**
|
|
23
|
+
* @description gap 属性是用来设置网格行与列之间的间隙,该属性是row-gap and column-gap的简写形式。
|
|
24
|
+
*/
|
|
25
|
+
gap?: string | number;
|
|
26
|
+
}
|
|
27
|
+
/**布局组件*/
|
|
28
|
+
export declare const FormLayout: React.MemoExoticComponent<(props: FormLayoutProps) => import("react/jsx-runtime").JSX.Element>;
|
|
29
|
+
/**布局组件 占据一整行*/
|
|
30
|
+
export declare const FormLayoutRows: (props: ViewProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE__hooks_useAttrs_js_86d21a28__ from "../hooks/useAttrs.js";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react_native_4af9217e__ from "react-native";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__styles_index_js_2b6f3fb9__ from "../styles/index.js";
|
|
6
|
+
const FormLayout = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)((props)=>{
|
|
7
|
+
const { colCount: p_colCount = 4, errorLayout: p_errorLayout = 'left-bottom', labelMode: p_labelMode = 'left', showColon: p_showColon = true, formItemStyle: p_formItemStyle, formItemLabelStyle: p_formItemLabelStyle } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_useAttrs_js_86d21a28__.useAttrs)();
|
|
8
|
+
const { colCount = p_colCount, title, extra, children, isAllColSpan, style, headerStyle, bodyStyle, errorLayout = p_errorLayout, labelMode = p_labelMode, showColon = p_showColon, formItemStyle = p_formItemStyle, formItemLabelStyle = p_formItemLabelStyle, bordered = false, gap } = props;
|
|
9
|
+
const propsRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(props);
|
|
10
|
+
propsRef.current = props;
|
|
11
|
+
const value = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
|
|
12
|
+
colCount,
|
|
13
|
+
errorLayout,
|
|
14
|
+
labelMode,
|
|
15
|
+
showColon,
|
|
16
|
+
formItemStyle,
|
|
17
|
+
formItemLabelStyle
|
|
18
|
+
}), [
|
|
19
|
+
colCount,
|
|
20
|
+
errorLayout,
|
|
21
|
+
labelMode,
|
|
22
|
+
showColon,
|
|
23
|
+
formItemStyle,
|
|
24
|
+
formItemLabelStyle
|
|
25
|
+
]);
|
|
26
|
+
const styleBase = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
|
|
27
|
+
const css = {};
|
|
28
|
+
if ('string' == typeof gap) css.gap = Number(gap);
|
|
29
|
+
if ('number' == typeof gap) css.gap = gap;
|
|
30
|
+
return css;
|
|
31
|
+
}, [
|
|
32
|
+
colCount,
|
|
33
|
+
gap
|
|
34
|
+
]);
|
|
35
|
+
const layoutStyle = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>[
|
|
36
|
+
__WEBPACK_EXTERNAL_MODULE__styles_index_js_2b6f3fb9__.StylesBase["carefrees-form-layout"],
|
|
37
|
+
bordered && __WEBPACK_EXTERNAL_MODULE__styles_index_js_2b6f3fb9__.StylesBase["carefrees-form-layout.bordered"],
|
|
38
|
+
isAllColSpan && __WEBPACK_EXTERNAL_MODULE__styles_index_js_2b6f3fb9__.StylesBase.isAllColSpan,
|
|
39
|
+
style
|
|
40
|
+
].filter(Boolean), [
|
|
41
|
+
bordered,
|
|
42
|
+
isAllColSpan,
|
|
43
|
+
style
|
|
44
|
+
]);
|
|
45
|
+
const headStyle = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>[
|
|
46
|
+
__WEBPACK_EXTERNAL_MODULE__styles_index_js_2b6f3fb9__.StylesBase["carefrees-form-layout-header"],
|
|
47
|
+
bordered && __WEBPACK_EXTERNAL_MODULE__styles_index_js_2b6f3fb9__.StylesBase["carefrees-form-layout-header.bordered"],
|
|
48
|
+
headerStyle
|
|
49
|
+
].filter(Boolean), [
|
|
50
|
+
bordered,
|
|
51
|
+
headerStyle
|
|
52
|
+
]);
|
|
53
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__hooks_useAttrs_js_86d21a28__.AttrsContext.Provider, {
|
|
54
|
+
value: value,
|
|
55
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_native_4af9217e__.View, {
|
|
56
|
+
style: layoutStyle,
|
|
57
|
+
children: [
|
|
58
|
+
title || extra ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_native_4af9217e__.View, {
|
|
59
|
+
style: headStyle,
|
|
60
|
+
children: [
|
|
61
|
+
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_native_4af9217e__.View, {
|
|
62
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_native_4af9217e__.Text, {
|
|
63
|
+
style: [
|
|
64
|
+
__WEBPACK_EXTERNAL_MODULE__styles_index_js_2b6f3fb9__.StylesBase["carefrees-form-layout-header-title"]
|
|
65
|
+
],
|
|
66
|
+
children: title
|
|
67
|
+
})
|
|
68
|
+
}),
|
|
69
|
+
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_native_4af9217e__.View, {
|
|
70
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_native_4af9217e__.Text, {
|
|
71
|
+
style: [
|
|
72
|
+
__WEBPACK_EXTERNAL_MODULE__styles_index_js_2b6f3fb9__.StylesBase["carefrees-form-layout-header-extra"]
|
|
73
|
+
],
|
|
74
|
+
children: extra
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
]
|
|
78
|
+
}) : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react__.Fragment, {}),
|
|
79
|
+
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_native_4af9217e__.View, {
|
|
80
|
+
style: [
|
|
81
|
+
__WEBPACK_EXTERNAL_MODULE__styles_index_js_2b6f3fb9__.StylesBase["carefrees-form-layout-body"],
|
|
82
|
+
styleBase,
|
|
83
|
+
bodyStyle
|
|
84
|
+
],
|
|
85
|
+
children: children
|
|
86
|
+
})
|
|
87
|
+
]
|
|
88
|
+
})
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
const FormLayoutRows = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_native_4af9217e__.View, {
|
|
92
|
+
...props,
|
|
93
|
+
style: [
|
|
94
|
+
props.style,
|
|
95
|
+
__WEBPACK_EXTERNAL_MODULE__styles_index_js_2b6f3fb9__.StylesBase.isAllColSpan
|
|
96
|
+
]
|
|
97
|
+
});
|
|
98
|
+
export { FormLayout, FormLayoutRows };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ViewProps } from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export interface LayoutFormItemProps {
|
|
4
|
+
/**规则校验失败错误提示位置*/
|
|
5
|
+
errorLayout?: 'left-bottom' | 'right-bottom' | 'top-right' | 'top-left';
|
|
6
|
+
/**必填样式*/
|
|
7
|
+
required?: boolean;
|
|
8
|
+
/**label显示模式*/
|
|
9
|
+
labelMode?: 'left' | 'top' | 'between' | 'hide';
|
|
10
|
+
/**内容*/
|
|
11
|
+
children?: React.ReactNode;
|
|
12
|
+
/**只进行规则样式*/
|
|
13
|
+
onlyRuleStyle?: boolean;
|
|
14
|
+
label?: React.ReactNode;
|
|
15
|
+
/**底部提示内容*/
|
|
16
|
+
helpText?: React.ReactNode;
|
|
17
|
+
/**额外内容*/
|
|
18
|
+
extra?: React.ReactNode;
|
|
19
|
+
/**是否显示label后的冒号*/
|
|
20
|
+
showColon?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* 表单项占据列数
|
|
23
|
+
* @default 1
|
|
24
|
+
*/
|
|
25
|
+
colSpan?: number;
|
|
26
|
+
htmlFor?: string;
|
|
27
|
+
/**规则验证结果*/
|
|
28
|
+
validateResult?: {
|
|
29
|
+
tip: string | (string | undefined)[];
|
|
30
|
+
isInvalid: boolean;
|
|
31
|
+
};
|
|
32
|
+
style?: ViewProps['style'];
|
|
33
|
+
labelStyle?: ViewProps['style'];
|
|
34
|
+
/**底部边框*/
|
|
35
|
+
inputBordered?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**布局组件 表单项*/
|
|
38
|
+
export declare const LayoutFormItem: React.MemoExoticComponent<(props: LayoutFormItemProps) => import("react/jsx-runtime").JSX.Element>;
|