@carefrees/form-utils-react-taro 0.0.4
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 +9 -0
- package/esm/formItem/index.d.ts +11 -0
- package/esm/formItem/index.js +70 -0
- package/esm/formList/index.d.ts +27 -0
- package/esm/formList/index.js +40 -0
- package/esm/hooks/attr/attr.FormItem.d.ts +48 -0
- package/esm/hooks/attr/attr.FormItem.js +61 -0
- package/esm/hooks/register/register.FormHideItem.d.ts +9 -0
- package/esm/hooks/register/register.FormHideItem.js +31 -0
- package/esm/hooks/register/register.FormItem.d.ts +23 -0
- package/esm/hooks/register/register.FormItem.js +42 -0
- package/esm/hooks/register/register.FormList.d.ts +9 -0
- package/esm/hooks/register/register.FormList.js +31 -0
- package/esm/hooks/register/register.form.d.ts +3 -0
- package/esm/hooks/register/register.form.js +17 -0
- package/esm/hooks/useAttrs.d.ts +25 -0
- package/esm/hooks/useAttrs.js +10 -0
- package/esm/hooks/useForm.d.ts +7 -0
- package/esm/hooks/useForm.js +13 -0
- package/esm/hooks/useFormItem.d.ts +7 -0
- package/esm/hooks/useFormItem.js +11 -0
- package/esm/hooks/useFormItemParentName.d.ts +30 -0
- package/esm/hooks/useFormItemParentName.js +61 -0
- package/esm/hooks/useFormList.d.ts +7 -0
- package/esm/hooks/useFormList.js +11 -0
- package/esm/hooks/useHtmlFor.d.ts +1 -0
- package/esm/hooks/useHtmlFor.js +10 -0
- package/esm/hooks/useMultipleForm.d.ts +13 -0
- package/esm/hooks/useMultipleForm.js +19 -0
- package/esm/hooks/useUpdate.d.ts +2 -0
- package/esm/hooks/useUpdate.js +10 -0
- package/esm/hooks/useWatch.d.ts +19 -0
- package/esm/hooks/useWatch.js +41 -0
- package/esm/index.d.ts +46 -0
- package/esm/index.js +61 -0
- package/esm/layout/index.d.ts +35 -0
- package/esm/layout/index.js +99 -0
- package/esm/layout/layout.formItem.d.ts +44 -0
- package/esm/layout/layout.formItem.js +113 -0
- package/esm/styles/index.css +200 -0
- package/lib/formItem/index.d.ts +11 -0
- package/lib/formItem/index.js +107 -0
- package/lib/formList/index.d.ts +27 -0
- package/lib/formList/index.js +77 -0
- package/lib/hooks/attr/attr.FormItem.d.ts +48 -0
- package/lib/hooks/attr/attr.FormItem.js +95 -0
- package/lib/hooks/register/register.FormHideItem.d.ts +9 -0
- package/lib/hooks/register/register.FormHideItem.js +65 -0
- package/lib/hooks/register/register.FormItem.d.ts +23 -0
- package/lib/hooks/register/register.FormItem.js +76 -0
- package/lib/hooks/register/register.FormList.d.ts +9 -0
- package/lib/hooks/register/register.FormList.js +65 -0
- package/lib/hooks/register/register.form.d.ts +3 -0
- package/lib/hooks/register/register.form.js +51 -0
- package/lib/hooks/useAttrs.d.ts +25 -0
- package/lib/hooks/useAttrs.js +47 -0
- package/lib/hooks/useForm.d.ts +7 -0
- package/lib/hooks/useForm.js +53 -0
- package/lib/hooks/useFormItem.d.ts +7 -0
- package/lib/hooks/useFormItem.js +51 -0
- package/lib/hooks/useFormItemParentName.d.ts +30 -0
- package/lib/hooks/useFormItemParentName.js +101 -0
- package/lib/hooks/useFormList.d.ts +7 -0
- package/lib/hooks/useFormList.js +51 -0
- package/lib/hooks/useHtmlFor.d.ts +1 -0
- package/lib/hooks/useHtmlFor.js +44 -0
- package/lib/hooks/useMultipleForm.d.ts +13 -0
- package/lib/hooks/useMultipleForm.js +62 -0
- package/lib/hooks/useUpdate.d.ts +2 -0
- package/lib/hooks/useUpdate.js +44 -0
- package/lib/hooks/useWatch.d.ts +19 -0
- package/lib/hooks/useWatch.js +78 -0
- package/lib/index.d.ts +46 -0
- package/lib/index.js +317 -0
- package/lib/layout/index.d.ts +35 -0
- package/lib/layout/index.js +146 -0
- package/lib/layout/layout.formItem.d.ts +44 -0
- package/lib/layout/layout.formItem.js +157 -0
- package/lib/styles/index.css +200 -0
- package/package.json +32 -0
- package/src/formItem/index.tsx +103 -0
- package/src/formList/index.tsx +59 -0
- package/src/hooks/attr/attr.FormItem.tsx +131 -0
- package/src/hooks/register/register.FormHideItem.ts +29 -0
- package/src/hooks/register/register.FormItem.ts +52 -0
- package/src/hooks/register/register.FormList.ts +31 -0
- package/src/hooks/register/register.form.ts +18 -0
- package/src/hooks/useAttrs.ts +35 -0
- package/src/hooks/useForm.ts +23 -0
- package/src/hooks/useFormItem.ts +21 -0
- package/src/hooks/useFormItemParentName.ts +49 -0
- package/src/hooks/useFormList.ts +21 -0
- package/src/hooks/useHtmlFor.ts +9 -0
- package/src/hooks/useMultipleForm.ts +36 -0
- package/src/hooks/useUpdate.ts +12 -0
- package/src/hooks/useWatch.ts +61 -0
- package/src/index.tsx +102 -0
- package/src/layout/index.tsx +152 -0
- package/src/layout/layout.formItem.tsx +152 -0
- package/src/styles/index.css +208 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
2
|
+
let localId = 0;
|
|
3
|
+
const useHtmlFor = (suffix)=>{
|
|
4
|
+
const count = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(localId++);
|
|
5
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>`carefree-form-item_${count.current.toString(32)}_${suffix}`, [
|
|
6
|
+
count.current,
|
|
7
|
+
suffix
|
|
8
|
+
]);
|
|
9
|
+
};
|
|
10
|
+
export { useHtmlFor };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MultipleInstanceBase } from '@carefrees/form-utils';
|
|
2
|
+
/**多表单收集 Context */
|
|
3
|
+
export declare const MultipleFormInstanceContext: import("react").Context<MultipleInstanceBase>;
|
|
4
|
+
/**子项中获取 多表单收集 实例*/
|
|
5
|
+
export declare const useMultipleFormInstance: () => MultipleInstanceBase;
|
|
6
|
+
/**初始化 多表单收集 实例*/
|
|
7
|
+
export declare const useMultipleForm: (multipleForm?: MultipleInstanceBase) => MultipleInstanceBase;
|
|
8
|
+
export interface MultipleFormProviderProps {
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
multipleForm?: MultipleInstanceBase;
|
|
11
|
+
}
|
|
12
|
+
/**多表单收集 Provider */
|
|
13
|
+
export declare const MultipleFormProvider: (props: MultipleFormProviderProps) => import("react").FunctionComponentElement<import("react").ProviderProps<MultipleInstanceBase>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__ from "@carefrees/form-utils";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
3
|
+
const MultipleFormInstanceContext = (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)(new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.MultipleInstanceBase());
|
|
4
|
+
const useMultipleFormInstance = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(MultipleFormInstanceContext);
|
|
5
|
+
const useMultipleForm = (multipleForm)=>{
|
|
6
|
+
const ref = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)();
|
|
7
|
+
if (!ref.current) if (multipleForm) ref.current = multipleForm;
|
|
8
|
+
else ref.current = new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.MultipleInstanceBase();
|
|
9
|
+
return ref.current;
|
|
10
|
+
};
|
|
11
|
+
const MultipleFormProvider = (props)=>{
|
|
12
|
+
const { children, multipleForm } = props;
|
|
13
|
+
const multipleFormInstance = useMultipleForm(multipleForm);
|
|
14
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_react__.createElement)(MultipleFormInstanceContext.Provider, {
|
|
15
|
+
value: multipleFormInstance,
|
|
16
|
+
children
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export { MultipleFormInstanceContext, MultipleFormProvider, useMultipleForm, useMultipleFormInstance };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
2
|
+
const useUpdate = ()=>{
|
|
3
|
+
const [, _update] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)({});
|
|
4
|
+
const refUpdate = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(()=>void 0);
|
|
5
|
+
refUpdate.current = ()=>{
|
|
6
|
+
_update({});
|
|
7
|
+
};
|
|
8
|
+
return refUpdate;
|
|
9
|
+
};
|
|
10
|
+
export { useUpdate };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FormInstanceBase } from '@carefrees/form-utils';
|
|
2
|
+
export declare class WatchInstanceBase {
|
|
3
|
+
/**监听字段*/
|
|
4
|
+
name: string;
|
|
5
|
+
/**表单实例*/
|
|
6
|
+
form: FormInstanceBase;
|
|
7
|
+
/**老值*/
|
|
8
|
+
oldValue: any;
|
|
9
|
+
/**更新值*/
|
|
10
|
+
dispatch: (value: any) => void;
|
|
11
|
+
/**回调*/
|
|
12
|
+
callBack?: (value: any, form: FormInstanceBase) => void;
|
|
13
|
+
/**更新*/
|
|
14
|
+
updated: () => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 字段监听
|
|
18
|
+
*/
|
|
19
|
+
export declare const useWatch: (name: string, form: FormInstanceBase, callBack?: (value: any, form: FormInstanceBase) => void) => [any, FormInstanceBase, WatchInstanceBase];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__useForm_js_e31b00cd__ from "./useForm.js";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE__useFormItem_js_ee04de55__ from "./useFormItem.js";
|
|
4
|
+
class WatchInstanceBase {
|
|
5
|
+
name;
|
|
6
|
+
form;
|
|
7
|
+
oldValue;
|
|
8
|
+
dispatch;
|
|
9
|
+
callBack;
|
|
10
|
+
updated = ()=>{
|
|
11
|
+
const newValue = this.form.getFieldValue(this.name);
|
|
12
|
+
if (this.oldValue === newValue) return;
|
|
13
|
+
if (this.callBack) this.callBack(newValue, this.form);
|
|
14
|
+
else this.dispatch(newValue);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const useWatch = (name, form, callBack)=>{
|
|
18
|
+
const formInstance = form || (0, __WEBPACK_EXTERNAL_MODULE__useForm_js_e31b00cd__.useFormInstance)();
|
|
19
|
+
const [oldValue, setValue] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(formInstance.getFieldValue(name));
|
|
20
|
+
const watch = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(new WatchInstanceBase()).current;
|
|
21
|
+
watch.name = name;
|
|
22
|
+
watch.oldValue = oldValue;
|
|
23
|
+
watch.dispatch = setValue;
|
|
24
|
+
watch.callBack = callBack;
|
|
25
|
+
watch.form = formInstance;
|
|
26
|
+
const formItemInstance = (0, __WEBPACK_EXTERNAL_MODULE__useFormItem_js_ee04de55__.useFormItem)();
|
|
27
|
+
(0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>formItemInstance.ctor(name), []);
|
|
28
|
+
formItemInstance.instance = formInstance;
|
|
29
|
+
formItemInstance.isWatch = true;
|
|
30
|
+
formItemInstance.updated = watch.updated;
|
|
31
|
+
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
32
|
+
const unMount = formInstance.registerFormItem(formItemInstance);
|
|
33
|
+
return ()=>unMount();
|
|
34
|
+
}, []);
|
|
35
|
+
return [
|
|
36
|
+
oldValue,
|
|
37
|
+
formInstance,
|
|
38
|
+
watch
|
|
39
|
+
];
|
|
40
|
+
};
|
|
41
|
+
export { WatchInstanceBase, useWatch };
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FormInstanceBase, ValidateErrorEntity } from '@carefrees/form-utils';
|
|
3
|
+
import { FormLayoutProps } from './layout';
|
|
4
|
+
import './styles/index.css';
|
|
5
|
+
export * from './formItem';
|
|
6
|
+
export * from './formList';
|
|
7
|
+
export * from './layout';
|
|
8
|
+
export * from './layout/layout.formItem';
|
|
9
|
+
export * from './hooks/useAttrs';
|
|
10
|
+
export * from './hooks/useForm';
|
|
11
|
+
export * from './hooks/useFormItem';
|
|
12
|
+
export * from './hooks/useFormItemParentName';
|
|
13
|
+
export * from './hooks/useFormList';
|
|
14
|
+
export * from './hooks/useHtmlFor';
|
|
15
|
+
export * from './hooks/useMultipleForm';
|
|
16
|
+
export * from './hooks/useWatch';
|
|
17
|
+
export * from './hooks/attr/attr.FormItem';
|
|
18
|
+
export * from './hooks/register/register.FormHideItem';
|
|
19
|
+
export * from './hooks/register/register.FormItem';
|
|
20
|
+
export * from './hooks/register/register.FormList';
|
|
21
|
+
export * from './hooks/register/register.form';
|
|
22
|
+
export interface FormProps<T = any> extends FormLayoutProps {
|
|
23
|
+
children?: React.ReactNode;
|
|
24
|
+
form?: FormInstanceBase;
|
|
25
|
+
style?: React.CSSProperties;
|
|
26
|
+
className?: string;
|
|
27
|
+
layoutClassName?: string;
|
|
28
|
+
layoutStyle?: React.CSSProperties;
|
|
29
|
+
/**表单数据*/
|
|
30
|
+
formData?: any;
|
|
31
|
+
/**值更新触发*/
|
|
32
|
+
onValuesChange?: (changedValues: Partial<T>, values: T) => void;
|
|
33
|
+
/**提交保存 验证成功*/
|
|
34
|
+
onFinish?: (values: T) => void;
|
|
35
|
+
/**提交保存 验证失败*/
|
|
36
|
+
onFinishFailed?: (errorInfo: ValidateErrorEntity<T>) => void;
|
|
37
|
+
/**隐藏表单项初始值*/
|
|
38
|
+
hideData?: Record<string, boolean>;
|
|
39
|
+
/**表单名称*/
|
|
40
|
+
name?: string;
|
|
41
|
+
/**隐藏规则校验*/
|
|
42
|
+
hideRuleData?: Record<string, boolean>;
|
|
43
|
+
/**自动重置更新formData数据*/
|
|
44
|
+
isAutoUpdatedFormData?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export declare function Form<T = any>(props: FormProps<T>): import("react/jsx-runtime").JSX.Element;
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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_classnames__ from "classnames";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__layout_index_js_0ed29524__ from "./layout/index.js";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__hooks_useForm_js_204ed681__ from "./hooks/useForm.js";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__hooks_register_register_form_js_792e1382__ from "./hooks/register/register.form.js";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__ from "@tarojs/components";
|
|
8
|
+
import "./styles/index.css";
|
|
9
|
+
export * from "./formItem/index.js";
|
|
10
|
+
export * from "./formList/index.js";
|
|
11
|
+
export * from "./layout/index.js";
|
|
12
|
+
export * from "./layout/layout.formItem.js";
|
|
13
|
+
export * from "./hooks/useAttrs.js";
|
|
14
|
+
export * from "./hooks/useForm.js";
|
|
15
|
+
export * from "./hooks/useFormItem.js";
|
|
16
|
+
export * from "./hooks/useFormItemParentName.js";
|
|
17
|
+
export * from "./hooks/useFormList.js";
|
|
18
|
+
export * from "./hooks/useHtmlFor.js";
|
|
19
|
+
export * from "./hooks/useMultipleForm.js";
|
|
20
|
+
export * from "./hooks/useWatch.js";
|
|
21
|
+
export * from "./hooks/attr/attr.FormItem.js";
|
|
22
|
+
export * from "./hooks/register/register.FormHideItem.js";
|
|
23
|
+
export * from "./hooks/register/register.FormItem.js";
|
|
24
|
+
export * from "./hooks/register/register.FormList.js";
|
|
25
|
+
export * from "./hooks/register/register.form.js";
|
|
26
|
+
function Form(props) {
|
|
27
|
+
const { children, form, style, className, formData, hideData, hideRuleData, isAutoUpdatedFormData = false, name, onFinish, onFinishFailed, onValuesChange, layoutStyle, layoutClassName, ...rest } = props;
|
|
28
|
+
const formInstance = (0, __WEBPACK_EXTERNAL_MODULE__hooks_useForm_js_204ed681__.useForm)(form);
|
|
29
|
+
(0, __WEBPACK_EXTERNAL_MODULE__hooks_register_register_form_js_792e1382__.useRegisterForm)(formInstance, name);
|
|
30
|
+
const cls = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])('carefrees-form', className), []);
|
|
31
|
+
(0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>formInstance.ctor(formData, hideData, hideRuleData), []);
|
|
32
|
+
formInstance.onFinish = onFinish;
|
|
33
|
+
formInstance.onValuesChange = onValuesChange;
|
|
34
|
+
formInstance.onFinishFailed = onFinishFailed;
|
|
35
|
+
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
36
|
+
if (isAutoUpdatedFormData) formInstance.resetFieldValue(formData);
|
|
37
|
+
}, [
|
|
38
|
+
isAutoUpdatedFormData,
|
|
39
|
+
formData
|
|
40
|
+
]);
|
|
41
|
+
const onSubmit = (event)=>{
|
|
42
|
+
event?.preventDefault?.();
|
|
43
|
+
event?.stopPropagation?.();
|
|
44
|
+
formInstance.submit();
|
|
45
|
+
};
|
|
46
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__hooks_useForm_js_204ed681__.FormInstanceContext.Provider, {
|
|
47
|
+
value: formInstance,
|
|
48
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.Form, {
|
|
49
|
+
className: cls,
|
|
50
|
+
style: style,
|
|
51
|
+
onSubmit: onSubmit,
|
|
52
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__layout_index_js_0ed29524__.FormLayout, {
|
|
53
|
+
...rest,
|
|
54
|
+
className: layoutClassName,
|
|
55
|
+
style: layoutStyle,
|
|
56
|
+
children: children
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export { Form };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ViewProps } from '@tarojs/components';
|
|
3
|
+
import { AttrsOptions } from '../hooks/useAttrs';
|
|
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
|
+
className?: string;
|
|
14
|
+
/**头部ClassName*/
|
|
15
|
+
headerClassName?: string;
|
|
16
|
+
/**内容ClassName*/
|
|
17
|
+
bodyClassName?: string;
|
|
18
|
+
style?: React.CSSProperties;
|
|
19
|
+
/**头部样式*/
|
|
20
|
+
headerStyle?: React.CSSProperties;
|
|
21
|
+
/**内容样式*/
|
|
22
|
+
bodyStyle?: React.CSSProperties;
|
|
23
|
+
/**是否添加边框*/
|
|
24
|
+
bordered?: boolean;
|
|
25
|
+
/**列数据*/
|
|
26
|
+
colCount?: number;
|
|
27
|
+
/**
|
|
28
|
+
* @description gap 属性是用来设置网格行与列之间的间隙,该属性是row-gap and column-gap的简写形式。
|
|
29
|
+
*/
|
|
30
|
+
gap?: string | number;
|
|
31
|
+
}
|
|
32
|
+
/**布局组件*/
|
|
33
|
+
export declare const FormLayout: React.MemoExoticComponent<(props: FormLayoutProps) => import("react/jsx-runtime").JSX.Element>;
|
|
34
|
+
/**布局组件 占据一整行*/
|
|
35
|
+
export declare const FormLayoutRows: (props: ViewProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,99 @@
|
|
|
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__tarojs_components_865ae511__ from "@tarojs/components";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_classnames__ from "classnames";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__hooks_useAttrs_js_86d21a28__ from "../hooks/useAttrs.js";
|
|
6
|
+
const preCls = 'carefrees-form-layout';
|
|
7
|
+
const FormLayout = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)((props)=>{
|
|
8
|
+
const { colCount: p_colCount = 4, errorLayout: p_errorLayout = 'left-bottom', labelMode: p_labelMode = 'left', showColon: p_showColon = true, formItemClassName: p_formItemClassName, formItemStyle: p_formItemStyle, formItemLabelClassName: p_formItemLabelClassName, formItemLabelStyle: p_formItemLabelStyle } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_useAttrs_js_86d21a28__.useAttrs)();
|
|
9
|
+
const { colCount = p_colCount, title, extra, children, isAllColSpan, className, headerClassName, bodyClassName, style, headerStyle, bodyStyle, errorLayout = p_errorLayout, labelMode = p_labelMode, showColon = p_showColon, formItemClassName = p_formItemClassName, formItemStyle = p_formItemStyle, formItemLabelClassName = p_formItemLabelClassName, formItemLabelStyle = p_formItemLabelStyle, bordered = false, gap } = props;
|
|
10
|
+
const propsRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(props);
|
|
11
|
+
propsRef.current = props;
|
|
12
|
+
const cls = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(preCls, className, {
|
|
13
|
+
'all-colspan': isAllColSpan,
|
|
14
|
+
bordered: bordered
|
|
15
|
+
}), [
|
|
16
|
+
className
|
|
17
|
+
]);
|
|
18
|
+
const bodyCls = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(`${preCls}-body`, bodyClassName), [
|
|
19
|
+
bodyClassName
|
|
20
|
+
]);
|
|
21
|
+
const headerCls = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(`${preCls}-header`, headerClassName), [
|
|
22
|
+
headerClassName
|
|
23
|
+
]);
|
|
24
|
+
const headerTitleCls = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(`${preCls}-header-title`), []);
|
|
25
|
+
const headerExtraCls = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(`${preCls}-header-extra`), []);
|
|
26
|
+
const value = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
|
|
27
|
+
colCount,
|
|
28
|
+
errorLayout,
|
|
29
|
+
labelMode,
|
|
30
|
+
showColon,
|
|
31
|
+
formItemClassName,
|
|
32
|
+
formItemStyle,
|
|
33
|
+
formItemLabelClassName,
|
|
34
|
+
formItemLabelStyle
|
|
35
|
+
}), [
|
|
36
|
+
colCount,
|
|
37
|
+
errorLayout,
|
|
38
|
+
labelMode,
|
|
39
|
+
showColon,
|
|
40
|
+
formItemClassName,
|
|
41
|
+
formItemStyle,
|
|
42
|
+
formItemLabelClassName,
|
|
43
|
+
formItemLabelStyle
|
|
44
|
+
]);
|
|
45
|
+
const styleBase = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
|
|
46
|
+
const css = {};
|
|
47
|
+
if ('string' == typeof gap) css.gap = gap;
|
|
48
|
+
if ('number' == typeof gap) css.gap = `${gap}px`;
|
|
49
|
+
if (colCount) css.gridTemplateColumns = `repeat(${colCount}, auto)`;
|
|
50
|
+
return css;
|
|
51
|
+
}, [
|
|
52
|
+
colCount,
|
|
53
|
+
gap
|
|
54
|
+
]);
|
|
55
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__hooks_useAttrs_js_86d21a28__.AttrsContext.Provider, {
|
|
56
|
+
value: value,
|
|
57
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.View, {
|
|
58
|
+
style: style,
|
|
59
|
+
className: cls,
|
|
60
|
+
children: [
|
|
61
|
+
title || extra ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.View, {
|
|
62
|
+
style: headerStyle,
|
|
63
|
+
className: headerCls,
|
|
64
|
+
children: [
|
|
65
|
+
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.View, {
|
|
66
|
+
className: headerTitleCls,
|
|
67
|
+
children: title
|
|
68
|
+
}),
|
|
69
|
+
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.View, {
|
|
70
|
+
className: headerExtraCls,
|
|
71
|
+
children: extra
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
}) : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react__.Fragment, {}),
|
|
75
|
+
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.View, {
|
|
76
|
+
style: {
|
|
77
|
+
...styleBase,
|
|
78
|
+
...bodyStyle
|
|
79
|
+
},
|
|
80
|
+
className: bodyCls,
|
|
81
|
+
children: children
|
|
82
|
+
})
|
|
83
|
+
]
|
|
84
|
+
})
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
const FormLayoutRows = (props)=>{
|
|
88
|
+
const { className } = props;
|
|
89
|
+
const cls = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(preCls, className, {
|
|
90
|
+
'all-colspan': true
|
|
91
|
+
}), [
|
|
92
|
+
className
|
|
93
|
+
]);
|
|
94
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.View, {
|
|
95
|
+
...props,
|
|
96
|
+
className: cls
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
export { FormLayout, FormLayoutRows };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface LayoutFormItemProps {
|
|
3
|
+
/**规则校验失败错误提示位置*/
|
|
4
|
+
errorLayout?: 'left-bottom' | 'right-bottom' | 'top-right' | 'top-left';
|
|
5
|
+
/**必填样式*/
|
|
6
|
+
required?: boolean;
|
|
7
|
+
/**label显示模式*/
|
|
8
|
+
labelMode?: 'left' | 'top' | 'between' | 'hide';
|
|
9
|
+
/**内容*/
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
/**只进行规则样式*/
|
|
12
|
+
onlyRuleStyle?: boolean;
|
|
13
|
+
label?: React.ReactNode;
|
|
14
|
+
/**底部提示内容*/
|
|
15
|
+
helpText?: React.ReactNode;
|
|
16
|
+
/**额外内容*/
|
|
17
|
+
extra?: React.ReactNode;
|
|
18
|
+
/**是否显示label后的冒号*/
|
|
19
|
+
showColon?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* 表单项占据列数
|
|
22
|
+
* @default 1
|
|
23
|
+
*/
|
|
24
|
+
colSpan?: number;
|
|
25
|
+
/**
|
|
26
|
+
* 表单项占据行数
|
|
27
|
+
* @default 1
|
|
28
|
+
*/
|
|
29
|
+
rowSpan?: number;
|
|
30
|
+
htmlFor?: string;
|
|
31
|
+
/**规则验证结果*/
|
|
32
|
+
validateResult?: {
|
|
33
|
+
tip: string | (string | undefined)[];
|
|
34
|
+
isInvalid: boolean;
|
|
35
|
+
};
|
|
36
|
+
style?: React.CSSProperties;
|
|
37
|
+
className?: string;
|
|
38
|
+
labelStyle?: React.CSSProperties;
|
|
39
|
+
labelClassName?: string;
|
|
40
|
+
/**底部边框*/
|
|
41
|
+
inputBordered?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**布局组件 表单项*/
|
|
44
|
+
export declare const LayoutFormItem: React.MemoExoticComponent<(props: LayoutFormItemProps) => import("react/jsx-runtime").JSX.Element>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__ from "@tarojs/components";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_classnames__ from "classnames";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__hooks_useAttrs_js_86d21a28__ from "../hooks/useAttrs.js";
|
|
6
|
+
const preCls = 'carefrees-form-item';
|
|
7
|
+
const LayoutFormItem = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)((props)=>{
|
|
8
|
+
const { formItemClassName, formItemLabelClassName, formItemLabelStyle, formItemStyle, labelMode: p_labelMode = 'top', errorLayout: p_errorLayout = 'left-bottom', showColon: p_showColon = true, colCount = 1, inputBordered: p_inputBordered = true } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_useAttrs_js_86d21a28__.useAttrs)();
|
|
9
|
+
const { children, labelMode = p_labelMode, onlyRuleStyle, label, helpText, extra, showColon = p_showColon, colSpan = 1, rowSpan = 1, validateResult, htmlFor, required, errorLayout = p_errorLayout, style, className, labelClassName, labelStyle, inputBordered = p_inputBordered } = props;
|
|
10
|
+
const tip = validateResult?.tip;
|
|
11
|
+
const isInvalid = !!validateResult?.isInvalid;
|
|
12
|
+
const _errorLayout = 'between' === labelMode ? 'right-bottom' : errorLayout;
|
|
13
|
+
const cls = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(preCls, className, formItemClassName, {
|
|
14
|
+
'dx-invalid': isInvalid
|
|
15
|
+
}), [
|
|
16
|
+
isInvalid
|
|
17
|
+
]);
|
|
18
|
+
const containerCls = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(`${preCls}-container`, {
|
|
19
|
+
[`${labelMode}`]: !!labelMode
|
|
20
|
+
}), [
|
|
21
|
+
labelMode
|
|
22
|
+
]);
|
|
23
|
+
const labelCls = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(`${preCls}-label`, {
|
|
24
|
+
required: required,
|
|
25
|
+
'show-colon': showColon && ('left' === labelMode || 'between' === labelMode)
|
|
26
|
+
}), [
|
|
27
|
+
labelMode,
|
|
28
|
+
required,
|
|
29
|
+
showColon
|
|
30
|
+
]);
|
|
31
|
+
const labelWarpCls = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(`${preCls}-label-warp`, labelClassName, formItemLabelClassName), [
|
|
32
|
+
labelClassName,
|
|
33
|
+
formItemLabelClassName
|
|
34
|
+
]);
|
|
35
|
+
const inputCls = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(`${preCls}-body-input`, {
|
|
36
|
+
'input-bordered': inputBordered
|
|
37
|
+
}), [
|
|
38
|
+
inputBordered
|
|
39
|
+
]);
|
|
40
|
+
const errorCls = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(`${preCls}-body-error`, {
|
|
41
|
+
[_errorLayout]: !!_errorLayout
|
|
42
|
+
}), [
|
|
43
|
+
_errorLayout
|
|
44
|
+
]);
|
|
45
|
+
const _isLabel = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>label && 'hide' !== labelMode, [
|
|
46
|
+
label,
|
|
47
|
+
labelMode
|
|
48
|
+
]);
|
|
49
|
+
const styleBase = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
|
|
50
|
+
const css = {};
|
|
51
|
+
if (onlyRuleStyle) css.padding = '0px';
|
|
52
|
+
if (colSpan) {
|
|
53
|
+
const end = colCount > colSpan ? colSpan : colCount;
|
|
54
|
+
css.gridColumnEnd = `span ${end}`;
|
|
55
|
+
}
|
|
56
|
+
if (rowSpan) css.gridRowEnd = `span ${rowSpan}`;
|
|
57
|
+
return css;
|
|
58
|
+
}, [
|
|
59
|
+
onlyRuleStyle,
|
|
60
|
+
colSpan,
|
|
61
|
+
rowSpan,
|
|
62
|
+
colCount
|
|
63
|
+
]);
|
|
64
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.View, {
|
|
65
|
+
style: {
|
|
66
|
+
...formItemStyle,
|
|
67
|
+
...styleBase,
|
|
68
|
+
...style
|
|
69
|
+
},
|
|
70
|
+
className: cls,
|
|
71
|
+
children: [
|
|
72
|
+
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.View, {
|
|
73
|
+
className: containerCls,
|
|
74
|
+
children: [
|
|
75
|
+
_isLabel ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.View, {
|
|
76
|
+
style: {
|
|
77
|
+
...formItemLabelStyle,
|
|
78
|
+
...labelStyle
|
|
79
|
+
},
|
|
80
|
+
className: labelWarpCls,
|
|
81
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.Label, {
|
|
82
|
+
for: htmlFor,
|
|
83
|
+
className: labelCls,
|
|
84
|
+
children: label
|
|
85
|
+
})
|
|
86
|
+
}) : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react__.Fragment, {}),
|
|
87
|
+
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.View, {
|
|
88
|
+
className: `${preCls}-body`,
|
|
89
|
+
children: [
|
|
90
|
+
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.View, {
|
|
91
|
+
className: inputCls,
|
|
92
|
+
children: children
|
|
93
|
+
}),
|
|
94
|
+
helpText ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.View, {
|
|
95
|
+
className: `${preCls}-body-help`,
|
|
96
|
+
children: helpText
|
|
97
|
+
}) : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react__.Fragment, {}),
|
|
98
|
+
isInvalid ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.View, {
|
|
99
|
+
className: errorCls,
|
|
100
|
+
children: tip
|
|
101
|
+
}) : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react__.Fragment, {})
|
|
102
|
+
]
|
|
103
|
+
})
|
|
104
|
+
]
|
|
105
|
+
}),
|
|
106
|
+
extra ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__tarojs_components_865ae511__.View, {
|
|
107
|
+
className: `${preCls}-extra`,
|
|
108
|
+
children: extra
|
|
109
|
+
}) : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react__.Fragment, {})
|
|
110
|
+
]
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
export { LayoutFormItem };
|