@carefrees/form-utils-react-taro 0.0.11 → 0.0.12
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/assets/index.css +220 -0
- package/esm/formItem/index.js +17 -17
- package/esm/formList/index.js +11 -11
- package/esm/hooks/attr/attr.FormItem.js +8 -8
- package/esm/index.js +16 -16
- package/esm/layout/index.js +24 -24
- package/esm/layout/layout.formItem.js +28 -28
- package/esm/styles/index.css +2 -3
- package/lib/formItem/index.js +2 -2
- package/lib/formList/index.js +2 -2
- package/lib/layout/index.js +2 -2
- package/lib/styles/index.css +2 -3
- package/package.json +5 -4
- package/src/styles/index.css +2 -3
package/assets/index.css
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/* 表单 */
|
|
2
|
+
html.dark .carefrees-form {
|
|
3
|
+
--form-color: #e3e3e3;
|
|
4
|
+
--form-header-color: #e3e3e3;
|
|
5
|
+
--form-font-size: 14px;
|
|
6
|
+
--form-border-color: #e0e0e0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/* 表单 */
|
|
10
|
+
.carefrees-form {
|
|
11
|
+
--form-color: rgba(0, 0, 0, 0.88);
|
|
12
|
+
--form-header-color: #1d2129;
|
|
13
|
+
--form-font-size: 14px;
|
|
14
|
+
--form-border-color: #e0e0e0;
|
|
15
|
+
|
|
16
|
+
box-sizing: border-box;
|
|
17
|
+
font-size: var(--form-font-size);
|
|
18
|
+
color: var(--form-color, rgba(0, 0, 0, 0.88));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/* 布局 */
|
|
22
|
+
.carefrees-form-layout {
|
|
23
|
+
width: 100%;
|
|
24
|
+
box-sizing: border-box;
|
|
25
|
+
border-radius: 4px;
|
|
26
|
+
padding-bottom: 8px;
|
|
27
|
+
position: relative;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.carefrees-form-layout.all-colspan {
|
|
31
|
+
grid-column: 1 / -1;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.carefrees-form-layout.bordered {
|
|
35
|
+
border: 1px solid var(--form-border-color, #e0e0e0);
|
|
36
|
+
}
|
|
37
|
+
.carefrees-form-layout.bordered .carefrees-form-layout-header {
|
|
38
|
+
padding-inline-start: 8px;
|
|
39
|
+
padding-inline-end: 8px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.carefrees-form-layout-header {
|
|
43
|
+
display: flex;
|
|
44
|
+
justify-content: space-between;
|
|
45
|
+
align-items: center;
|
|
46
|
+
flex-direction: row;
|
|
47
|
+
border-bottom: 1px solid var(--form-border-color, #e0e0e0);
|
|
48
|
+
padding-top: 5px;
|
|
49
|
+
padding-bottom: 5px;
|
|
50
|
+
margin-block-end: 4px;
|
|
51
|
+
padding-inline-start: 2px;
|
|
52
|
+
padding-inline-end: 2px;
|
|
53
|
+
box-sizing: border-box;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.carefrees-form-layout-header-title {
|
|
57
|
+
font-size: 14px;
|
|
58
|
+
font-weight: 600;
|
|
59
|
+
color: var(--form-header-color, #1d2129);
|
|
60
|
+
box-sizing: border-box;
|
|
61
|
+
}
|
|
62
|
+
.carefrees-form-layout-header-extra {
|
|
63
|
+
font-size: 14px;
|
|
64
|
+
font-weight: 500;
|
|
65
|
+
color: var(--form-header-color, #1d2129);
|
|
66
|
+
box-sizing: border-box;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.carefrees-form-layout-body {
|
|
70
|
+
width: 100%;
|
|
71
|
+
display: grid;
|
|
72
|
+
grid-template-columns: repeat(1, auto);
|
|
73
|
+
gap: 2px;
|
|
74
|
+
padding-left: 2px;
|
|
75
|
+
padding-right: 2px;
|
|
76
|
+
box-sizing: border-box;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* 表单项 */
|
|
80
|
+
.carefrees-form-item {
|
|
81
|
+
font-size: 14px;
|
|
82
|
+
display: flex;
|
|
83
|
+
flex-direction: row;
|
|
84
|
+
align-items: flex-start;
|
|
85
|
+
padding: 8px;
|
|
86
|
+
box-sizing: border-box;
|
|
87
|
+
color: var(--form-header-color, #1d2129);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.carefrees-form-item-container {
|
|
91
|
+
flex: 1;
|
|
92
|
+
height: 100%;
|
|
93
|
+
display: flex;
|
|
94
|
+
flex-direction: column;
|
|
95
|
+
gap: 4px;
|
|
96
|
+
box-sizing: border-box;
|
|
97
|
+
}
|
|
98
|
+
.carefrees-form-item-container.left {
|
|
99
|
+
flex-direction: row;
|
|
100
|
+
gap: 8px;
|
|
101
|
+
}
|
|
102
|
+
.carefrees-form-item-container.left .carefrees-form-item-label-warp {
|
|
103
|
+
text-align: right;
|
|
104
|
+
}
|
|
105
|
+
.carefrees-form-item-container.between {
|
|
106
|
+
gap: 8px;
|
|
107
|
+
text-align: left;
|
|
108
|
+
flex-direction: row;
|
|
109
|
+
justify-content: space-between;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.carefrees-form-item-container.between .carefrees-form-item-body,
|
|
113
|
+
.carefrees-form-item-container.between .carefrees-form-item-body-input {
|
|
114
|
+
justify-content: flex-end;
|
|
115
|
+
text-align: right;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.carefrees-form-item-label-warp {
|
|
119
|
+
box-sizing: border-box;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.carefrees-form-item-label {
|
|
123
|
+
box-sizing: border-box;
|
|
124
|
+
display: flex;
|
|
125
|
+
align-items: center;
|
|
126
|
+
justify-content: flex-start;
|
|
127
|
+
position: relative;
|
|
128
|
+
font-size: 14px;
|
|
129
|
+
color: var(--form-header-color, #1d2129);
|
|
130
|
+
min-height: 1.4rem;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.carefrees-form-item-label.show-colon::after {
|
|
134
|
+
content: ':';
|
|
135
|
+
display: inline-block;
|
|
136
|
+
text-align: center;
|
|
137
|
+
margin: 0;
|
|
138
|
+
margin-inline-end: 2px;
|
|
139
|
+
margin-inline-start: 2px;
|
|
140
|
+
box-sizing: border-box;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.carefrees-form-item-label.required::before {
|
|
144
|
+
content: '*';
|
|
145
|
+
color: red;
|
|
146
|
+
display: inline-block;
|
|
147
|
+
margin-inline-end: 4px;
|
|
148
|
+
box-sizing: border-box;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.carefrees-form-item-body {
|
|
152
|
+
position: relative;
|
|
153
|
+
display: flex;
|
|
154
|
+
flex-direction: column;
|
|
155
|
+
align-items: flex-start;
|
|
156
|
+
justify-content: flex-start;
|
|
157
|
+
box-sizing: border-box;
|
|
158
|
+
gap: 4px;
|
|
159
|
+
flex: 1;
|
|
160
|
+
}
|
|
161
|
+
.carefrees-form-item-body-input {
|
|
162
|
+
box-sizing: border-box;
|
|
163
|
+
width: 100%;
|
|
164
|
+
flex: 1;
|
|
165
|
+
display: flex;
|
|
166
|
+
justify-content: flex-start;
|
|
167
|
+
align-items: center;
|
|
168
|
+
flex-direction: row;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.carefrees-form-item-body-input.input-bordered {
|
|
172
|
+
border-bottom: 1px solid var(--form-border-color, #e0e0e0);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.carefrees-form-item-body-help {
|
|
176
|
+
width: 100%;
|
|
177
|
+
box-sizing: border-box;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.carefrees-form-item-body-error {
|
|
181
|
+
position: absolute;
|
|
182
|
+
width: 100%;
|
|
183
|
+
color: red;
|
|
184
|
+
top: auto;
|
|
185
|
+
left: 0;
|
|
186
|
+
right: 0;
|
|
187
|
+
bottom: -16px;
|
|
188
|
+
padding-top: 2px;
|
|
189
|
+
font-size: 12px;
|
|
190
|
+
box-sizing: border-box;
|
|
191
|
+
z-index: 10;
|
|
192
|
+
pointer-events: none;
|
|
193
|
+
display: flex;
|
|
194
|
+
flex-direction: row;
|
|
195
|
+
justify-content: start;
|
|
196
|
+
}
|
|
197
|
+
.carefrees-form-item-body-error.right-bottom {
|
|
198
|
+
justify-content: flex-end;
|
|
199
|
+
top: auto;
|
|
200
|
+
left: 0;
|
|
201
|
+
right: 0;
|
|
202
|
+
bottom: -16px;
|
|
203
|
+
}
|
|
204
|
+
.carefrees-form-item-body-error.top-left {
|
|
205
|
+
justify-content: start;
|
|
206
|
+
top: -16px;
|
|
207
|
+
left: 0px;
|
|
208
|
+
right: 0px;
|
|
209
|
+
bottom: auto;
|
|
210
|
+
}
|
|
211
|
+
.carefrees-form-item-body-error.top-right {
|
|
212
|
+
justify-content: flex-end;
|
|
213
|
+
top: -16px;
|
|
214
|
+
left: 0px;
|
|
215
|
+
right: 0px;
|
|
216
|
+
bottom: auto;
|
|
217
|
+
}
|
|
218
|
+
.carefrees-form-item-extra {
|
|
219
|
+
box-sizing: border-box;
|
|
220
|
+
}
|
package/esm/formItem/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
const FormItemInstance = /*#__PURE__*/
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { LayoutFormItem } from "../layout/layout.formItem.js";
|
|
3
|
+
import { useFormItemAttr } from "../hooks/attr/attr.FormItem.js";
|
|
4
|
+
import { Fragment, memo } from "react";
|
|
5
|
+
import { FormItemParentNameProvider, useRegisterFormHideItem } from "@carefrees/form-utils-react-hooks";
|
|
6
|
+
const FormItemInstance = /*#__PURE__*/ memo((props)=>{
|
|
7
7
|
const { labelMode, noStyle, onlyRuleStyle, label, helpText, extra, errorLayout, required, showColon, colSpan, rowSpan, ...rest } = props;
|
|
8
|
-
const { children, ruleInstance, formItemInstance, htmlFor, validateResult } =
|
|
8
|
+
const { children, ruleInstance, formItemInstance, htmlFor, validateResult } = useFormItemAttr({
|
|
9
9
|
...rest
|
|
10
10
|
});
|
|
11
|
-
if (noStyle) return /*#__PURE__*/
|
|
11
|
+
if (noStyle) return /*#__PURE__*/ jsx(FormItemParentNameProvider, {
|
|
12
12
|
name: formItemInstance.name,
|
|
13
13
|
sort: formItemInstance.sort,
|
|
14
14
|
children: children
|
|
15
15
|
});
|
|
16
|
-
return /*#__PURE__*/
|
|
16
|
+
return /*#__PURE__*/ jsx(FormItemParentNameProvider, {
|
|
17
17
|
name: formItemInstance.name,
|
|
18
18
|
sort: formItemInstance.sort,
|
|
19
|
-
children: /*#__PURE__*/
|
|
19
|
+
children: /*#__PURE__*/ jsx(LayoutFormItem, {
|
|
20
20
|
labelMode: labelMode,
|
|
21
21
|
onlyRuleStyle: onlyRuleStyle,
|
|
22
22
|
required: required || ruleInstance?.isRequired?.(),
|
|
@@ -33,14 +33,14 @@ const FormItemInstance = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.mem
|
|
|
33
33
|
})
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
|
-
const FormItem = /*#__PURE__*/
|
|
36
|
+
const FormItem = /*#__PURE__*/ memo((props)=>{
|
|
37
37
|
const { name } = props;
|
|
38
|
-
if (name) return /*#__PURE__*/
|
|
38
|
+
if (name) return /*#__PURE__*/ jsx(FormItemInstance, {
|
|
39
39
|
...props,
|
|
40
40
|
name: name
|
|
41
41
|
});
|
|
42
42
|
const { labelMode, onlyRuleStyle, label, helpText, extra, errorLayout, required, showColon, colSpan, rowSpan, children } = props;
|
|
43
|
-
return /*#__PURE__*/
|
|
43
|
+
return /*#__PURE__*/ jsx(LayoutFormItem, {
|
|
44
44
|
labelMode: labelMode,
|
|
45
45
|
onlyRuleStyle: onlyRuleStyle,
|
|
46
46
|
required: required,
|
|
@@ -54,15 +54,15 @@ const FormItem = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)((prop
|
|
|
54
54
|
children: children
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
|
-
const FormHideItem = /*#__PURE__*/
|
|
57
|
+
const FormHideItem = /*#__PURE__*/ memo((props)=>{
|
|
58
58
|
const { name, sort, isJoinParentField } = props;
|
|
59
|
-
const { isHide } =
|
|
59
|
+
const { isHide } = useRegisterFormHideItem({
|
|
60
60
|
name,
|
|
61
61
|
sort: sort,
|
|
62
62
|
isJoinParentField
|
|
63
63
|
});
|
|
64
|
-
if (isHide) return /*#__PURE__*/
|
|
65
|
-
return /*#__PURE__*/
|
|
64
|
+
if (isHide) return /*#__PURE__*/ jsx(Fragment, {});
|
|
65
|
+
return /*#__PURE__*/ jsx(FormItemInstance, {
|
|
66
66
|
...props
|
|
67
67
|
});
|
|
68
68
|
});
|
package/esm/formList/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
const FormList = /*#__PURE__*/
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, memo } from "react";
|
|
3
|
+
import { FormItemParentNameProvider, FormListInstanceContext, useRegisterFormHideItem, useRegisterFormList } from "@carefrees/form-utils-react-hooks";
|
|
4
|
+
const FormList = /*#__PURE__*/ memo((props)=>{
|
|
5
5
|
const { children, ...rest } = props;
|
|
6
|
-
const { formListInstance, ruleInstance, formItemInstance } =
|
|
7
|
-
return /*#__PURE__*/
|
|
6
|
+
const { formListInstance, ruleInstance, formItemInstance } = useRegisterFormList(rest);
|
|
7
|
+
return /*#__PURE__*/ jsx(FormListInstanceContext.Provider, {
|
|
8
8
|
value: formListInstance,
|
|
9
|
-
children: /*#__PURE__*/
|
|
9
|
+
children: /*#__PURE__*/ jsx(FormItemParentNameProvider, {
|
|
10
10
|
name: formListInstance.name,
|
|
11
11
|
sort: formListInstance.sort,
|
|
12
12
|
children: children({
|
|
@@ -22,15 +22,15 @@ const FormList = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)((prop
|
|
|
22
22
|
})
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
|
-
const FormHideList = /*#__PURE__*/
|
|
25
|
+
const FormHideList = /*#__PURE__*/ memo((props)=>{
|
|
26
26
|
const { name, sort, isJoinParentField } = props;
|
|
27
|
-
const { isHide } =
|
|
27
|
+
const { isHide } = useRegisterFormHideItem({
|
|
28
28
|
name,
|
|
29
29
|
sort: sort,
|
|
30
30
|
isJoinParentField
|
|
31
31
|
});
|
|
32
|
-
if (isHide) return /*#__PURE__*/
|
|
33
|
-
return /*#__PURE__*/
|
|
32
|
+
if (isHide) return /*#__PURE__*/ jsx(Fragment, {});
|
|
33
|
+
return /*#__PURE__*/ jsx(FormList, {
|
|
34
34
|
...props
|
|
35
35
|
});
|
|
36
36
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { get } from "@carefrees/form-utils";
|
|
2
|
+
import { useHtmlFor, useRegisterFormItem } from "@carefrees/form-utils-react-hooks";
|
|
3
|
+
import { cloneElement, isValidElement, useMemo } from "react";
|
|
4
4
|
const useFormItemAttr = (options)=>{
|
|
5
5
|
const { trigger = 'onChange', dependencies, noticeOnlyRuleDataField, isNoticeParentField, noticeWatchField, preserve, valuePropName = 'value', getValuePath = valuePropName, getValueFromEvent, formatValue, onAfterUpdate, useAttrs, useRules, attrs, children, ...rest } = options;
|
|
6
|
-
const { formItemInstance, form, ruleInstance, newName } =
|
|
6
|
+
const { formItemInstance, form, ruleInstance, newName } = useRegisterFormItem({
|
|
7
7
|
...rest
|
|
8
8
|
});
|
|
9
9
|
formItemInstance.dependencies = dependencies;
|
|
@@ -18,7 +18,7 @@ const useFormItemAttr = (options)=>{
|
|
|
18
18
|
let value = event;
|
|
19
19
|
const target = event?.detail || event?.target;
|
|
20
20
|
if ('function' == typeof getValueFromEvent) value = getValueFromEvent(event, form, formItemInstance);
|
|
21
|
-
else if (event && target && 'object' == typeof target && getValuePath in target) value =
|
|
21
|
+
else if (event && target && 'object' == typeof target && getValuePath in target) value = get(target, getValuePath);
|
|
22
22
|
if ('function' == typeof formatValue) value = formatValue(value, form, formItemInstance, event);
|
|
23
23
|
if (oldValue !== value) {
|
|
24
24
|
form.updatedFieldValue(newName, value, 'validate');
|
|
@@ -32,7 +32,7 @@ const useFormItemAttr = (options)=>{
|
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
formItemInstance.onChange = onValueChange;
|
|
35
|
-
const htmlFor =
|
|
35
|
+
const htmlFor = useHtmlFor(newName);
|
|
36
36
|
formItemInstance.htmlFor = htmlFor;
|
|
37
37
|
const control = {
|
|
38
38
|
[trigger]: onValueChange,
|
|
@@ -44,11 +44,11 @@ const useFormItemAttr = (options)=>{
|
|
|
44
44
|
const newControl = useAttrs?.(control, form, formItemInstance) || control;
|
|
45
45
|
formItemInstance.control = newControl;
|
|
46
46
|
useRules?.(ruleInstance, form, formItemInstance);
|
|
47
|
-
const validateResult =
|
|
47
|
+
const validateResult = useMemo(()=>ruleInstance.getValidateResult(), [
|
|
48
48
|
ruleInstance.messages
|
|
49
49
|
]);
|
|
50
50
|
return {
|
|
51
|
-
children: /*#__PURE__*/
|
|
51
|
+
children: /*#__PURE__*/ isValidElement(children) ? /*#__PURE__*/ cloneElement(children, newControl) : children,
|
|
52
52
|
form,
|
|
53
53
|
formItemInstance,
|
|
54
54
|
ruleInstance,
|
package/esm/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo } from "react";
|
|
3
|
+
import classnames from "classnames";
|
|
4
|
+
import { FormLayout } from "./layout/index.js";
|
|
5
|
+
import { FormInstanceContext, useForm, useRegisterForm } from "@carefrees/form-utils-react-hooks";
|
|
6
|
+
import { Form } from "@tarojs/components";
|
|
7
7
|
import "./styles/index.css";
|
|
8
8
|
export * from "./formItem/index.js";
|
|
9
9
|
export * from "./formList/index.js";
|
|
@@ -11,16 +11,16 @@ export * from "./layout/index.js";
|
|
|
11
11
|
export * from "./layout/layout.formItem.js";
|
|
12
12
|
export * from "./hooks/attr/attr.FormItem.js";
|
|
13
13
|
export * from "@carefrees/form-utils-react-hooks";
|
|
14
|
-
function
|
|
14
|
+
function src_Form(props) {
|
|
15
15
|
const { children, form, style, className, formData, hideData, hideRuleData, isAutoUpdatedFormData = false, name, onFinish, onFinishFailed, onValuesChange, layoutStyle, layoutClassName, ...rest } = props;
|
|
16
|
-
const formInstance =
|
|
17
|
-
|
|
18
|
-
const cls =
|
|
19
|
-
|
|
16
|
+
const formInstance = useForm(form);
|
|
17
|
+
useRegisterForm(formInstance, name);
|
|
18
|
+
const cls = useMemo(()=>classnames('carefrees-form', className), []);
|
|
19
|
+
useMemo(()=>formInstance.ctor(formData, hideData, hideRuleData), []);
|
|
20
20
|
formInstance.onFinish = onFinish;
|
|
21
21
|
formInstance.onValuesChange = onValuesChange;
|
|
22
22
|
formInstance.onFinishFailed = onFinishFailed;
|
|
23
|
-
|
|
23
|
+
useEffect(()=>{
|
|
24
24
|
if (isAutoUpdatedFormData) formInstance.resetFormValues(formData);
|
|
25
25
|
}, [
|
|
26
26
|
isAutoUpdatedFormData,
|
|
@@ -31,13 +31,13 @@ function Form(props) {
|
|
|
31
31
|
event?.stopPropagation?.();
|
|
32
32
|
formInstance.submit();
|
|
33
33
|
};
|
|
34
|
-
return /*#__PURE__*/
|
|
34
|
+
return /*#__PURE__*/ jsx(FormInstanceContext.Provider, {
|
|
35
35
|
value: formInstance,
|
|
36
|
-
children: /*#__PURE__*/
|
|
36
|
+
children: /*#__PURE__*/ jsx(Form, {
|
|
37
37
|
className: cls,
|
|
38
38
|
style: style,
|
|
39
39
|
onSubmit: onSubmit,
|
|
40
|
-
children: /*#__PURE__*/
|
|
40
|
+
children: /*#__PURE__*/ jsx(FormLayout, {
|
|
41
41
|
...rest,
|
|
42
42
|
className: layoutClassName,
|
|
43
43
|
style: layoutStyle,
|
|
@@ -46,4 +46,4 @@ function Form(props) {
|
|
|
46
46
|
})
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
export { Form };
|
|
49
|
+
export { src_Form as Form };
|
package/esm/layout/index.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, memo, useMemo, useRef } from "react";
|
|
3
|
+
import { View } from "@tarojs/components";
|
|
4
|
+
import classnames from "classnames";
|
|
5
|
+
import { AttrsContext, useAttrs } from "@carefrees/form-utils-react-hooks";
|
|
6
6
|
const preCls = 'carefrees-form-layout';
|
|
7
|
-
const FormLayout = /*#__PURE__*/
|
|
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 } =
|
|
7
|
+
const FormLayout = /*#__PURE__*/ 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 } = useAttrs();
|
|
9
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 =
|
|
10
|
+
const propsRef = useRef(props);
|
|
11
11
|
propsRef.current = props;
|
|
12
|
-
const cls =
|
|
12
|
+
const cls = useMemo(()=>classnames(preCls, className, {
|
|
13
13
|
'all-colspan': isAllColSpan,
|
|
14
14
|
bordered: bordered
|
|
15
15
|
}), [
|
|
16
16
|
className
|
|
17
17
|
]);
|
|
18
|
-
const bodyCls =
|
|
18
|
+
const bodyCls = useMemo(()=>classnames(`${preCls}-body`, bodyClassName), [
|
|
19
19
|
bodyClassName
|
|
20
20
|
]);
|
|
21
|
-
const headerCls =
|
|
21
|
+
const headerCls = useMemo(()=>classnames(`${preCls}-header`, headerClassName), [
|
|
22
22
|
headerClassName
|
|
23
23
|
]);
|
|
24
|
-
const headerTitleCls =
|
|
25
|
-
const headerExtraCls =
|
|
26
|
-
const value =
|
|
24
|
+
const headerTitleCls = useMemo(()=>classnames(`${preCls}-header-title`), []);
|
|
25
|
+
const headerExtraCls = useMemo(()=>classnames(`${preCls}-header-extra`), []);
|
|
26
|
+
const value = useMemo(()=>({
|
|
27
27
|
colCount,
|
|
28
28
|
errorLayout,
|
|
29
29
|
labelMode,
|
|
@@ -42,7 +42,7 @@ const FormLayout = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)((pr
|
|
|
42
42
|
formItemLabelClassName,
|
|
43
43
|
formItemLabelStyle
|
|
44
44
|
]);
|
|
45
|
-
const styleBase =
|
|
45
|
+
const styleBase = useMemo(()=>{
|
|
46
46
|
const css = {};
|
|
47
47
|
if ('string' == typeof gap) css.gap = gap;
|
|
48
48
|
if ('number' == typeof gap) css.gap = `${gap}px`;
|
|
@@ -52,27 +52,27 @@ const FormLayout = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)((pr
|
|
|
52
52
|
colCount,
|
|
53
53
|
gap
|
|
54
54
|
]);
|
|
55
|
-
return /*#__PURE__*/
|
|
55
|
+
return /*#__PURE__*/ jsx(AttrsContext.Provider, {
|
|
56
56
|
value: value,
|
|
57
|
-
children: /*#__PURE__*/
|
|
57
|
+
children: /*#__PURE__*/ jsxs(View, {
|
|
58
58
|
style: style,
|
|
59
59
|
className: cls,
|
|
60
60
|
children: [
|
|
61
|
-
title || extra ? /*#__PURE__*/
|
|
61
|
+
title || extra ? /*#__PURE__*/ jsxs(View, {
|
|
62
62
|
style: headerStyle,
|
|
63
63
|
className: headerCls,
|
|
64
64
|
children: [
|
|
65
|
-
/*#__PURE__*/
|
|
65
|
+
/*#__PURE__*/ jsx(View, {
|
|
66
66
|
className: headerTitleCls,
|
|
67
67
|
children: title
|
|
68
68
|
}),
|
|
69
|
-
/*#__PURE__*/
|
|
69
|
+
/*#__PURE__*/ jsx(View, {
|
|
70
70
|
className: headerExtraCls,
|
|
71
71
|
children: extra
|
|
72
72
|
})
|
|
73
73
|
]
|
|
74
|
-
}) : /*#__PURE__*/
|
|
75
|
-
/*#__PURE__*/
|
|
74
|
+
}) : /*#__PURE__*/ jsx(Fragment, {}),
|
|
75
|
+
/*#__PURE__*/ jsx(View, {
|
|
76
76
|
style: {
|
|
77
77
|
...styleBase,
|
|
78
78
|
...bodyStyle
|
|
@@ -86,12 +86,12 @@ const FormLayout = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)((pr
|
|
|
86
86
|
});
|
|
87
87
|
const FormLayoutRows = (props)=>{
|
|
88
88
|
const { className } = props;
|
|
89
|
-
const cls =
|
|
89
|
+
const cls = useMemo(()=>classnames(preCls, className, {
|
|
90
90
|
'all-colspan': true
|
|
91
91
|
}), [
|
|
92
92
|
className
|
|
93
93
|
]);
|
|
94
|
-
return /*#__PURE__*/
|
|
94
|
+
return /*#__PURE__*/ jsx(View, {
|
|
95
95
|
...props,
|
|
96
96
|
className: cls
|
|
97
97
|
});
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Label, View } from "@tarojs/components";
|
|
3
|
+
import { Fragment, memo, useMemo } from "react";
|
|
4
|
+
import classnames from "classnames";
|
|
5
|
+
import { useAttrs } from "@carefrees/form-utils-react-hooks";
|
|
6
6
|
const preCls = 'carefrees-form-item';
|
|
7
|
-
const LayoutFormItem = /*#__PURE__*/
|
|
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 } =
|
|
7
|
+
const LayoutFormItem = /*#__PURE__*/ 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 } = useAttrs();
|
|
9
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
10
|
const tip = validateResult?.tip;
|
|
11
11
|
const isInvalid = !!validateResult?.isInvalid;
|
|
12
12
|
const _errorLayout = 'between' === labelMode ? 'right-bottom' : errorLayout;
|
|
13
|
-
const cls =
|
|
13
|
+
const cls = useMemo(()=>classnames(preCls, className, formItemClassName, {
|
|
14
14
|
'dx-invalid': isInvalid
|
|
15
15
|
}), [
|
|
16
16
|
isInvalid
|
|
17
17
|
]);
|
|
18
|
-
const containerCls =
|
|
18
|
+
const containerCls = useMemo(()=>classnames(`${preCls}-container`, {
|
|
19
19
|
[`${labelMode}`]: !!labelMode
|
|
20
20
|
}), [
|
|
21
21
|
labelMode
|
|
22
22
|
]);
|
|
23
|
-
const labelCls =
|
|
23
|
+
const labelCls = useMemo(()=>classnames(`${preCls}-label`, {
|
|
24
24
|
required: required,
|
|
25
25
|
'show-colon': showColon && ('left' === labelMode || 'between' === labelMode)
|
|
26
26
|
}), [
|
|
@@ -28,25 +28,25 @@ const LayoutFormItem = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)
|
|
|
28
28
|
required,
|
|
29
29
|
showColon
|
|
30
30
|
]);
|
|
31
|
-
const labelWarpCls =
|
|
31
|
+
const labelWarpCls = useMemo(()=>classnames(`${preCls}-label-warp`, labelClassName, formItemLabelClassName), [
|
|
32
32
|
labelClassName,
|
|
33
33
|
formItemLabelClassName
|
|
34
34
|
]);
|
|
35
|
-
const inputCls =
|
|
35
|
+
const inputCls = useMemo(()=>classnames(`${preCls}-body-input`, {
|
|
36
36
|
'input-bordered': inputBordered
|
|
37
37
|
}), [
|
|
38
38
|
inputBordered
|
|
39
39
|
]);
|
|
40
|
-
const errorCls =
|
|
40
|
+
const errorCls = useMemo(()=>classnames(`${preCls}-body-error`, {
|
|
41
41
|
[_errorLayout]: !!_errorLayout
|
|
42
42
|
}), [
|
|
43
43
|
_errorLayout
|
|
44
44
|
]);
|
|
45
|
-
const _isLabel =
|
|
45
|
+
const _isLabel = useMemo(()=>label && 'hide' !== labelMode, [
|
|
46
46
|
label,
|
|
47
47
|
labelMode
|
|
48
48
|
]);
|
|
49
|
-
const styleBase =
|
|
49
|
+
const styleBase = useMemo(()=>{
|
|
50
50
|
const css = {};
|
|
51
51
|
if (onlyRuleStyle) css.padding = '0px';
|
|
52
52
|
if (colSpan) {
|
|
@@ -61,7 +61,7 @@ const LayoutFormItem = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)
|
|
|
61
61
|
rowSpan,
|
|
62
62
|
colCount
|
|
63
63
|
]);
|
|
64
|
-
return /*#__PURE__*/
|
|
64
|
+
return /*#__PURE__*/ jsxs(View, {
|
|
65
65
|
style: {
|
|
66
66
|
...formItemStyle,
|
|
67
67
|
...styleBase,
|
|
@@ -69,44 +69,44 @@ const LayoutFormItem = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.memo)
|
|
|
69
69
|
},
|
|
70
70
|
className: cls,
|
|
71
71
|
children: [
|
|
72
|
-
/*#__PURE__*/
|
|
72
|
+
/*#__PURE__*/ jsxs(View, {
|
|
73
73
|
className: containerCls,
|
|
74
74
|
children: [
|
|
75
|
-
_isLabel ? /*#__PURE__*/
|
|
75
|
+
_isLabel ? /*#__PURE__*/ jsx(View, {
|
|
76
76
|
style: {
|
|
77
77
|
...formItemLabelStyle,
|
|
78
78
|
...labelStyle
|
|
79
79
|
},
|
|
80
80
|
className: labelWarpCls,
|
|
81
|
-
children: /*#__PURE__*/
|
|
81
|
+
children: /*#__PURE__*/ jsx(Label, {
|
|
82
82
|
for: htmlFor,
|
|
83
83
|
className: labelCls,
|
|
84
84
|
children: label
|
|
85
85
|
})
|
|
86
|
-
}) : /*#__PURE__*/
|
|
87
|
-
/*#__PURE__*/
|
|
86
|
+
}) : /*#__PURE__*/ jsx(Fragment, {}),
|
|
87
|
+
/*#__PURE__*/ jsxs(View, {
|
|
88
88
|
className: `${preCls}-body`,
|
|
89
89
|
children: [
|
|
90
|
-
/*#__PURE__*/
|
|
90
|
+
/*#__PURE__*/ jsx(View, {
|
|
91
91
|
className: inputCls,
|
|
92
92
|
children: children
|
|
93
93
|
}),
|
|
94
|
-
helpText ? /*#__PURE__*/
|
|
94
|
+
helpText ? /*#__PURE__*/ jsx(View, {
|
|
95
95
|
className: `${preCls}-body-help`,
|
|
96
96
|
children: helpText
|
|
97
|
-
}) : /*#__PURE__*/
|
|
98
|
-
isInvalid ? /*#__PURE__*/
|
|
97
|
+
}) : /*#__PURE__*/ jsx(Fragment, {}),
|
|
98
|
+
isInvalid ? /*#__PURE__*/ jsx(View, {
|
|
99
99
|
className: errorCls,
|
|
100
100
|
children: tip
|
|
101
|
-
}) : /*#__PURE__*/
|
|
101
|
+
}) : /*#__PURE__*/ jsx(Fragment, {})
|
|
102
102
|
]
|
|
103
103
|
})
|
|
104
104
|
]
|
|
105
105
|
}),
|
|
106
|
-
extra ? /*#__PURE__*/
|
|
106
|
+
extra ? /*#__PURE__*/ jsx(View, {
|
|
107
107
|
className: `${preCls}-extra`,
|
|
108
108
|
children: extra
|
|
109
|
-
}) : /*#__PURE__*/
|
|
109
|
+
}) : /*#__PURE__*/ jsx(Fragment, {})
|
|
110
110
|
]
|
|
111
111
|
});
|
|
112
112
|
});
|
package/esm/styles/index.css
CHANGED
|
@@ -81,13 +81,12 @@
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
.carefrees-form-item-container.left {
|
|
84
|
-
text-align: left;
|
|
85
84
|
flex-direction: row;
|
|
86
85
|
gap: 8px;
|
|
87
86
|
}
|
|
88
87
|
|
|
89
|
-
.carefrees-form-item-container.left .carefrees-form-item-label {
|
|
90
|
-
|
|
88
|
+
.carefrees-form-item-container.left .carefrees-form-item-label-warp {
|
|
89
|
+
text-align: right;
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
.carefrees-form-item-container.between {
|
package/lib/formItem/index.js
CHANGED
|
@@ -24,8 +24,8 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
FormHideItem: ()=>FormHideItem,
|
|
28
|
+
FormItem: ()=>FormItem
|
|
29
29
|
});
|
|
30
30
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
31
31
|
const layout_formItem_js_namespaceObject = require("../layout/layout.formItem.js");
|
package/lib/formList/index.js
CHANGED
|
@@ -24,8 +24,8 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
FormList: ()=>FormList,
|
|
28
|
+
FormHideList: ()=>FormHideList
|
|
29
29
|
});
|
|
30
30
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
31
31
|
const external_react_namespaceObject = require("react");
|
package/lib/layout/index.js
CHANGED
|
@@ -33,8 +33,8 @@ var __webpack_require__ = {};
|
|
|
33
33
|
var __webpack_exports__ = {};
|
|
34
34
|
__webpack_require__.r(__webpack_exports__);
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
FormLayoutRows: ()=>FormLayoutRows,
|
|
37
|
+
FormLayout: ()=>FormLayout
|
|
38
38
|
});
|
|
39
39
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
40
40
|
const external_react_namespaceObject = require("react");
|
package/lib/styles/index.css
CHANGED
|
@@ -81,13 +81,12 @@
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
.carefrees-form-item-container.left {
|
|
84
|
-
text-align: left;
|
|
85
84
|
flex-direction: row;
|
|
86
85
|
gap: 8px;
|
|
87
86
|
}
|
|
88
87
|
|
|
89
|
-
.carefrees-form-item-container.left .carefrees-form-item-label {
|
|
90
|
-
|
|
88
|
+
.carefrees-form-item-container.left .carefrees-form-item-label-warp {
|
|
89
|
+
text-align: right;
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
.carefrees-form-item-container.between {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "SunLxy <1011771396@qq.com>",
|
|
4
4
|
"description": "taro react 表单组件",
|
|
5
5
|
"homepage": "https://github.com/SunLxy/carefrees-form-utils",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.12",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"types": "lib/index.d.ts",
|
|
9
9
|
"module": "esm/index.js",
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"src",
|
|
20
20
|
"lib",
|
|
21
|
-
"esm"
|
|
21
|
+
"esm",
|
|
22
|
+
"assets"
|
|
22
23
|
],
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@carefrees/form-utils": "^0.0.
|
|
25
|
-
"@carefrees/form-utils-react-hooks": "^0.0.
|
|
25
|
+
"@carefrees/form-utils": "^0.0.12",
|
|
26
|
+
"@carefrees/form-utils-react-hooks": "^0.0.12",
|
|
26
27
|
"classnames": "2.5.1"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
package/src/styles/index.css
CHANGED
|
@@ -85,10 +85,9 @@
|
|
|
85
85
|
.carefrees-form-item-container.left {
|
|
86
86
|
flex-direction: row;
|
|
87
87
|
gap: 8px;
|
|
88
|
-
text-align: left;
|
|
89
88
|
}
|
|
90
|
-
.carefrees-form-item-container.left .carefrees-form-item-label {
|
|
91
|
-
|
|
89
|
+
.carefrees-form-item-container.left .carefrees-form-item-label-warp {
|
|
90
|
+
text-align: right;
|
|
92
91
|
}
|
|
93
92
|
.carefrees-form-item-container.between {
|
|
94
93
|
gap: 8px;
|