@hw-component/form 1.8.1 → 1.8.2
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/.eslintcache +1 -1
- package/.stylelintrc.js +6 -2
- package/es/Form/Basic.d.ts +1 -1
- package/es/Form/Basic.js +4 -2
- package/es/Form/index.d.ts +1 -1
- package/es/Form/index.js +3 -1
- package/es/Form/modal.d.ts +1 -0
- package/es/index.css +3 -3
- package/es/index.d.ts +1 -1
- package/lib/Form/Basic.d.ts +1 -1
- package/lib/Form/Basic.js +4 -2
- package/lib/Form/index.d.ts +1 -1
- package/lib/Form/index.js +3 -1
- package/lib/Form/modal.d.ts +1 -0
- package/lib/index.css +3 -3
- package/lib/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/components/Form/Basic.tsx +55 -43
- package/src/components/Form/FormItem/BasicItem.tsx +7 -2
- package/src/components/Form/FormItem/hooks.tsx +3 -3
- package/src/components/Form/FormItem/index.tsx +13 -12
- package/src/components/Form/index.less +2 -2
- package/src/components/Form/index.tsx +15 -14
- package/src/components/Form/modal.ts +3 -2
- package/src/components/Input/InputNumberGroup.tsx +8 -8
- package/src/components/Input/index.less +4 -6
- package/src/components/Select/hooks/changeHooks.tsx +31 -29
- package/src/components/Select/hooks/norHooks.ts +1 -1
- package/src/components/index.tsx +1 -1
- package/src/pages/Form/index.tsx +58 -85
- package/src/pages/Input/index.tsx +7 -5
- package/src/pages/Select/index.tsx +12 -12
|
@@ -13,26 +13,27 @@ export const useValueChange = (params: PartialHSelectProps) => {
|
|
|
13
13
|
fieldNames = {},
|
|
14
14
|
} = params;
|
|
15
15
|
const [val, setVal] = useState<any>();
|
|
16
|
-
const labelInValueItemMaker=(changeVal)=>{
|
|
17
|
-
const {value:fieldValue="value",label:fieldLabel="label"}=
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
[
|
|
22
|
-
|
|
16
|
+
const labelInValueItemMaker = (changeVal) => {
|
|
17
|
+
const { value: fieldValue = "value", label: fieldLabel = "label" } =
|
|
18
|
+
fieldNames;
|
|
19
|
+
const { label: changeLabel, value: changeValue, ...oVal } = changeVal;
|
|
20
|
+
return {
|
|
21
|
+
[fieldValue]: changeValue,
|
|
22
|
+
[fieldLabel]: changeLabel,
|
|
23
|
+
...oVal,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const labelInValueMaker = (changeVal) => {
|
|
27
|
+
if (!changeVal) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
if (!Array.isArray(changeVal)) {
|
|
31
|
+
return labelInValueItemMaker(changeVal);
|
|
23
32
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
if (!Array.isArray(changeVal)){
|
|
30
|
-
return labelInValueItemMaker(changeVal)
|
|
31
|
-
}
|
|
32
|
-
return changeVal.map((item)=>{
|
|
33
|
-
return labelInValueItemMaker(item)
|
|
34
|
-
})
|
|
35
|
-
}
|
|
33
|
+
return changeVal.map((item) => {
|
|
34
|
+
return labelInValueItemMaker(item);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
36
37
|
const change = (changeVal, itemOps) => {
|
|
37
38
|
if (!onChange) {
|
|
38
39
|
setVal(changeVal);
|
|
@@ -44,11 +45,11 @@ export const useValueChange = (params: PartialHSelectProps) => {
|
|
|
44
45
|
}
|
|
45
46
|
const subItemOps = itemOpProvider(itemOps, fieldNames);
|
|
46
47
|
if (labelInValue) {
|
|
47
|
-
onChange(labelInValueMaker(changeVal),itemOps);
|
|
48
|
+
onChange(labelInValueMaker(changeVal), itemOps);
|
|
48
49
|
return;
|
|
49
50
|
}
|
|
50
51
|
let newChangeVal = changeVal.value;
|
|
51
|
-
if (Array.isArray(changeVal)
|
|
52
|
+
if (Array.isArray(changeVal) && !labelInValue) {
|
|
52
53
|
newChangeVal = changeVal.map((item) => {
|
|
53
54
|
return item.value;
|
|
54
55
|
});
|
|
@@ -60,7 +61,7 @@ export const useValueChange = (params: PartialHSelectProps) => {
|
|
|
60
61
|
setVal(undefined);
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
|
-
if (mode === "tags"||labelInValue) {
|
|
64
|
+
if (mode === "tags" || labelInValue) {
|
|
64
65
|
setVal(value);
|
|
65
66
|
return;
|
|
66
67
|
}
|
|
@@ -73,13 +74,14 @@ export const useValueChange = (params: PartialHSelectProps) => {
|
|
|
73
74
|
}, [value, options, mode]);
|
|
74
75
|
const itemMaker = (item) => {
|
|
75
76
|
const { value: itemVal, label, noMatch } = item;
|
|
76
|
-
const {value:fieldValue="value",label:fieldLabel="label"}=
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
const { value: fieldValue = "value", label: fieldLabel = "label" } =
|
|
78
|
+
fieldNames;
|
|
79
|
+
if (labelInValue) {
|
|
80
|
+
const { [fieldValue]: changeVal, [fieldLabel]: changeLable } = item;
|
|
81
|
+
return {
|
|
82
|
+
value: changeVal,
|
|
83
|
+
label: changeLable,
|
|
84
|
+
};
|
|
83
85
|
}
|
|
84
86
|
if (noMatch) {
|
|
85
87
|
return {
|
package/src/components/index.tsx
CHANGED
|
@@ -6,7 +6,7 @@ export { default as useHForm } from "./Form/hooks/useHForm";
|
|
|
6
6
|
export { useHDialogForm } from "./DialogForm/hooks";
|
|
7
7
|
export { default as HFormConnect } from "./Form/HFormConnect";
|
|
8
8
|
export { default as HFormConfigProvider } from "./Form/Context/FormConfigProvider";
|
|
9
|
-
export {default as HBasicForm} from
|
|
9
|
+
export { default as HBasicForm } from "./Form/Basic";
|
|
10
10
|
|
|
11
11
|
import ModalForm from "./DialogForm/ModalForm";
|
|
12
12
|
import DrawerForm from "./DialogForm/DrawerForm";
|
package/src/pages/Form/index.tsx
CHANGED
|
@@ -1,102 +1,74 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
HBasicForm,
|
|
3
|
+
HForm,
|
|
4
|
+
HFormConfigProvider,
|
|
5
|
+
HSwitch,
|
|
6
|
+
useHForm,
|
|
7
|
+
HSelect,
|
|
8
8
|
} from "../../components";
|
|
9
9
|
import { useState } from "react";
|
|
10
|
-
import {Button, DatePicker, Form, Input, Row, Space} from "antd";
|
|
10
|
+
import { Button, DatePicker, Form, Input, Row, Space } from "antd";
|
|
11
11
|
const Test2 = () => {
|
|
12
12
|
return <Row style={{ background: "red" }} />;
|
|
13
13
|
};
|
|
14
|
-
const Test3 = ({ value={}, onChange }) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
14
|
+
const Test3 = ({ value = {}, onChange }) => {
|
|
15
|
+
const { fs, end } = value;
|
|
16
|
+
return (
|
|
17
|
+
<Space>
|
|
18
|
+
<HSelect
|
|
19
|
+
options={[{ value: "1321", key: 1 }]}
|
|
20
|
+
value={fs}
|
|
21
|
+
allowClear
|
|
22
|
+
onChange={() => {
|
|
23
|
+
onChange?.({});
|
|
24
|
+
}}
|
|
25
|
+
/>
|
|
26
|
+
<HSelect
|
|
27
|
+
options={[{ value: "112", key: 2 }]}
|
|
28
|
+
allowClear
|
|
29
|
+
value={end}
|
|
30
|
+
onChange={(val) => {
|
|
31
|
+
onChange?.({
|
|
32
|
+
...value,
|
|
33
|
+
end: val,
|
|
34
|
+
});
|
|
35
|
+
}}
|
|
36
|
+
/>
|
|
35
37
|
</Space>
|
|
38
|
+
);
|
|
36
39
|
};
|
|
37
|
-
const TestItem=()=>{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
const TestItem = () => {
|
|
41
|
+
return (
|
|
42
|
+
<Form.Item name="name1">
|
|
43
|
+
<Test3 />
|
|
40
44
|
</Form.Item>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
const Test3Item = () => {
|
|
48
|
+
return (
|
|
49
|
+
<Form.List name="users">
|
|
50
|
+
{(fields, { add, remove }) => (
|
|
45
51
|
<>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
name={name}
|
|
50
|
-
key={key}
|
|
51
|
-
>
|
|
52
|
-
<Test3/>
|
|
53
|
-
</Form.Item>
|
|
54
|
-
))}
|
|
55
|
-
<Form.Item>
|
|
56
|
-
<Button type="dashed" onClick={() => add({})} block>
|
|
57
|
-
Add field
|
|
58
|
-
</Button>
|
|
52
|
+
{fields.map(({ key, name, ...restField }) => (
|
|
53
|
+
<Form.Item {...restField} name={name} key={key}>
|
|
54
|
+
<Test3 />
|
|
59
55
|
</Form.Item>
|
|
56
|
+
))}
|
|
57
|
+
<Form.Item>
|
|
58
|
+
<Button type="dashed" onClick={() => add({})} block>
|
|
59
|
+
Add field
|
|
60
|
+
</Button>
|
|
61
|
+
</Form.Item>
|
|
60
62
|
</>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
63
|
+
)}
|
|
64
|
+
</Form.List>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
65
67
|
const formData = (options) => {
|
|
66
68
|
return [
|
|
67
69
|
{
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
configData={[
|
|
71
|
-
{
|
|
72
|
-
label: "下拉123",
|
|
73
|
-
className: "xiala",
|
|
74
|
-
render:()=>{
|
|
75
|
-
return <TestItem/>
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
]}/>
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
label: '会员标签',
|
|
83
|
-
hover: '添加新的会员标签后会覆盖用户原有的会员标签类型',
|
|
84
|
-
nameKey: 'userTags',
|
|
85
|
-
style: {
|
|
86
|
-
marginBottom: 0,
|
|
87
|
-
},
|
|
88
|
-
render:()=>{
|
|
89
|
-
return <HBasicForm
|
|
90
|
-
configData={[
|
|
91
|
-
{
|
|
92
|
-
label: "333",
|
|
93
|
-
className: "xiala",
|
|
94
|
-
render:()=>{
|
|
95
|
-
return <Test3Item/>
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
]}/>
|
|
99
|
-
}
|
|
70
|
+
name:"name",
|
|
71
|
+
label:"输入框"
|
|
100
72
|
},
|
|
101
73
|
];
|
|
102
74
|
};
|
|
@@ -140,6 +112,7 @@ export default () => {
|
|
|
140
112
|
<HForm
|
|
141
113
|
configData={formData(options)}
|
|
142
114
|
labelWidth={300}
|
|
115
|
+
dismissOnPressEnter={false}
|
|
143
116
|
form={form}
|
|
144
117
|
labelAlign={"left"}
|
|
145
118
|
onFinish={(value) => {
|
|
@@ -149,7 +122,7 @@ export default () => {
|
|
|
149
122
|
console.log(val, "onValuesChange");
|
|
150
123
|
}}
|
|
151
124
|
initialValues={{
|
|
152
|
-
|
|
125
|
+
name1: {},
|
|
153
126
|
}}
|
|
154
127
|
request={(params) => {
|
|
155
128
|
return new Promise<any>((resolve) => {
|
|
@@ -26,11 +26,13 @@ export default () => {
|
|
|
26
26
|
return Promise.resolve({ code: 200 });
|
|
27
27
|
}}
|
|
28
28
|
/>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
<HInputNumberGroup
|
|
30
|
+
inputNumberProps={[
|
|
31
|
+
{
|
|
32
|
+
min: Number.MIN_SAFE_INTEGER,
|
|
33
|
+
},
|
|
34
|
+
]}
|
|
35
|
+
/>
|
|
34
36
|
</Space>
|
|
35
37
|
);
|
|
36
38
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { HSelect } from "../../components";
|
|
2
|
-
import { Space
|
|
2
|
+
import { Space, Select } from "antd";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
export default () => {
|
|
5
|
-
const [selectVal, setSelectVal] = useState([{name:"11",id
|
|
5
|
+
const [selectVal, setSelectVal] = useState([{ name: "11", id: -100 }]);
|
|
6
6
|
return (
|
|
7
7
|
<Space size={"large"} direction={"vertical"} style={{ width: "100%" }}>
|
|
8
8
|
<HSelect
|
|
@@ -11,12 +11,12 @@ export default () => {
|
|
|
11
11
|
allowClear={true}
|
|
12
12
|
labelInValue
|
|
13
13
|
fieldNames={{
|
|
14
|
-
label:"name",
|
|
15
|
-
value:"id"
|
|
14
|
+
label: "name",
|
|
15
|
+
value: "id",
|
|
16
16
|
}}
|
|
17
17
|
value={selectVal}
|
|
18
|
-
onChange={(val,item)=>{
|
|
19
|
-
|
|
18
|
+
onChange={(val, item) => {
|
|
19
|
+
setSelectVal(val);
|
|
20
20
|
}}
|
|
21
21
|
request={async (params) => {
|
|
22
22
|
const { page, size } = params;
|
|
@@ -24,12 +24,12 @@ export default () => {
|
|
|
24
24
|
for (let i = 0; i < 100; i += 1) {
|
|
25
25
|
op.push({ name: `第${page}页第${i}条`, id: i + page });
|
|
26
26
|
}
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
})
|
|
27
|
+
return Promise.resolve({
|
|
28
|
+
page,
|
|
29
|
+
size: 100,
|
|
30
|
+
total: 1000,
|
|
31
|
+
data: op,
|
|
32
|
+
});
|
|
33
33
|
}}
|
|
34
34
|
isList
|
|
35
35
|
/>
|