@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.
Files changed (100) hide show
  1. package/README.md +9 -0
  2. package/esm/formItem/index.d.ts +11 -0
  3. package/esm/formItem/index.js +70 -0
  4. package/esm/formList/index.d.ts +27 -0
  5. package/esm/formList/index.js +40 -0
  6. package/esm/hooks/attr/attr.FormItem.d.ts +48 -0
  7. package/esm/hooks/attr/attr.FormItem.js +61 -0
  8. package/esm/hooks/register/register.FormHideItem.d.ts +9 -0
  9. package/esm/hooks/register/register.FormHideItem.js +31 -0
  10. package/esm/hooks/register/register.FormItem.d.ts +23 -0
  11. package/esm/hooks/register/register.FormItem.js +42 -0
  12. package/esm/hooks/register/register.FormList.d.ts +9 -0
  13. package/esm/hooks/register/register.FormList.js +31 -0
  14. package/esm/hooks/register/register.form.d.ts +3 -0
  15. package/esm/hooks/register/register.form.js +17 -0
  16. package/esm/hooks/useAttrs.d.ts +25 -0
  17. package/esm/hooks/useAttrs.js +10 -0
  18. package/esm/hooks/useForm.d.ts +7 -0
  19. package/esm/hooks/useForm.js +13 -0
  20. package/esm/hooks/useFormItem.d.ts +7 -0
  21. package/esm/hooks/useFormItem.js +11 -0
  22. package/esm/hooks/useFormItemParentName.d.ts +30 -0
  23. package/esm/hooks/useFormItemParentName.js +61 -0
  24. package/esm/hooks/useFormList.d.ts +7 -0
  25. package/esm/hooks/useFormList.js +11 -0
  26. package/esm/hooks/useHtmlFor.d.ts +1 -0
  27. package/esm/hooks/useHtmlFor.js +10 -0
  28. package/esm/hooks/useMultipleForm.d.ts +13 -0
  29. package/esm/hooks/useMultipleForm.js +19 -0
  30. package/esm/hooks/useUpdate.d.ts +2 -0
  31. package/esm/hooks/useUpdate.js +10 -0
  32. package/esm/hooks/useWatch.d.ts +19 -0
  33. package/esm/hooks/useWatch.js +41 -0
  34. package/esm/index.d.ts +46 -0
  35. package/esm/index.js +61 -0
  36. package/esm/layout/index.d.ts +35 -0
  37. package/esm/layout/index.js +99 -0
  38. package/esm/layout/layout.formItem.d.ts +44 -0
  39. package/esm/layout/layout.formItem.js +113 -0
  40. package/esm/styles/index.css +200 -0
  41. package/lib/formItem/index.d.ts +11 -0
  42. package/lib/formItem/index.js +107 -0
  43. package/lib/formList/index.d.ts +27 -0
  44. package/lib/formList/index.js +77 -0
  45. package/lib/hooks/attr/attr.FormItem.d.ts +48 -0
  46. package/lib/hooks/attr/attr.FormItem.js +95 -0
  47. package/lib/hooks/register/register.FormHideItem.d.ts +9 -0
  48. package/lib/hooks/register/register.FormHideItem.js +65 -0
  49. package/lib/hooks/register/register.FormItem.d.ts +23 -0
  50. package/lib/hooks/register/register.FormItem.js +76 -0
  51. package/lib/hooks/register/register.FormList.d.ts +9 -0
  52. package/lib/hooks/register/register.FormList.js +65 -0
  53. package/lib/hooks/register/register.form.d.ts +3 -0
  54. package/lib/hooks/register/register.form.js +51 -0
  55. package/lib/hooks/useAttrs.d.ts +25 -0
  56. package/lib/hooks/useAttrs.js +47 -0
  57. package/lib/hooks/useForm.d.ts +7 -0
  58. package/lib/hooks/useForm.js +53 -0
  59. package/lib/hooks/useFormItem.d.ts +7 -0
  60. package/lib/hooks/useFormItem.js +51 -0
  61. package/lib/hooks/useFormItemParentName.d.ts +30 -0
  62. package/lib/hooks/useFormItemParentName.js +101 -0
  63. package/lib/hooks/useFormList.d.ts +7 -0
  64. package/lib/hooks/useFormList.js +51 -0
  65. package/lib/hooks/useHtmlFor.d.ts +1 -0
  66. package/lib/hooks/useHtmlFor.js +44 -0
  67. package/lib/hooks/useMultipleForm.d.ts +13 -0
  68. package/lib/hooks/useMultipleForm.js +62 -0
  69. package/lib/hooks/useUpdate.d.ts +2 -0
  70. package/lib/hooks/useUpdate.js +44 -0
  71. package/lib/hooks/useWatch.d.ts +19 -0
  72. package/lib/hooks/useWatch.js +78 -0
  73. package/lib/index.d.ts +46 -0
  74. package/lib/index.js +317 -0
  75. package/lib/layout/index.d.ts +35 -0
  76. package/lib/layout/index.js +146 -0
  77. package/lib/layout/layout.formItem.d.ts +44 -0
  78. package/lib/layout/layout.formItem.js +157 -0
  79. package/lib/styles/index.css +200 -0
  80. package/package.json +32 -0
  81. package/src/formItem/index.tsx +103 -0
  82. package/src/formList/index.tsx +59 -0
  83. package/src/hooks/attr/attr.FormItem.tsx +131 -0
  84. package/src/hooks/register/register.FormHideItem.ts +29 -0
  85. package/src/hooks/register/register.FormItem.ts +52 -0
  86. package/src/hooks/register/register.FormList.ts +31 -0
  87. package/src/hooks/register/register.form.ts +18 -0
  88. package/src/hooks/useAttrs.ts +35 -0
  89. package/src/hooks/useForm.ts +23 -0
  90. package/src/hooks/useFormItem.ts +21 -0
  91. package/src/hooks/useFormItemParentName.ts +49 -0
  92. package/src/hooks/useFormList.ts +21 -0
  93. package/src/hooks/useHtmlFor.ts +9 -0
  94. package/src/hooks/useMultipleForm.ts +36 -0
  95. package/src/hooks/useUpdate.ts +12 -0
  96. package/src/hooks/useWatch.ts +61 -0
  97. package/src/index.tsx +102 -0
  98. package/src/layout/index.tsx +152 -0
  99. package/src/layout/layout.formItem.tsx +152 -0
  100. package/src/styles/index.css +208 -0
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ FormLayout: ()=>FormLayout,
37
+ FormLayoutRows: ()=>FormLayoutRows
38
+ });
39
+ const jsx_runtime_namespaceObject = require("react/jsx-runtime");
40
+ const external_react_namespaceObject = require("react");
41
+ const components_namespaceObject = require("@tarojs/components");
42
+ const external_classnames_namespaceObject = require("classnames");
43
+ var external_classnames_default = /*#__PURE__*/ __webpack_require__.n(external_classnames_namespaceObject);
44
+ const useAttrs_js_namespaceObject = require("../hooks/useAttrs.js");
45
+ const preCls = 'carefrees-form-layout';
46
+ const FormLayout = /*#__PURE__*/ (0, external_react_namespaceObject.memo)((props)=>{
47
+ 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, useAttrs_js_namespaceObject.useAttrs)();
48
+ 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;
49
+ const propsRef = (0, external_react_namespaceObject.useRef)(props);
50
+ propsRef.current = props;
51
+ const cls = (0, external_react_namespaceObject.useMemo)(()=>external_classnames_default()(preCls, className, {
52
+ 'all-colspan': isAllColSpan,
53
+ bordered: bordered
54
+ }), [
55
+ className
56
+ ]);
57
+ const bodyCls = (0, external_react_namespaceObject.useMemo)(()=>external_classnames_default()(`${preCls}-body`, bodyClassName), [
58
+ bodyClassName
59
+ ]);
60
+ const headerCls = (0, external_react_namespaceObject.useMemo)(()=>external_classnames_default()(`${preCls}-header`, headerClassName), [
61
+ headerClassName
62
+ ]);
63
+ const headerTitleCls = (0, external_react_namespaceObject.useMemo)(()=>external_classnames_default()(`${preCls}-header-title`), []);
64
+ const headerExtraCls = (0, external_react_namespaceObject.useMemo)(()=>external_classnames_default()(`${preCls}-header-extra`), []);
65
+ const value = (0, external_react_namespaceObject.useMemo)(()=>({
66
+ colCount,
67
+ errorLayout,
68
+ labelMode,
69
+ showColon,
70
+ formItemClassName,
71
+ formItemStyle,
72
+ formItemLabelClassName,
73
+ formItemLabelStyle
74
+ }), [
75
+ colCount,
76
+ errorLayout,
77
+ labelMode,
78
+ showColon,
79
+ formItemClassName,
80
+ formItemStyle,
81
+ formItemLabelClassName,
82
+ formItemLabelStyle
83
+ ]);
84
+ const styleBase = (0, external_react_namespaceObject.useMemo)(()=>{
85
+ const css = {};
86
+ if ('string' == typeof gap) css.gap = gap;
87
+ if ('number' == typeof gap) css.gap = `${gap}px`;
88
+ if (colCount) css.gridTemplateColumns = `repeat(${colCount}, auto)`;
89
+ return css;
90
+ }, [
91
+ colCount,
92
+ gap
93
+ ]);
94
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(useAttrs_js_namespaceObject.AttrsContext.Provider, {
95
+ value: value,
96
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(components_namespaceObject.View, {
97
+ style: style,
98
+ className: cls,
99
+ children: [
100
+ title || extra ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(components_namespaceObject.View, {
101
+ style: headerStyle,
102
+ className: headerCls,
103
+ children: [
104
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.View, {
105
+ className: headerTitleCls,
106
+ children: title
107
+ }),
108
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.View, {
109
+ className: headerExtraCls,
110
+ children: extra
111
+ })
112
+ ]
113
+ }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_namespaceObject.Fragment, {}),
114
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.View, {
115
+ style: {
116
+ ...styleBase,
117
+ ...bodyStyle
118
+ },
119
+ className: bodyCls,
120
+ children: children
121
+ })
122
+ ]
123
+ })
124
+ });
125
+ });
126
+ const FormLayoutRows = (props)=>{
127
+ const { className } = props;
128
+ const cls = (0, external_react_namespaceObject.useMemo)(()=>external_classnames_default()(preCls, className, {
129
+ 'all-colspan': true
130
+ }), [
131
+ className
132
+ ]);
133
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.View, {
134
+ ...props,
135
+ className: cls
136
+ });
137
+ };
138
+ exports.FormLayout = __webpack_exports__.FormLayout;
139
+ exports.FormLayoutRows = __webpack_exports__.FormLayoutRows;
140
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
141
+ "FormLayout",
142
+ "FormLayoutRows"
143
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
144
+ Object.defineProperty(exports, '__esModule', {
145
+ value: true
146
+ });
@@ -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,157 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ LayoutFormItem: ()=>LayoutFormItem
37
+ });
38
+ const jsx_runtime_namespaceObject = require("react/jsx-runtime");
39
+ const components_namespaceObject = require("@tarojs/components");
40
+ const external_react_namespaceObject = require("react");
41
+ const external_classnames_namespaceObject = require("classnames");
42
+ var external_classnames_default = /*#__PURE__*/ __webpack_require__.n(external_classnames_namespaceObject);
43
+ const useAttrs_js_namespaceObject = require("../hooks/useAttrs.js");
44
+ const preCls = 'carefrees-form-item';
45
+ const LayoutFormItem = /*#__PURE__*/ (0, external_react_namespaceObject.memo)((props)=>{
46
+ 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, useAttrs_js_namespaceObject.useAttrs)();
47
+ 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;
48
+ const tip = validateResult?.tip;
49
+ const isInvalid = !!validateResult?.isInvalid;
50
+ const _errorLayout = 'between' === labelMode ? 'right-bottom' : errorLayout;
51
+ const cls = (0, external_react_namespaceObject.useMemo)(()=>external_classnames_default()(preCls, className, formItemClassName, {
52
+ 'dx-invalid': isInvalid
53
+ }), [
54
+ isInvalid
55
+ ]);
56
+ const containerCls = (0, external_react_namespaceObject.useMemo)(()=>external_classnames_default()(`${preCls}-container`, {
57
+ [`${labelMode}`]: !!labelMode
58
+ }), [
59
+ labelMode
60
+ ]);
61
+ const labelCls = (0, external_react_namespaceObject.useMemo)(()=>external_classnames_default()(`${preCls}-label`, {
62
+ required: required,
63
+ 'show-colon': showColon && ('left' === labelMode || 'between' === labelMode)
64
+ }), [
65
+ labelMode,
66
+ required,
67
+ showColon
68
+ ]);
69
+ const labelWarpCls = (0, external_react_namespaceObject.useMemo)(()=>external_classnames_default()(`${preCls}-label-warp`, labelClassName, formItemLabelClassName), [
70
+ labelClassName,
71
+ formItemLabelClassName
72
+ ]);
73
+ const inputCls = (0, external_react_namespaceObject.useMemo)(()=>external_classnames_default()(`${preCls}-body-input`, {
74
+ 'input-bordered': inputBordered
75
+ }), [
76
+ inputBordered
77
+ ]);
78
+ const errorCls = (0, external_react_namespaceObject.useMemo)(()=>external_classnames_default()(`${preCls}-body-error`, {
79
+ [_errorLayout]: !!_errorLayout
80
+ }), [
81
+ _errorLayout
82
+ ]);
83
+ const _isLabel = (0, external_react_namespaceObject.useMemo)(()=>label && 'hide' !== labelMode, [
84
+ label,
85
+ labelMode
86
+ ]);
87
+ const styleBase = (0, external_react_namespaceObject.useMemo)(()=>{
88
+ const css = {};
89
+ if (onlyRuleStyle) css.padding = '0px';
90
+ if (colSpan) {
91
+ const end = colCount > colSpan ? colSpan : colCount;
92
+ css.gridColumnEnd = `span ${end}`;
93
+ }
94
+ if (rowSpan) css.gridRowEnd = `span ${rowSpan}`;
95
+ return css;
96
+ }, [
97
+ onlyRuleStyle,
98
+ colSpan,
99
+ rowSpan,
100
+ colCount
101
+ ]);
102
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(components_namespaceObject.View, {
103
+ style: {
104
+ ...formItemStyle,
105
+ ...styleBase,
106
+ ...style
107
+ },
108
+ className: cls,
109
+ children: [
110
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(components_namespaceObject.View, {
111
+ className: containerCls,
112
+ children: [
113
+ _isLabel ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.View, {
114
+ style: {
115
+ ...formItemLabelStyle,
116
+ ...labelStyle
117
+ },
118
+ className: labelWarpCls,
119
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.Label, {
120
+ for: htmlFor,
121
+ className: labelCls,
122
+ children: label
123
+ })
124
+ }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_namespaceObject.Fragment, {}),
125
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(components_namespaceObject.View, {
126
+ className: `${preCls}-body`,
127
+ children: [
128
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.View, {
129
+ className: inputCls,
130
+ children: children
131
+ }),
132
+ helpText ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.View, {
133
+ className: `${preCls}-body-help`,
134
+ children: helpText
135
+ }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_namespaceObject.Fragment, {}),
136
+ isInvalid ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.View, {
137
+ className: errorCls,
138
+ children: tip
139
+ }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_namespaceObject.Fragment, {})
140
+ ]
141
+ })
142
+ ]
143
+ }),
144
+ extra ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.View, {
145
+ className: `${preCls}-extra`,
146
+ children: extra
147
+ }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_namespaceObject.Fragment, {})
148
+ ]
149
+ });
150
+ });
151
+ exports.LayoutFormItem = __webpack_exports__.LayoutFormItem;
152
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
153
+ "LayoutFormItem"
154
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
155
+ Object.defineProperty(exports, '__esModule', {
156
+ value: true
157
+ });
@@ -0,0 +1,200 @@
1
+ .carefrees-form {
2
+ box-sizing: border-box;
3
+ background-color: #fff;
4
+ font-size: 14px;
5
+ }
6
+
7
+ .carefrees-form-layout {
8
+ box-sizing: border-box;
9
+ border-radius: 4px;
10
+ width: 100%;
11
+ padding-bottom: 8px;
12
+ position: relative;
13
+ }
14
+
15
+ .carefrees-form-layout.all-colspan {
16
+ grid-column: 1 / -1;
17
+ }
18
+
19
+ .carefrees-form-layout.bordered {
20
+ border: 1px solid #e0e0e0;
21
+ }
22
+
23
+ .carefrees-form-layout.bordered .carefrees-form-layout-header {
24
+ padding-inline: 8px;
25
+ }
26
+
27
+ .carefrees-form-layout-header {
28
+ padding-top: 5px;
29
+ padding-bottom: 5px;
30
+ box-sizing: border-box;
31
+ border-bottom: 1px solid #e0e0e0;
32
+ flex-direction: row;
33
+ justify-content: space-between;
34
+ align-items: center;
35
+ margin-block-end: 4px;
36
+ padding-inline: 2px;
37
+ display: flex;
38
+ }
39
+
40
+ .carefrees-form-layout-header-title {
41
+ color: #1d2129;
42
+ box-sizing: border-box;
43
+ font-size: 14px;
44
+ font-weight: 600;
45
+ }
46
+
47
+ .carefrees-form-layout-header-extra {
48
+ color: #1d2129;
49
+ box-sizing: border-box;
50
+ font-size: 14px;
51
+ font-weight: 500;
52
+ }
53
+
54
+ .carefrees-form-layout-body {
55
+ box-sizing: border-box;
56
+ grid-template-columns: repeat(1, auto);
57
+ gap: 2px;
58
+ width: 100%;
59
+ padding-left: 2px;
60
+ padding-right: 2px;
61
+ display: grid;
62
+ }
63
+
64
+ .carefrees-form-item {
65
+ box-sizing: border-box;
66
+ color: #000000e0;
67
+ flex-direction: row;
68
+ align-items: flex-start;
69
+ padding: 8px;
70
+ font-size: 14px;
71
+ display: flex;
72
+ }
73
+
74
+ .carefrees-form-item-container {
75
+ box-sizing: border-box;
76
+ flex-direction: column;
77
+ flex: 1;
78
+ gap: 4px;
79
+ height: 100%;
80
+ display: flex;
81
+ }
82
+
83
+ .carefrees-form-item-container.left {
84
+ text-align: left;
85
+ flex-direction: row;
86
+ gap: 8px;
87
+ }
88
+
89
+ .carefrees-form-item-container.left .carefrees-form-item-label {
90
+ justify-content: flex-end;
91
+ }
92
+
93
+ .carefrees-form-item-container.between {
94
+ text-align: left;
95
+ flex-direction: row;
96
+ justify-content: space-between;
97
+ gap: 8px;
98
+ }
99
+
100
+ .carefrees-form-item-container.between .carefrees-form-item-body, .carefrees-form-item-container.between .carefrees-form-item-body-input {
101
+ text-align: right;
102
+ justify-content: flex-end;
103
+ }
104
+
105
+ .carefrees-form-item-label-warp {
106
+ box-sizing: border-box;
107
+ }
108
+
109
+ .carefrees-form-item-label {
110
+ box-sizing: border-box;
111
+ color: #000000e0;
112
+ justify-content: flex-start;
113
+ align-items: center;
114
+ min-height: 1.4rem;
115
+ font-size: 14px;
116
+ display: flex;
117
+ position: relative;
118
+ }
119
+
120
+ .carefrees-form-item-label.show-colon:after {
121
+ content: ":";
122
+ text-align: center;
123
+ box-sizing: border-box;
124
+ margin: 0;
125
+ margin-inline: 2px;
126
+ display: inline-block;
127
+ }
128
+
129
+ .carefrees-form-item-label.required:before {
130
+ content: "*";
131
+ color: red;
132
+ box-sizing: border-box;
133
+ margin-inline-end: 4px;
134
+ display: inline-block;
135
+ }
136
+
137
+ .carefrees-form-item-body {
138
+ box-sizing: border-box;
139
+ flex-direction: column;
140
+ flex: 1;
141
+ justify-content: flex-start;
142
+ align-items: flex-start;
143
+ gap: 4px;
144
+ display: flex;
145
+ position: relative;
146
+ }
147
+
148
+ .carefrees-form-item-body-input {
149
+ box-sizing: border-box;
150
+ flex-direction: row;
151
+ flex: 1;
152
+ justify-content: flex-start;
153
+ align-items: center;
154
+ width: 100%;
155
+ display: flex;
156
+ }
157
+
158
+ .carefrees-form-item-body-input.input-bordered {
159
+ border-bottom: 1px solid #e0e0e0;
160
+ }
161
+
162
+ .carefrees-form-item-body-help {
163
+ box-sizing: border-box;
164
+ width: 100%;
165
+ }
166
+
167
+ .carefrees-form-item-body-error {
168
+ color: red;
169
+ box-sizing: border-box;
170
+ z-index: 10;
171
+ pointer-events: none;
172
+ flex-direction: row;
173
+ justify-content: start;
174
+ width: 100%;
175
+ padding-top: 2px;
176
+ font-size: 12px;
177
+ display: flex;
178
+ position: absolute;
179
+ inset: auto 0 -16px;
180
+ }
181
+
182
+ .carefrees-form-item-body-error.right-bottom {
183
+ justify-content: flex-end;
184
+ inset: auto 0 -16px;
185
+ }
186
+
187
+ .carefrees-form-item-body-error.top-left {
188
+ justify-content: start;
189
+ inset: -16px 0 auto;
190
+ }
191
+
192
+ .carefrees-form-item-body-error.top-right {
193
+ justify-content: flex-end;
194
+ inset: -16px 0 auto;
195
+ }
196
+
197
+ .carefrees-form-item-extra {
198
+ box-sizing: border-box;
199
+ }
200
+
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@carefrees/form-utils-react-taro",
3
+ "author": "SunLxy <1011771396@qq.com>",
4
+ "description": "taro react 表单组件",
5
+ "homepage": "https://github.com/SunLxy/carefrees-form-utils",
6
+ "version": "0.0.4",
7
+ "main": "lib/index.js",
8
+ "types": "lib/index.d.ts",
9
+ "module": "esm/index.js",
10
+ "license": "ISC",
11
+ "scripts": {
12
+ "build": "carefrees-rslib build",
13
+ "watch": "carefrees-rslib build --watch"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "files": [
19
+ "src",
20
+ "lib",
21
+ "esm"
22
+ ],
23
+ "dependencies": {
24
+ "@carefrees/form-utils": "^0.0.4",
25
+ "classnames": "2.5.1"
26
+ },
27
+ "devDependencies": {
28
+ "@tarojs/components": "4.0.5",
29
+ "@types/react": "18.2.21",
30
+ "react": "^18.2.0"
31
+ }
32
+ }
@@ -0,0 +1,103 @@
1
+ import { LayoutFormItem, LayoutFormItemProps } from './../layout/layout.formItem';
2
+ import { useFormItemAttr, FormItemAttrOptions } from '../hooks/attr/attr.FormItem';
3
+ import { FormItemParentNameProvider } from '../hooks/useFormItemParentName';
4
+ import { useRegisterFormHideItem } from '../hooks/register/register.FormHideItem';
5
+ import React, { Fragment, memo } from 'react';
6
+
7
+ export interface FormItemProps extends FormItemAttrOptions, LayoutFormItemProps {
8
+ /**不进行样式渲染*/
9
+ noStyle?: boolean;
10
+ }
11
+
12
+ /**表单项基础实例*/
13
+ const FormItemInstance = memo((props: FormItemProps) => {
14
+ const {
15
+ labelMode,
16
+ noStyle,
17
+ onlyRuleStyle,
18
+ label,
19
+ helpText,
20
+ extra,
21
+ errorLayout,
22
+ required,
23
+ showColon,
24
+ colSpan,
25
+ rowSpan,
26
+ ...rest
27
+ } = props;
28
+ const { children, ruleInstance, formItemInstance, htmlFor, validateResult } = useFormItemAttr({ ...rest });
29
+ if (noStyle) {
30
+ return (
31
+ <FormItemParentNameProvider name={formItemInstance.name} sort={formItemInstance.sort}>
32
+ {children}
33
+ </FormItemParentNameProvider>
34
+ );
35
+ }
36
+ return (
37
+ <FormItemParentNameProvider name={formItemInstance.name} sort={formItemInstance.sort}>
38
+ <LayoutFormItem
39
+ labelMode={labelMode}
40
+ onlyRuleStyle={onlyRuleStyle}
41
+ required={required || ruleInstance?.isRequired?.()}
42
+ label={label}
43
+ helpText={helpText}
44
+ extra={extra}
45
+ errorLayout={errorLayout}
46
+ showColon={showColon}
47
+ colSpan={colSpan}
48
+ rowSpan={rowSpan}
49
+ htmlFor={htmlFor}
50
+ validateResult={validateResult}
51
+ >
52
+ {children}
53
+ </LayoutFormItem>
54
+ </FormItemParentNameProvider>
55
+ );
56
+ });
57
+
58
+ /**表单项*/
59
+ export const FormItem = memo((props: Partial<FormItemProps>) => {
60
+ const { name } = props;
61
+ if (name) {
62
+ return <FormItemInstance {...props} name={name} />;
63
+ }
64
+ const {
65
+ labelMode,
66
+ onlyRuleStyle,
67
+ label,
68
+ helpText,
69
+ extra,
70
+ errorLayout,
71
+ required,
72
+ showColon,
73
+ colSpan,
74
+ rowSpan,
75
+ children,
76
+ } = props;
77
+ return (
78
+ <LayoutFormItem
79
+ labelMode={labelMode}
80
+ onlyRuleStyle={onlyRuleStyle}
81
+ required={required}
82
+ label={label}
83
+ helpText={helpText}
84
+ extra={extra}
85
+ errorLayout={errorLayout}
86
+ showColon={showColon}
87
+ colSpan={colSpan}
88
+ rowSpan={rowSpan}
89
+ >
90
+ {children}
91
+ </LayoutFormItem>
92
+ );
93
+ });
94
+
95
+ /**隐藏表单项*/
96
+ export const FormHideItem = memo((props: FormItemProps) => {
97
+ const { name, sort, isJoinParentField } = props;
98
+ const { isHide } = useRegisterFormHideItem({ name, sort: sort, isJoinParentField });
99
+ if (isHide) {
100
+ return <Fragment />;
101
+ }
102
+ return <FormItemInstance {...props} />;
103
+ });