@hw-component/form 0.0.8-beta-v6 → 0.0.8-beta-v8
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/es/DialogForm/DrawerForm/index.d.ts +1 -1
- package/es/DialogForm/DrawerForm/index.js +42 -40
- package/es/DialogForm/ModalForm.d.ts +1 -1
- package/es/DialogForm/ModalForm.js +41 -39
- package/es/DialogForm/modal.d.ts +2 -0
- package/es/Form/config.d.ts +6 -4
- package/es/Form/config.js +11 -7
- package/es/Input/TrimInput.d.ts +3 -0
- package/es/Input/TrimInput.js +43 -0
- package/es/Input/VerificationCodeInput.d.ts +3 -3
- package/es/Input/VerificationCodeInput.js +2 -2
- package/es/Input/modal.d.ts +1 -0
- package/es/Switch/index.d.ts +4 -2
- package/es/Switch/index.js +28 -4
- package/es/TextArea/TrimTextArea.d.ts +3 -0
- package/es/TextArea/TrimTextArea.js +43 -0
- package/es/index.d.ts +8 -6
- package/es/index.js +3 -1
- package/lib/DialogForm/DrawerForm/index.d.ts +1 -1
- package/lib/DialogForm/DrawerForm/index.js +42 -40
- package/lib/DialogForm/ModalForm.d.ts +1 -1
- package/lib/DialogForm/ModalForm.js +41 -39
- package/lib/DialogForm/modal.d.ts +2 -0
- package/lib/Form/config.d.ts +6 -4
- package/lib/Form/config.js +6 -2
- package/lib/Input/TrimInput.d.ts +3 -0
- package/lib/Input/TrimInput.js +46 -0
- package/lib/Input/VerificationCodeInput.d.ts +3 -3
- package/lib/Input/VerificationCodeInput.js +2 -2
- package/lib/Input/modal.d.ts +1 -0
- package/lib/Switch/index.d.ts +4 -2
- package/lib/Switch/index.js +28 -4
- package/lib/TextArea/TrimTextArea.d.ts +3 -0
- package/lib/TextArea/TrimTextArea.js +46 -0
- package/lib/index.d.ts +8 -6
- package/lib/index.js +4 -0
- package/package.json +1 -1
- package/src/components/DialogForm/DrawerForm/index.tsx +22 -18
- package/src/components/DialogForm/ModalForm.tsx +21 -17
- package/src/components/DialogForm/modal.ts +5 -0
- package/src/components/Form/config.ts +8 -3
- package/src/components/Input/TrimInput.tsx +26 -0
- package/src/components/Input/VerificationCodeInput.tsx +4 -4
- package/src/components/Input/modal.ts +1 -0
- package/src/components/Switch/index.tsx +27 -1
- package/src/components/TextArea/TrimTextArea.tsx +30 -0
- package/src/components/index.tsx +5 -0
- package/src/pages/Form/index.tsx +20 -0
- package/src/pages/ModalForm/index.tsx +8 -0
|
@@ -20,6 +20,7 @@ export default ({
|
|
|
20
20
|
onOk,
|
|
21
21
|
onValuesChange,
|
|
22
22
|
autoClear = true,
|
|
23
|
+
contentRender,
|
|
23
24
|
...props
|
|
24
25
|
}: DialogFormProps) => {
|
|
25
26
|
const currentForm = useCurrentForm(dialogForm);
|
|
@@ -47,6 +48,25 @@ export default ({
|
|
|
47
48
|
setModalVisible(false);
|
|
48
49
|
};
|
|
49
50
|
const { loading, run } = useSub({ request, onFinish });
|
|
51
|
+
const node = (
|
|
52
|
+
<HForm
|
|
53
|
+
configData={modalFormData}
|
|
54
|
+
initialValues={initValue}
|
|
55
|
+
onValuesChange={onValuesChange}
|
|
56
|
+
onFinish={async (values, outParams) => {
|
|
57
|
+
const result = await run(values, outParams);
|
|
58
|
+
const close = onOk?.(result, outParams);
|
|
59
|
+
if (close === false) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
cancel();
|
|
63
|
+
}}
|
|
64
|
+
{...props}
|
|
65
|
+
params={formParams}
|
|
66
|
+
form={currentForm}
|
|
67
|
+
infoRequest={infoRequest}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
50
70
|
return (
|
|
51
71
|
<Modal
|
|
52
72
|
title={modalTitle}
|
|
@@ -64,23 +84,7 @@ export default ({
|
|
|
64
84
|
destroyOnClose={true}
|
|
65
85
|
>
|
|
66
86
|
<FormConfigProvider {...providerConfig}>
|
|
67
|
-
|
|
68
|
-
configData={modalFormData}
|
|
69
|
-
initialValues={initValue}
|
|
70
|
-
onValuesChange={onValuesChange}
|
|
71
|
-
onFinish={async (values, outParams) => {
|
|
72
|
-
const result = await run(values, outParams);
|
|
73
|
-
const close = onOk?.(result, outParams);
|
|
74
|
-
if (close === false) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
cancel();
|
|
78
|
-
}}
|
|
79
|
-
{...props}
|
|
80
|
-
params={formParams}
|
|
81
|
-
form={currentForm}
|
|
82
|
-
infoRequest={infoRequest}
|
|
83
|
-
/>
|
|
87
|
+
{contentRender ? contentRender?.(node, currentForm) : node}
|
|
84
88
|
</FormConfigProvider>
|
|
85
89
|
</Modal>
|
|
86
90
|
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ModalProps } from "antd";
|
|
2
2
|
import type { HFormInstance, HItemProps, HFormProps } from "../Form/modal";
|
|
3
3
|
import type { PromiseFnResult } from "../modal";
|
|
4
|
+
import type React from "react";
|
|
4
5
|
|
|
5
6
|
type RootProps = HFormProps & ModalProps;
|
|
6
7
|
|
|
@@ -36,4 +37,8 @@ export interface DialogFormProps<P = any, T = any>
|
|
|
36
37
|
onOk?: (data: T, params: P) => boolean | void;
|
|
37
38
|
infoRequest?: (params: P) => Promise<T>;
|
|
38
39
|
autoClear?: boolean;
|
|
40
|
+
contentRender?: (
|
|
41
|
+
dom: React.ReactNode,
|
|
42
|
+
form: HDialogFormInstance
|
|
43
|
+
) => React.ReactNode;
|
|
39
44
|
}
|
|
@@ -16,8 +16,9 @@ import HSubmit from "../Submit";
|
|
|
16
16
|
import TextArea from "../TextArea";
|
|
17
17
|
import ColorInput from "../Input/ColorInput";
|
|
18
18
|
import Cascader from "../Cascader";
|
|
19
|
-
import
|
|
20
|
-
|
|
19
|
+
import VerificationCodeInput from "../Input/VerificationCodeInput";
|
|
20
|
+
import TrimInput from "../Input/TrimInput";
|
|
21
|
+
import TrimTextArea from "../TextArea/TrimTextArea";
|
|
21
22
|
export const placeholderConfig = {
|
|
22
23
|
inputType: [
|
|
23
24
|
"input",
|
|
@@ -25,6 +26,8 @@ export const placeholderConfig = {
|
|
|
25
26
|
"selectInput",
|
|
26
27
|
"buttonInput",
|
|
27
28
|
"verificationCodeInput",
|
|
29
|
+
"trimInput",
|
|
30
|
+
"",
|
|
28
31
|
],
|
|
29
32
|
selectType: ["select", "datePicker", "timePicker", "colorInput"],
|
|
30
33
|
};
|
|
@@ -47,7 +50,9 @@ const componentConfig = {
|
|
|
47
50
|
textArea: TextArea,
|
|
48
51
|
colorInput: ColorInput,
|
|
49
52
|
cascader: Cascader,
|
|
50
|
-
verificationCodeInput:
|
|
53
|
+
verificationCodeInput: VerificationCodeInput,
|
|
54
|
+
trimInput: TrimInput,
|
|
55
|
+
trimTextArea: TrimTextArea,
|
|
51
56
|
};
|
|
52
57
|
|
|
53
58
|
export default componentConfig;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Input from "./index";
|
|
2
|
+
import type { HInputProps } from "./modal";
|
|
3
|
+
import HFormConnect from "../Form/HFormConnect";
|
|
4
|
+
|
|
5
|
+
const Index = ({ addFormat, ...props }: HInputProps) => {
|
|
6
|
+
addFormat?.({
|
|
7
|
+
float: {
|
|
8
|
+
inputValue: (item, initValue) => {
|
|
9
|
+
const { name: valueName = "" } = item;
|
|
10
|
+
return {
|
|
11
|
+
[valueName]: initValue[valueName],
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
outputValue: (item, outputValue) => {
|
|
15
|
+
const { name = "" } = item;
|
|
16
|
+
const { [name]: itemVal } = outputValue;
|
|
17
|
+
return {
|
|
18
|
+
[name]: itemVal?.trim(),
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
return <Input {...props} />;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default HFormConnect(Index);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
2
|
import ButtonInput from "./ButtonInput";
|
|
3
3
|
import { useRequest } from "ahooks";
|
|
4
|
-
import type { HFormInstance } from "
|
|
4
|
+
import type { HFormInstance } from "../Form/modal";
|
|
5
5
|
import type { InputProps } from "antd";
|
|
6
|
-
interface
|
|
7
|
-
request?: (value) => Promise<any>;
|
|
6
|
+
export interface HVerificationCodeInputProps extends Omit<InputProps, "form"> {
|
|
7
|
+
request?: (value: any) => Promise<any>;
|
|
8
8
|
form?: HFormInstance;
|
|
9
9
|
}
|
|
10
10
|
export default ({
|
|
@@ -13,7 +13,7 @@ export default ({
|
|
|
13
13
|
form,
|
|
14
14
|
onChange,
|
|
15
15
|
...props
|
|
16
|
-
}:
|
|
16
|
+
}: HVerificationCodeInputProps) => {
|
|
17
17
|
const [countdown, setCountdown] = useState<number>(0);
|
|
18
18
|
const timer = useMemo<{ time: any }>(() => {
|
|
19
19
|
return {
|
|
@@ -3,12 +3,15 @@ import { Space, Switch } from "antd";
|
|
|
3
3
|
import React, { useMemo } from "react";
|
|
4
4
|
import { useMatchConfigProps } from "../hooks";
|
|
5
5
|
import type { ValueSwitchMapModal } from "../modal";
|
|
6
|
+
import type { addFormatItemModal } from "../Form/modal";
|
|
7
|
+
import HFormConnect from "../Form/HFormConnect";
|
|
6
8
|
|
|
7
9
|
export interface HSwitchProps extends Omit<SwitchProps, "onChange"> {
|
|
8
10
|
valueMap?: ValueSwitchMapModal;
|
|
9
11
|
value?: any;
|
|
10
12
|
onChange?: (val: any) => void;
|
|
11
13
|
beforeText?: React.ReactNode;
|
|
14
|
+
addFormat?: (format: Record<string, addFormatItemModal>) => void;
|
|
12
15
|
}
|
|
13
16
|
const Index: React.FC<HSwitchProps> = ({
|
|
14
17
|
value,
|
|
@@ -18,6 +21,7 @@ const Index: React.FC<HSwitchProps> = ({
|
|
|
18
21
|
unCheckedChildren = "关闭",
|
|
19
22
|
checkedChildren = "开启",
|
|
20
23
|
beforeText,
|
|
24
|
+
addFormat,
|
|
21
25
|
...props
|
|
22
26
|
}) => {
|
|
23
27
|
const { valueSwitchMap = {} } = useMatchConfigProps({
|
|
@@ -34,6 +38,28 @@ const Index: React.FC<HSwitchProps> = ({
|
|
|
34
38
|
}
|
|
35
39
|
onChange?.(subVal);
|
|
36
40
|
};
|
|
41
|
+
addFormat?.({
|
|
42
|
+
float: {
|
|
43
|
+
inputValue: (item, initValue) => {
|
|
44
|
+
const { close } = valueSwitchMap;
|
|
45
|
+
const { name: valueName = "" } = item;
|
|
46
|
+
let val = initValue[valueName];
|
|
47
|
+
if (typeof val === "undefined" || val === null) {
|
|
48
|
+
val = close;
|
|
49
|
+
}
|
|
50
|
+
console.log(val, "");
|
|
51
|
+
return {
|
|
52
|
+
[valueName]: val,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
outputValue: (item, outputValue) => {
|
|
56
|
+
const { name = "" } = item;
|
|
57
|
+
return {
|
|
58
|
+
[name]: outputValue[name],
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
});
|
|
37
63
|
return (
|
|
38
64
|
<Space>
|
|
39
65
|
{beforeText}
|
|
@@ -49,4 +75,4 @@ const Index: React.FC<HSwitchProps> = ({
|
|
|
49
75
|
);
|
|
50
76
|
};
|
|
51
77
|
|
|
52
|
-
export default Index;
|
|
78
|
+
export default HFormConnect(Index);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import TextArea from "./index";
|
|
2
|
+
import type { TextAreaProps } from "antd/es/input";
|
|
3
|
+
import type { addFormatItemModal } from "../Form/modal";
|
|
4
|
+
import HFormConnect from "../Form/HFormConnect";
|
|
5
|
+
|
|
6
|
+
interface TrimTextAreaProps extends TextAreaProps {
|
|
7
|
+
addFormat?: (config: Record<string, addFormatItemModal>) => void;
|
|
8
|
+
}
|
|
9
|
+
const Index = ({ addFormat, ...props }: TrimTextAreaProps) => {
|
|
10
|
+
addFormat?.({
|
|
11
|
+
float: {
|
|
12
|
+
inputValue: (item, initValue) => {
|
|
13
|
+
const { name: valueName = "" } = item;
|
|
14
|
+
return {
|
|
15
|
+
[valueName]: initValue[valueName],
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
outputValue: (item, outputValue) => {
|
|
19
|
+
const { name = "" } = item;
|
|
20
|
+
const { [name]: itemVal } = outputValue;
|
|
21
|
+
return {
|
|
22
|
+
[name]: itemVal?.trim(),
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return <TextArea {...props} />;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default HFormConnect(Index);
|
package/src/components/index.tsx
CHANGED
|
@@ -29,4 +29,9 @@ export const HColorInput = FormConfig.colorInput;
|
|
|
29
29
|
export const HModalForm = ModalForm;
|
|
30
30
|
export const HDrawerForm = DrawerForm;
|
|
31
31
|
export const HCascader = FormConfig.cascader;
|
|
32
|
+
// @ts-ignore
|
|
32
33
|
export const HVerificationCodeInput = FormConfig.verificationCodeInput;
|
|
34
|
+
|
|
35
|
+
export const HTrimInput = FormConfig.trimInput;
|
|
36
|
+
|
|
37
|
+
export const HTrimTextArea = FormConfig.trimTextArea;
|
package/src/pages/Form/index.tsx
CHANGED
|
@@ -82,6 +82,12 @@ const formData = (options) => {
|
|
|
82
82
|
name: "switch",
|
|
83
83
|
type: "switch",
|
|
84
84
|
rules: [{ required: true }],
|
|
85
|
+
itemProps: {
|
|
86
|
+
valueMap: {
|
|
87
|
+
open: 1,
|
|
88
|
+
close: 0,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
85
91
|
},
|
|
86
92
|
{
|
|
87
93
|
label: "时间",
|
|
@@ -170,6 +176,16 @@ const formData = (options) => {
|
|
|
170
176
|
},
|
|
171
177
|
},
|
|
172
178
|
},
|
|
179
|
+
{
|
|
180
|
+
label: "去空input",
|
|
181
|
+
type: "trimInput",
|
|
182
|
+
name: "trimInput",
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
label: "去空textArea",
|
|
186
|
+
type: "trimTextArea",
|
|
187
|
+
name: "trimTextArea",
|
|
188
|
+
},
|
|
173
189
|
{
|
|
174
190
|
type: "submit",
|
|
175
191
|
},
|
|
@@ -201,6 +217,8 @@ export default () => {
|
|
|
201
217
|
form={form}
|
|
202
218
|
initialValues={{
|
|
203
219
|
name: "fff",
|
|
220
|
+
trimInput: "trimInput",
|
|
221
|
+
trimTextArea: "trimTextArea",
|
|
204
222
|
}}
|
|
205
223
|
itemSpan={{ span: 12 }}
|
|
206
224
|
onFinish={(value) => {
|
|
@@ -219,6 +237,8 @@ export default () => {
|
|
|
219
237
|
colorInput: "rgba(24, 144, 255,1)",
|
|
220
238
|
upload:
|
|
221
239
|
"https://img2.baidu.com/it/u=2048195462,703560066&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=333",
|
|
240
|
+
trimInput: "trimInput",
|
|
241
|
+
trimTextArea: "trimTextArea",
|
|
222
242
|
});
|
|
223
243
|
}, 3000);
|
|
224
244
|
});
|
|
@@ -176,6 +176,14 @@ export default () => {
|
|
|
176
176
|
configData={data}
|
|
177
177
|
labelWidth={88}
|
|
178
178
|
autoClear={false}
|
|
179
|
+
contentRender={(node, form) => {
|
|
180
|
+
return (
|
|
181
|
+
<div>
|
|
182
|
+
<div>测试一些</div>
|
|
183
|
+
{node}
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
186
|
+
}}
|
|
179
187
|
request={(val, params) => {
|
|
180
188
|
console.log(val, params);
|
|
181
189
|
}}
|