@hw-component/form 0.0.8-beta-v7 → 0.0.8-beta-v9

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 (59) hide show
  1. package/es/CheckboxGroup/modal.d.ts +1 -0
  2. package/es/DialogForm/modal.d.ts +1 -1
  3. package/es/Form/config.d.ts +7 -5
  4. package/es/Form/config.js +11 -7
  5. package/es/Input/TrimInput.d.ts +3 -0
  6. package/es/Input/TrimInput.js +43 -0
  7. package/es/Input/VerificationCodeInput.d.ts +3 -3
  8. package/es/Input/VerificationCodeInput.js +2 -2
  9. package/es/Input/modal.d.ts +2 -0
  10. package/es/Submit/components.d.ts +6 -0
  11. package/es/Submit/components.js +70 -0
  12. package/es/Submit/hooks.d.ts +5 -0
  13. package/es/Submit/hooks.js +28 -0
  14. package/es/Submit/index.d.ts +4 -1
  15. package/es/Submit/index.js +24 -28
  16. package/es/Switch/index.d.ts +4 -2
  17. package/es/Switch/index.js +28 -4
  18. package/es/TextArea/TrimTextArea.d.ts +3 -0
  19. package/es/TextArea/TrimTextArea.js +43 -0
  20. package/es/index.d.ts +8 -6
  21. package/es/index.js +3 -1
  22. package/lib/CheckboxGroup/modal.d.ts +1 -0
  23. package/lib/DialogForm/modal.d.ts +1 -1
  24. package/lib/Form/config.d.ts +7 -5
  25. package/lib/Form/config.js +6 -2
  26. package/lib/Input/TrimInput.d.ts +3 -0
  27. package/lib/Input/TrimInput.js +46 -0
  28. package/lib/Input/VerificationCodeInput.d.ts +3 -3
  29. package/lib/Input/VerificationCodeInput.js +2 -2
  30. package/lib/Input/modal.d.ts +2 -0
  31. package/lib/Submit/components.d.ts +6 -0
  32. package/lib/Submit/components.js +71 -0
  33. package/lib/Submit/hooks.d.ts +5 -0
  34. package/lib/Submit/hooks.js +29 -0
  35. package/lib/Submit/index.d.ts +4 -1
  36. package/lib/Submit/index.js +22 -26
  37. package/lib/Switch/index.d.ts +4 -2
  38. package/lib/Switch/index.js +28 -4
  39. package/lib/TextArea/TrimTextArea.d.ts +3 -0
  40. package/lib/TextArea/TrimTextArea.js +46 -0
  41. package/lib/index.d.ts +8 -6
  42. package/lib/index.js +4 -0
  43. package/package.json +1 -1
  44. package/src/components/CheckboxGroup/modal.ts +1 -0
  45. package/src/components/DialogForm/DrawerForm/index.tsx +5 -3
  46. package/src/components/DialogForm/ModalForm.tsx +5 -3
  47. package/src/components/DialogForm/modal.ts +5 -2
  48. package/src/components/Form/config.ts +8 -3
  49. package/src/components/Input/TrimInput.tsx +26 -0
  50. package/src/components/Input/VerificationCodeInput.tsx +4 -4
  51. package/src/components/Input/modal.ts +2 -0
  52. package/src/components/Submit/components.tsx +57 -0
  53. package/src/components/Submit/hooks.ts +31 -0
  54. package/src/components/Submit/index.tsx +12 -25
  55. package/src/components/Switch/index.tsx +27 -1
  56. package/src/components/TextArea/TrimTextArea.tsx +30 -0
  57. package/src/components/index.tsx +5 -0
  58. package/src/pages/Form/index.tsx +70 -0
  59. package/src/pages/ModalForm/index.tsx +7 -5
@@ -1,7 +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 React from "react";
4
+ import type React from "react";
5
5
 
6
6
  type RootProps = HFormProps & ModalProps;
7
7
 
@@ -37,5 +37,8 @@ export interface DialogFormProps<P = any, T = any>
37
37
  onOk?: (data: T, params: P) => boolean | void;
38
38
  infoRequest?: (params: P) => Promise<T>;
39
39
  autoClear?: boolean;
40
- contentRender?:(dom:React.ReactNode,form:HDialogFormInstance)=>React.ReactNode;
40
+ contentRender?: (
41
+ dom: React.ReactNode,
42
+ form: HDialogFormInstance
43
+ ) => React.ReactNode;
41
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 HVerificationCodeInput from "../Input/VerificationCodeInput";
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: HVerificationCodeInput,
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 "@/components/Form/modal";
4
+ import type { HFormInstance } from "../Form/modal";
5
5
  import type { InputProps } from "antd";
6
- interface IVerificationCodeInputProps extends Omit<InputProps, "form"> {
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
- }: IVerificationCodeInputProps) => {
16
+ }: HVerificationCodeInputProps) => {
17
17
  const [countdown, setCountdown] = useState<number>(0);
18
18
  const timer = useMemo<{ time: any }>(() => {
19
19
  return {
@@ -10,6 +10,7 @@ export interface HInputProps<V = any>
10
10
  value?: V;
11
11
  defaultColor?: string;
12
12
  copy?: boolean;
13
+ addFormat?: (config: Record<string, addFormatItemModal>) => void;
13
14
  }
14
15
 
15
16
  interface ValueNameModal {
@@ -25,6 +26,7 @@ export interface HSelectInputProps
25
26
  valueName?: ValueNameModal;
26
27
  addFormat?: (config: Record<string, addFormatItemModal>) => void;
27
28
  addDispatchListener?: AddDispatchListenerFn;
29
+ subParams?: (formatValue: Record<string, any>) => any;
28
30
  }
29
31
  export interface HButtonProps extends Omit<ButtonProps, "onClick"> {
30
32
  onClick: (
@@ -0,0 +1,57 @@
1
+ import { Button } from "antd";
2
+ import { useFormContext } from "../Form/Context";
3
+ import React from "react";
4
+ import type {
5
+ ISubmitProps,
6
+ SubmitBarExtraType,
7
+ } from "@/components/Submit/index";
8
+ interface ControlFooterProps extends ISubmitProps {
9
+ action: SubmitBarExtraType;
10
+ }
11
+ function ResetBtn({ form, ...props }) {
12
+ return (
13
+ <Button
14
+ {...props}
15
+ onClick={() => {
16
+ form.resetFields();
17
+ }}
18
+ >
19
+ 重置
20
+ </Button>
21
+ );
22
+ }
23
+
24
+ function SubBtn({
25
+ type = "primary",
26
+ form,
27
+ text = "提交",
28
+ loading,
29
+ ...props
30
+ }: ISubmitProps) {
31
+ const { loading: formSubLoading = loading } = useFormContext();
32
+
33
+ return (
34
+ <Button
35
+ {...props}
36
+ type={type as any}
37
+ onClick={form.submit}
38
+ loading={formSubLoading}
39
+ >
40
+ {text}
41
+ </Button>
42
+ );
43
+ }
44
+
45
+ export const ControlFooter = ({ action, ...props }: ControlFooterProps) => {
46
+ const { form } = props;
47
+ if (action === "reset") {
48
+ return <ResetBtn {...props} />;
49
+ }
50
+ if (action === "submit") {
51
+ return <SubBtn {...props} />;
52
+ }
53
+ if (typeof action === "string") {
54
+ return <>{action}</>;
55
+ }
56
+ return React.cloneElement(action as any, { form });
57
+ };
@@ -0,0 +1,31 @@
1
+ import type {
2
+ ISubmitProps,
3
+ SubmitBarExtraType,
4
+ } from "@/components/Submit/index";
5
+ import { useMemo } from "react";
6
+
7
+ const getBarComKeyList = (extraList: SubmitBarExtraType[]) => {
8
+ return extraList.map((item, index) => {
9
+ return {
10
+ action: item,
11
+ key: `${index}`,
12
+ };
13
+ });
14
+ };
15
+
16
+ export const useBarSortList = (
17
+ props: Pick<ISubmitProps, "reset" | "extraList">
18
+ ) => {
19
+ const { extraList, reset = false } = props;
20
+ const list = useMemo(() => {
21
+ if (!extraList) {
22
+ const defaultList: SubmitBarExtraType[] = reset
23
+ ? ["reset", "submit"]
24
+ : ["submit"];
25
+ return getBarComKeyList(defaultList);
26
+ }
27
+ return getBarComKeyList(extraList);
28
+ }, [extraList, reset]);
29
+
30
+ return list;
31
+ };
@@ -1,45 +1,32 @@
1
- import { Button, Row, Space } from "antd";
1
+ import { Row, Space } from "antd";
2
2
  import React from "react";
3
- import { useFormContext } from "../Form/Context";
4
3
  import type { ButtonProps, FormInstance } from "antd/es";
4
+ import { useBarSortList } from "./hooks";
5
+ import { ControlFooter } from "./components";
6
+
7
+ export type SubmitBarExtraType = "submit" | "reset" | React.ReactDOM;
5
8
 
6
9
  export interface ISubmitProps extends Omit<ButtonProps, "form"> {
7
10
  text?: string;
8
11
  form: FormInstance;
9
12
  reset?: boolean;
10
13
  position?: "start" | "end";
14
+ extraList?: SubmitBarExtraType[];
11
15
  }
12
16
  export default ({
13
- text = "提交",
14
- type = "primary",
15
- form,
16
- loading,
17
17
  position = "start",
18
18
  reset,
19
+ extraList,
19
20
  ...props
20
21
  }: ISubmitProps) => {
21
- const { loading: formSubLoading = loading } = useFormContext();
22
+ const barList = useBarSortList({ reset, extraList });
23
+
22
24
  return (
23
25
  <Row justify={position} style={{ width: "100%" }}>
24
26
  <Space>
25
- {reset && (
26
- <Button
27
- {...props}
28
- onClick={() => {
29
- form.resetFields();
30
- }}
31
- >
32
- 重置
33
- </Button>
34
- )}
35
- <Button
36
- {...props}
37
- type={type}
38
- onClick={form.submit}
39
- loading={formSubLoading}
40
- >
41
- {text}
42
- </Button>
27
+ {barList?.map(({ action, key }) => {
28
+ return <ControlFooter {...props} key={key} action={action} />;
29
+ })}
43
30
  </Space>
44
31
  </Row>
45
32
  );
@@ -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);
@@ -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;
@@ -1,5 +1,6 @@
1
1
  import { HForm, HFormConfigProvider, useHForm } from "../../components";
2
2
  import { useState } from "react";
3
+ import { Button } from "antd";
3
4
 
4
5
  const formData = (options) => {
5
6
  const op = [
@@ -82,6 +83,12 @@ const formData = (options) => {
82
83
  name: "switch",
83
84
  type: "switch",
84
85
  rules: [{ required: true }],
86
+ itemProps: {
87
+ valueMap: {
88
+ open: 1,
89
+ close: 0,
90
+ },
91
+ },
85
92
  },
86
93
  {
87
94
  label: "时间",
@@ -170,11 +177,70 @@ const formData = (options) => {
170
177
  },
171
178
  },
172
179
  },
180
+ {
181
+ label: "去空input",
182
+ type: "trimInput",
183
+ name: "trimInput",
184
+ },
185
+ {
186
+ label: "去空textArea",
187
+ type: "trimTextArea",
188
+ name: "trimTextArea",
189
+ },
190
+ {
191
+ type: "submit",
192
+ },
193
+ {
194
+ type: "submit",
195
+ itemProps: {
196
+ extraList: [
197
+ <Button
198
+ key="wh"
199
+ onClick={() => {
200
+ console.log("起飞");
201
+ }}
202
+ >
203
+ 芜湖
204
+ </Button>,
205
+ "666",
206
+ "reset",
207
+ ],
208
+ },
209
+ },
173
210
  {
174
211
  type: "submit",
212
+ itemProps: {
213
+ extraList: [
214
+ <Button
215
+ key="wh"
216
+ onClick={() => {
217
+ console.log("起飞");
218
+ }}
219
+ >
220
+ 芜湖
221
+ </Button>,
222
+ <Ttta key="aa" />,
223
+ "666",
224
+ "submit",
225
+ "reset",
226
+ ],
227
+ },
175
228
  },
176
229
  ];
177
230
  };
231
+ function Ttta({ form }) {
232
+ return (
233
+ <div
234
+ onClick={() => {
235
+ console.log("form", form);
236
+ form.setFieldsValue({ switch: 1 });
237
+ }}
238
+ >
239
+ ttta
240
+ </div>
241
+ );
242
+ }
243
+
178
244
  const Test = (props) => {
179
245
  return <div>ffff</div>;
180
246
  };
@@ -201,6 +267,8 @@ export default () => {
201
267
  form={form}
202
268
  initialValues={{
203
269
  name: "fff",
270
+ trimInput: "trimInput",
271
+ trimTextArea: "trimTextArea",
204
272
  }}
205
273
  itemSpan={{ span: 12 }}
206
274
  onFinish={(value) => {
@@ -219,6 +287,8 @@ export default () => {
219
287
  colorInput: "rgba(24, 144, 255,1)",
220
288
  upload:
221
289
  "https://img2.baidu.com/it/u=2048195462,703560066&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=333",
290
+ trimInput: "trimInput",
291
+ trimTextArea: "trimTextArea",
222
292
  });
223
293
  }, 3000);
224
294
  });
@@ -176,11 +176,13 @@ export default () => {
176
176
  configData={data}
177
177
  labelWidth={88}
178
178
  autoClear={false}
179
- contentRender={(node,form)=>{
180
- return <div>
181
- <div>测试一些</div>
182
- {node}
183
- </div>
179
+ contentRender={(node, form) => {
180
+ return (
181
+ <div>
182
+ <div>测试一些</div>
183
+ {node}
184
+ </div>
185
+ );
184
186
  }}
185
187
  request={(val, params) => {
186
188
  console.log(val, params);