@hw-component/form 0.0.1-beta-v6 → 0.0.1-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.
Files changed (75) hide show
  1. package/es/CheckboxGroup/index.d.ts +1 -1
  2. package/es/DialogForm/DrawerForm/Footer.d.ts +4 -0
  3. package/es/DialogForm/DrawerForm/Footer.js +23 -0
  4. package/es/DialogForm/DrawerForm/Title.d.ts +4 -0
  5. package/es/DialogForm/DrawerForm/Title.js +18 -0
  6. package/es/DialogForm/DrawerForm/index.d.ts +4 -0
  7. package/es/DialogForm/DrawerForm/index.js +111 -0
  8. package/es/DialogForm/ModalForm.d.ts +4 -0
  9. package/es/{ModalForm/index.js → DialogForm/ModalForm.js} +39 -9
  10. package/es/DialogForm/hooks.d.ts +15 -0
  11. package/es/{ModalForm → DialogForm}/hooks.js +58 -13
  12. package/es/{ModalForm → DialogForm}/modal.d.ts +7 -4
  13. package/es/Form/HFormConnect.d.ts +1 -2
  14. package/es/Form/HFormConnect.js +8 -15
  15. package/es/Form/config.d.ts +4 -4
  16. package/es/Form/config.js +4 -4
  17. package/es/Form/modal.d.ts +7 -1
  18. package/es/Input/SelectInput.d.ts +1 -1
  19. package/es/TDPicker/RangePicker.d.ts +1 -1
  20. package/es/Upload/UrlUpload/index.d.ts +2 -2
  21. package/es/Upload/UrlUpload/index.js +3 -3
  22. package/es/Upload/index.d.ts +1 -2
  23. package/es/Upload/index.js +39 -5
  24. package/es/Upload/modal.d.ts +2 -0
  25. package/es/index.d.ts +7 -6
  26. package/es/index.js +5 -3
  27. package/lib/CheckboxGroup/index.d.ts +1 -1
  28. package/lib/DialogForm/DrawerForm/Footer.d.ts +4 -0
  29. package/lib/DialogForm/DrawerForm/Footer.js +26 -0
  30. package/lib/DialogForm/DrawerForm/Title.d.ts +4 -0
  31. package/lib/DialogForm/DrawerForm/Title.js +21 -0
  32. package/lib/DialogForm/DrawerForm/index.d.ts +4 -0
  33. package/lib/DialogForm/DrawerForm/index.js +114 -0
  34. package/lib/DialogForm/ModalForm.d.ts +4 -0
  35. package/lib/{ModalForm/index.js → DialogForm/ModalForm.js} +38 -8
  36. package/lib/DialogForm/hooks.d.ts +15 -0
  37. package/lib/{ModalForm → DialogForm}/hooks.js +59 -13
  38. package/lib/{ModalForm → DialogForm}/modal.d.ts +7 -4
  39. package/lib/Form/HFormConnect.d.ts +1 -2
  40. package/lib/Form/HFormConnect.js +8 -15
  41. package/lib/Form/config.d.ts +4 -4
  42. package/lib/Form/modal.d.ts +7 -1
  43. package/lib/Input/SelectInput.d.ts +1 -1
  44. package/lib/TDPicker/RangePicker.d.ts +1 -1
  45. package/lib/Upload/UrlUpload/index.d.ts +2 -2
  46. package/lib/Upload/UrlUpload/index.js +3 -3
  47. package/lib/Upload/index.d.ts +1 -2
  48. package/lib/Upload/index.js +39 -5
  49. package/lib/Upload/modal.d.ts +2 -0
  50. package/lib/index.d.ts +7 -6
  51. package/lib/index.js +7 -4
  52. package/package.json +1 -1
  53. package/src/components/DialogForm/DrawerForm/Footer.tsx +19 -0
  54. package/src/components/DialogForm/DrawerForm/Title.tsx +12 -0
  55. package/src/components/DialogForm/DrawerForm/index.tsx +85 -0
  56. package/src/components/{ModalForm/index.tsx → DialogForm/ModalForm.tsx} +14 -6
  57. package/src/components/{ModalForm → DialogForm}/hooks.ts +36 -11
  58. package/src/components/{ModalForm → DialogForm}/modal.ts +7 -4
  59. package/src/components/Form/HFormConnect.tsx +21 -7
  60. package/src/components/Form/config.ts +2 -2
  61. package/src/components/Form/modal.ts +7 -1
  62. package/src/components/Input/SelectInput.tsx +1 -0
  63. package/src/components/TDPicker/modal.ts +0 -1
  64. package/src/components/Upload/UrlUpload/index.tsx +2 -2
  65. package/src/components/Upload/index.tsx +39 -7
  66. package/src/components/Upload/modal.ts +2 -0
  67. package/src/components/index.tsx +5 -4
  68. package/src/pages/DrawerForm/index.tsx +127 -0
  69. package/src/pages/Form/index.tsx +3 -0
  70. package/src/pages/ModalForm/index.tsx +2 -2
  71. package/src/routes.tsx +7 -0
  72. package/es/ModalForm/hooks.d.ts +0 -12
  73. package/es/ModalForm/index.d.ts +0 -4
  74. package/lib/ModalForm/hooks.d.ts +0 -12
  75. package/lib/ModalForm/index.d.ts +0 -4
@@ -25,11 +25,17 @@ const formatMaker = (
25
25
  };
26
26
 
27
27
  export default (
28
- Component: React.FunctionComponent | React.ComponentClass,
28
+ component:
29
+ | React.FunctionComponent
30
+ | React.ComponentClass
31
+ | React.ForwardRefRenderFunction<any, any>,
29
32
  config: ConnectConfigModal = {}
30
33
  ) => {
31
34
  const { format = {} } = config;
32
- return (props: HFormItemProps) => {
35
+ const Index: React.ForwardRefRenderFunction<any, HFormItemProps> = (
36
+ props: HFormItemProps,
37
+ ref
38
+ ) => {
33
39
  const { name = "" } = props;
34
40
 
35
41
  const { form, valueType = "float" } = useFormContext();
@@ -44,10 +50,18 @@ export default (
44
50
  const addDispatchListener = (key: string, fn: argsFn) => {
45
51
  form?.addDispatchListener({ key, name }, fn);
46
52
  };
47
- return React.createElement<ConnectResultProps>(Component, {
48
- ...props,
49
- addFormat,
50
- addDispatchListener,
51
- });
53
+ const Component = component as React.ForwardRefRenderFunction<
54
+ any,
55
+ ConnectResultProps
56
+ >;
57
+ return (
58
+ <Component
59
+ {...props}
60
+ addFormat={addFormat}
61
+ addDispatchListener={addDispatchListener}
62
+ ref={ref}
63
+ />
64
+ );
52
65
  };
66
+ return React.forwardRef(Index);
53
67
  };
@@ -14,7 +14,7 @@ import HUpload from "../Upload";
14
14
  import HUrlUpload from "../Upload/UrlUpload";
15
15
  import HSubmit from "../Submit";
16
16
  import FormConfigProvider from "../Form/Context/FormConfigProvider";
17
- import TextArea from '../TextArea'
17
+ import TextArea from "../TextArea";
18
18
  export const placeholderConfig = {
19
19
  inputType: ["input", "inputNumber", "selectInput", "buttonInput"],
20
20
  selectType: ["select", "datePicker", "timePicker"],
@@ -37,5 +37,5 @@ export default {
37
37
  urlUpload: HUrlUpload,
38
38
  submit: HSubmit,
39
39
  formConfigProvider: FormConfigProvider,
40
- textArea:TextArea
40
+ textArea: TextArea,
41
41
  };
@@ -25,6 +25,7 @@ import type {
25
25
  ValueSwitchMapModal,
26
26
  DateRangePickerValueMapModal,
27
27
  } from "../modal";
28
+ import type { ForwardedRef } from "react";
28
29
  type RenderFun = (
29
30
  props: HItemProps,
30
31
  node: React.ReactNode,
@@ -80,6 +81,8 @@ export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form"> {
80
81
 
81
82
  export interface HFormItemProps extends HItemProps {
82
83
  required?: boolean;
84
+ value?: any;
85
+ onChange?: (val: any, item: any) => void;
83
86
  }
84
87
  export interface FormItemWithRender extends Omit<HFormItemProps, "render"> {
85
88
  render: (form: HFormInstance) => React.ReactNode;
@@ -142,7 +145,10 @@ export interface addFormatItemModal {
142
145
  outputValue: addValueFormat;
143
146
  }
144
147
 
145
- export interface ConnectResultProps {
148
+ export interface ConnectResultProps extends HFormItemProps {
146
149
  addFormat?: (format: Record<string, addFormatItemModal>) => void;
147
150
  addDispatchListener?: (key: string, fn: argsFn) => void;
151
+ ref?: ForwardedRef<any>;
152
+ value?: any;
153
+ onChange?: (value: any, item?: any) => void;
148
154
  }
@@ -3,6 +3,7 @@ import type { HSelectInputProps } from "./modal";
3
3
  import HSelect from "../Select";
4
4
  import { defaultSelectStyle, defaultValueName } from "./defaultConfig";
5
5
  import HFormConnect from "../Form/HFormConnect";
6
+ import { ConnectResultProps } from "@/components/Form/modal";
6
7
  export enum SelectInputType {
7
8
  input,
8
9
  select,
@@ -6,7 +6,6 @@ import type { TimePickerProps } from "antd";
6
6
  import type { DurationInputArg2 } from "moment";
7
7
  import type { DateRangePickerValueMapModal } from "../modal";
8
8
  import type { addFormatItemModal } from "@/components/Form/modal";
9
- import type { argsFn } from "@/components/Form/modal";
10
9
  export interface HDatePickerProps
11
10
  extends Omit<DatePickerProps, "onChange" | "format" | "ranges"> {
12
11
  onChange?: (time?: Moment | string | number) => void;
@@ -5,8 +5,7 @@ import type { IUploadRefModal, IUrlUploadProps } from "../modal";
5
5
  import TypeEle from "../MediaTypeEle/TypeEle";
6
6
  import { useRef, useState } from "react";
7
7
  import type { RcFile, UploadFile } from "antd/es/upload/interface";
8
-
9
- export default ({
8
+ const Index = ({
10
9
  placeholder = "请输入文件地址",
11
10
  value = [],
12
11
  onChange,
@@ -89,3 +88,4 @@ export default ({
89
88
  </Space>
90
89
  );
91
90
  };
91
+ export default Index;
@@ -1,11 +1,12 @@
1
- import { Upload } from "antd";
2
- import Btn from "./Btn";
3
1
  import React, { useImperativeHandle, useMemo, useState } from "react";
2
+ import type { IUpLoadProps, IUploadRefModal } from "./modal";
3
+ import { useProps } from "./hooks/propsMaker";
4
4
  import type { IPreviewProps } from "./Preview";
5
5
  import Preview from "./Preview";
6
6
  import { useChange } from "./hooks/change";
7
- import type { IUpLoadProps, IUploadRefModal } from "./modal";
8
- import { useProps } from "./hooks/propsMaker";
7
+ import { Upload } from "antd";
8
+ import Btn from "./Btn";
9
+ import HFormConnect from "../Form/HFormConnect";
9
10
 
10
11
  const Index: React.ForwardRefRenderFunction<IUploadRefModal, IUpLoadProps> = (
11
12
  {
@@ -18,6 +19,7 @@ const Index: React.ForwardRefRenderFunction<IUploadRefModal, IUpLoadProps> = (
18
19
  onPreview,
19
20
  request,
20
21
  maxSize,
22
+ addFormat,
21
23
  ...props
22
24
  },
23
25
  ref
@@ -52,10 +54,40 @@ const Index: React.ForwardRefRenderFunction<IUploadRefModal, IUpLoadProps> = (
52
54
  file,
53
55
  });
54
56
  };
55
-
56
57
  const maxNum = maxCount === 1 ? maxCount : Number.MAX_VALUE;
57
58
  const { visible, file: previewFile } = previewModal;
58
-
59
+ addFormat?.({
60
+ float: {
61
+ inputValue: (item, initValue) => {
62
+ const { name = "" } = item;
63
+ const initFileList = initValue[name] || [];
64
+ const fileList = initFileList.map((url, index) => {
65
+ return {
66
+ name: url,
67
+ response: {
68
+ url,
69
+ },
70
+ status: "done",
71
+ uid: `init-${index}`,
72
+ thumbUrl: url,
73
+ };
74
+ });
75
+ return {
76
+ [name]: fileList,
77
+ };
78
+ },
79
+ outputValue: (item, outputValue) => {
80
+ const { name: valueName = "" } = item;
81
+ const { [valueName]: itemVal = [] } = outputValue;
82
+ const urls = itemVal.map((fileItem) => {
83
+ return fileItem.response.url;
84
+ });
85
+ return {
86
+ [valueName]: urls,
87
+ };
88
+ },
89
+ },
90
+ });
59
91
  return (
60
92
  <div style={contentStyle}>
61
93
  <Upload
@@ -82,4 +114,4 @@ const Index: React.ForwardRefRenderFunction<IUploadRefModal, IUpLoadProps> = (
82
114
  );
83
115
  };
84
116
 
85
- export default React.forwardRef(Index);
117
+ export default HFormConnect(React.forwardRef(Index));
@@ -3,6 +3,7 @@ import type { UploadFile } from "antd/es/upload/interface";
3
3
  import type { BeforeUploadFileType, RcFile } from "rc-upload/lib/interface";
4
4
  import type { UploadChangeParam } from "antd/lib/upload/interface";
5
5
  import type { MediaTypeEnum } from "@/components/Upload/enums";
6
+ import type { addFormatItemModal } from "@/components/Form/modal";
6
7
 
7
8
  export interface IUpLoadProps extends Omit<UploadProps, "onChange"> {
8
9
  exFiles?: string[];
@@ -14,6 +15,7 @@ export interface IUpLoadProps extends Omit<UploadProps, "onChange"> {
14
15
  value?: UploadFile[];
15
16
  maxRowNum?: number;
16
17
  maxSize?: number;
18
+ addFormat?: (config: Record<string, addFormatItemModal>) => void;
17
19
  }
18
20
  export interface IMediaTypeEleProps {
19
21
  file?: UploadFile;
@@ -3,9 +3,9 @@ import FormConfig from "./Form/config";
3
3
  import PageHandler from "./PageHandler";
4
4
  export { default as HForm } from "./Form";
5
5
  export { default as useHForm } from "./Form/hooks/useHForm";
6
- export { useHModalForm } from "./ModalForm/hooks";
7
- import ModalForm from "./ModalForm";
8
-
6
+ export { useHDialogForm } from "./DialogForm/hooks";
7
+ import ModalForm from "./DialogForm/ModalForm";
8
+ import DrawerForm from "./DialogForm/DrawerForm";
9
9
  export const HSelect = FormConfig.select;
10
10
  export const HInput = FormConfig.input;
11
11
  export const HSelectInput = FormConfig.selectInput;
@@ -22,5 +22,6 @@ export const HTimePicker = FormConfig.timePicker;
22
22
  export const HInputNumber = FormConfig.inputNumber;
23
23
  export const HPageHandler = PageHandler;
24
24
  export const HFormConfigProvider = FormConfig.formConfigProvider;
25
- export const HTextArea=FormConfig.textArea;
25
+ export const HTextArea = FormConfig.textArea;
26
26
  export const HModalForm = ModalForm;
27
+ export const HDrawerForm = DrawerForm;
@@ -0,0 +1,127 @@
1
+ import { Button } from "antd";
2
+ import { HDrawerForm, useHDiaLogForm } from "../../components";
3
+ const data = [
4
+ {
5
+ label: "输入框",
6
+ name: "name",
7
+ rules: [
8
+ () => {
9
+ return {
10
+ required: true,
11
+ };
12
+ },
13
+ ],
14
+ },
15
+ {
16
+ label: "数字",
17
+ name: "sz",
18
+ type: "inputNumber",
19
+ rules: [{ required: true }],
20
+ },
21
+ {
22
+ label: "下拉输入框",
23
+ name: "selectInput",
24
+ type: "selectInput",
25
+ rules: [{ required: true }],
26
+ itemProps: {
27
+ valueName: {
28
+ select: "op",
29
+ input: "opInput",
30
+ },
31
+ selectProps: {
32
+ options: [{ label: "测试", value: 1 }],
33
+ },
34
+ },
35
+ },
36
+ {
37
+ label: "按钮输入框",
38
+ name: "buttonInput",
39
+ type: "buttonInput",
40
+ children: "点击",
41
+ rules: [{ required: true }],
42
+ },
43
+ {
44
+ label: "选择",
45
+ name: "checkboxGroup",
46
+ type: "checkboxGroup",
47
+ rules: [{ required: true }],
48
+ helper: "帮助我",
49
+ options: [
50
+ { label: "选择1", value: "check1" },
51
+ { label: "选择2", value: "check2" },
52
+ ],
53
+ },
54
+ {
55
+ label: "开关",
56
+ name: "switch",
57
+ type: "switch",
58
+ rules: [{ required: true }],
59
+ },
60
+ {
61
+ label: "时间",
62
+ name: "datePicker",
63
+ type: "datePicker",
64
+ hover: "时间选择",
65
+ helper: "帮助我",
66
+ rules: [{ required: true }],
67
+ },
68
+ {
69
+ label: "时间段",
70
+ name: "rangePicker",
71
+ type: "rangePicker",
72
+ helper: "帮助我",
73
+ rules: [{ required: true }],
74
+ itemProps: {
75
+ valueMap: {
76
+ start: "testStart",
77
+ end: "testEnd",
78
+ },
79
+ },
80
+ },
81
+ {
82
+ label: "时分秒",
83
+ name: "timePicker",
84
+ type: "timePicker",
85
+ rules: [{ required: true }],
86
+ },
87
+ {
88
+ label: "文件",
89
+ name: "upload",
90
+ type: "upload",
91
+ rules: [{ required: true }],
92
+ },
93
+ {
94
+ label: "地址文件",
95
+ name: "urlUpload",
96
+ type: "urlUpload",
97
+ rules: [{ required: true }],
98
+ },
99
+ ];
100
+ export default () => {
101
+ const modalForm = useHDiaLogForm();
102
+ return (
103
+ <>
104
+ <Button
105
+ onClick={() => {
106
+ modalForm.show({
107
+ initialValues: {
108
+ check1: 1,
109
+ testStart: "1694747960",
110
+ testEnd: "1693538359",
111
+ op: 1,
112
+ opInput: "12121",
113
+ },
114
+ });
115
+ }}
116
+ >
117
+ 打开
118
+ </Button>
119
+ <HDrawerForm
120
+ configData={data}
121
+ labelWidth={88}
122
+ modalForm={modalForm}
123
+ title="测试"
124
+ />
125
+ </>
126
+ );
127
+ };
@@ -128,6 +128,9 @@ export default () => {
128
128
  testEnd: "1693538359",
129
129
  op: 1,
130
130
  opInput: "12121",
131
+ upload: [
132
+ "https://img2.baidu.com/it/u=2048195462,703560066&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=333",
133
+ ],
131
134
  });
132
135
  }, 3000);
133
136
  });
@@ -1,5 +1,5 @@
1
1
  import { Button } from "antd";
2
- import { HModalForm, useHModalForm } from "../../components";
2
+ import { HModalForm, useHDiaLogForm } from "../../components";
3
3
  const data = [
4
4
  {
5
5
  label: "输入框",
@@ -98,7 +98,7 @@ const data = [
98
98
  },
99
99
  ];
100
100
  export default () => {
101
- const modalForm = useHModalForm();
101
+ const modalForm = useHDiaLogForm();
102
102
  return (
103
103
  <>
104
104
  <Button
package/src/routes.tsx CHANGED
@@ -9,6 +9,8 @@ import DatePicker from "./pages/DatePicker";
9
9
  import Upload from "./pages/Upload";
10
10
  import Form from "./pages/Form";
11
11
  import ModalForm from "./pages/ModalForm";
12
+ import DrawerForm from "./pages/DrawerForm";
13
+
12
14
  export interface RouteModal {
13
15
  path?: string;
14
16
  name?: string;
@@ -68,6 +70,11 @@ const routes: RouteModal[] = [
68
70
  name: "弹窗表单",
69
71
  element: <ModalForm />,
70
72
  },
73
+ {
74
+ path: "/drawerForm",
75
+ name: "抽屉表单",
76
+ element: <DrawerForm />,
77
+ },
71
78
  ];
72
79
 
73
80
  export default routes;
@@ -1,12 +0,0 @@
1
- /// <reference types="react" />
2
- import type { HModalFormInstance, ModifyPropsModal } from "@/components/ModalForm/modal";
3
- export declare const useModifyProps: ({ visible, configData, initialValues, modalForm, }: ModifyPropsModal) => {
4
- modalFormData: import("../Form/modal").HItemProps[];
5
- modalVisible: boolean | undefined;
6
- setModalVisible: import("react").Dispatch<import("react").SetStateAction<boolean | undefined>>;
7
- setModalFormData: import("react").Dispatch<import("react").SetStateAction<import("../Form/modal").HItemProps[]>>;
8
- initValue: Record<string, any> | undefined;
9
- setInitValue: import("react").Dispatch<import("react").SetStateAction<Record<string, any> | undefined>>;
10
- };
11
- export declare const useHModalForm: () => HModalFormInstance;
12
- export declare const useCurrentForm: (hModalForm?: HModalFormInstance) => HModalFormInstance;
@@ -1,4 +0,0 @@
1
- /// <reference types="react" />
2
- import type { ModalFormProps } from "@/components/ModalForm/modal";
3
- declare const _default: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, modalForm, initialValues, ...props }: ModalFormProps) => JSX.Element;
4
- export default _default;
@@ -1,12 +0,0 @@
1
- /// <reference types="react" />
2
- import type { HModalFormInstance, ModifyPropsModal } from "@/components/ModalForm/modal";
3
- export declare const useModifyProps: ({ visible, configData, initialValues, modalForm, }: ModifyPropsModal) => {
4
- modalFormData: import("../Form/modal").HItemProps[];
5
- modalVisible: boolean | undefined;
6
- setModalVisible: import("react").Dispatch<import("react").SetStateAction<boolean | undefined>>;
7
- setModalFormData: import("react").Dispatch<import("react").SetStateAction<import("../Form/modal").HItemProps[]>>;
8
- initValue: Record<string, any> | undefined;
9
- setInitValue: import("react").Dispatch<import("react").SetStateAction<Record<string, any> | undefined>>;
10
- };
11
- export declare const useHModalForm: () => HModalFormInstance;
12
- export declare const useCurrentForm: (hModalForm?: HModalFormInstance) => HModalFormInstance;
@@ -1,4 +0,0 @@
1
- /// <reference types="react" />
2
- import type { ModalFormProps } from "@/components/ModalForm/modal";
3
- declare const _default: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, modalForm, initialValues, ...props }: ModalFormProps) => JSX.Element;
4
- export default _default;