@hw-component/form 0.0.9-beta-v21 → 0.0.9-beta-v22

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 (111) hide show
  1. package/package.json +1 -1
  2. package/src/Layout.tsx +61 -0
  3. package/src/app.tsx +33 -0
  4. package/src/components/Cascader/index.tsx +31 -0
  5. package/src/components/CheckboxGroup/CheckBox/index.tsx +38 -0
  6. package/src/components/CheckboxGroup/hooks.ts +105 -0
  7. package/src/components/CheckboxGroup/index.tsx +85 -0
  8. package/src/components/CheckboxGroup/modal.ts +17 -0
  9. package/src/components/DialogForm/DrawerForm/Footer.tsx +20 -0
  10. package/src/components/DialogForm/DrawerForm/Title.tsx +12 -0
  11. package/src/components/DialogForm/DrawerForm/index.tsx +110 -0
  12. package/src/components/DialogForm/ModalForm.tsx +91 -0
  13. package/src/components/DialogForm/hooks.ts +122 -0
  14. package/src/components/DialogForm/modal.ts +44 -0
  15. package/src/components/Form/Context/FormConfigProvider.tsx +38 -0
  16. package/src/components/Form/Context/index.tsx +14 -0
  17. package/src/components/Form/FormItem/BasicItem.tsx +95 -0
  18. package/src/components/Form/FormItem/Helper.tsx +25 -0
  19. package/src/components/Form/FormItem/RegularFormItem.tsx +13 -0
  20. package/src/components/Form/FormItem/UpFormItem.tsx +21 -0
  21. package/src/components/Form/FormItem/hooks.tsx +54 -0
  22. package/src/components/Form/FormItem/index.tsx +8 -0
  23. package/src/components/Form/HFormConnect.tsx +74 -0
  24. package/src/components/Form/InitSet.tsx +10 -0
  25. package/src/components/Form/Label.tsx +50 -0
  26. package/src/components/Form/config.ts +58 -0
  27. package/src/components/Form/hooks/index.ts +114 -0
  28. package/src/components/Form/hooks/useDefaultRender.tsx +45 -0
  29. package/src/components/Form/hooks/useHForm.ts +182 -0
  30. package/src/components/Form/hooks/useInitConfigData.tsx +194 -0
  31. package/src/components/Form/index.less +54 -0
  32. package/src/components/Form/index.tsx +113 -0
  33. package/src/components/Form/modal.ts +206 -0
  34. package/src/components/Input/ButtonInput.tsx +47 -0
  35. package/src/components/Input/ColorInput/Picker.tsx +18 -0
  36. package/src/components/Input/ColorInput/data.ts +102 -0
  37. package/src/components/Input/ColorInput/index.less +10 -0
  38. package/src/components/Input/ColorInput/index.tsx +58 -0
  39. package/src/components/Input/InputNumber.tsx +5 -0
  40. package/src/components/Input/SelectInput.tsx +75 -0
  41. package/src/components/Input/TrimInput.tsx +26 -0
  42. package/src/components/Input/VerificationCodeInput.tsx +74 -0
  43. package/src/components/Input/defaultConfig.ts +8 -0
  44. package/src/components/Input/index.tsx +26 -0
  45. package/src/components/Input/modal.ts +40 -0
  46. package/src/components/PageHandler/ErrorComponent.tsx +20 -0
  47. package/src/components/PageHandler/LoadingComponent.tsx +9 -0
  48. package/src/components/PageHandler/index.tsx +14 -0
  49. package/src/components/PageHandler/modal.ts +6 -0
  50. package/src/components/RadioGroup/index.tsx +45 -0
  51. package/src/components/Select/components/AllSelect.tsx +54 -0
  52. package/src/components/Select/components/CheckBoxOption.tsx +14 -0
  53. package/src/components/Select/components/DropdownComponent.tsx +36 -0
  54. package/src/components/Select/components/NoFindItem.tsx +7 -0
  55. package/src/components/Select/components/NotFoundContent.tsx +25 -0
  56. package/src/components/Select/defaultConfig.tsx +23 -0
  57. package/src/components/Select/hooks/changeHooks.tsx +159 -0
  58. package/src/components/Select/hooks/norHooks.ts +85 -0
  59. package/src/components/Select/index.less +22 -0
  60. package/src/components/Select/index.tsx +126 -0
  61. package/src/components/Select/modal.ts +36 -0
  62. package/src/components/Select/utils.ts +18 -0
  63. package/src/components/Submit/components.tsx +57 -0
  64. package/src/components/Submit/hooks.ts +31 -0
  65. package/src/components/Submit/index.tsx +33 -0
  66. package/src/components/Switch/index.tsx +77 -0
  67. package/src/components/TDPicker/RangePicker.tsx +109 -0
  68. package/src/components/TDPicker/TimePicker.tsx +29 -0
  69. package/src/components/TDPicker/hooks.ts +150 -0
  70. package/src/components/TDPicker/index.tsx +33 -0
  71. package/src/components/TDPicker/modal.ts +48 -0
  72. package/src/components/TextArea/TrimTextArea.tsx +30 -0
  73. package/src/components/TextArea/index.tsx +8 -0
  74. package/src/components/Upload/Btn.tsx +24 -0
  75. package/src/components/Upload/MediaTypeEle/TypeEle.tsx +26 -0
  76. package/src/components/Upload/MediaTypeEle/index.tsx +34 -0
  77. package/src/components/Upload/Preview/index.tsx +14 -0
  78. package/src/components/Upload/UrlUpload/index.tsx +104 -0
  79. package/src/components/Upload/enums.ts +5 -0
  80. package/src/components/Upload/hooks/change.ts +79 -0
  81. package/src/components/Upload/hooks/customRequest.ts +87 -0
  82. package/src/components/Upload/hooks/propsMaker.ts +20 -0
  83. package/src/components/Upload/index.tsx +119 -0
  84. package/src/components/Upload/modal.ts +33 -0
  85. package/src/components/Upload/util.ts +27 -0
  86. package/src/components/config.ts +47 -0
  87. package/src/components/hooks/index.ts +53 -0
  88. package/src/components/index.tsx +37 -0
  89. package/src/components/modal.ts +20 -0
  90. package/src/components/styles/index.less +3 -0
  91. package/src/components/styles/local.less +1 -0
  92. package/src/components/typings.d.ts +11 -0
  93. package/src/index.less +20 -0
  94. package/src/index.tsx +12 -0
  95. package/src/pages/Checkbox/index.tsx +14 -0
  96. package/src/pages/DatePicker/index.tsx +33 -0
  97. package/src/pages/DrawerForm/index.tsx +145 -0
  98. package/src/pages/Form/index.tsx +172 -0
  99. package/src/pages/Input/index.tsx +30 -0
  100. package/src/pages/ModalForm/index.tsx +191 -0
  101. package/src/pages/Radio/index.tsx +18 -0
  102. package/src/pages/Select/index.tsx +63 -0
  103. package/src/pages/Switch/index.tsx +18 -0
  104. package/src/pages/Upload/index.tsx +14 -0
  105. package/src/routes.tsx +80 -0
  106. package/.husky/pre-commit +0 -4
  107. package/.idea/hw-component-form.iml +0 -12
  108. package/.idea/inspectionProfiles/Project_Default.xml +0 -7
  109. package/.idea/misc.xml +0 -6
  110. package/.idea/modules.xml +0 -8
  111. package/.idea/vcs.xml +0 -6
@@ -0,0 +1,122 @@
1
+ import { useEffect, useMemo, useState } from "react";
2
+ import useHForm from "../Form/hooks/useHForm";
3
+ import type {
4
+ DialogFormProps,
5
+ HDialogFormInstance,
6
+ ModifyPropsModal,
7
+ } from "./modal";
8
+ import { useRequest } from "ahooks";
9
+
10
+ export const useModifyProps = ({
11
+ visible,
12
+ configData,
13
+ initialValues,
14
+ dialogForm,
15
+ afterClose,
16
+ params,
17
+ title,
18
+ onCancel,
19
+ autoClear,
20
+ }: ModifyPropsModal) => {
21
+ const [modalVisible, setModalVisible] = useState(visible);
22
+ const [modalFormData, setModalFormData] = useState(configData);
23
+ const [initValue, setInitValue] = useState(initialValues);
24
+ const [formParams, setFormParams] = useState(params);
25
+ const [modalTitle, setModalTitle] = useState(title);
26
+ const saveOldParamsObj = useMemo(() => {
27
+ return {
28
+ old: {},
29
+ };
30
+ }, []);
31
+ const onAfterClose = () => {
32
+ onCancel?.();
33
+ saveOldParamsObj.old = dialogForm.outputValues();
34
+ setTimeout(() => {
35
+ dialogForm.clear();
36
+ afterClose?.();
37
+ }, 100);
38
+ };
39
+
40
+ useEffect(() => {
41
+ setModalVisible(visible);
42
+ }, [visible]);
43
+
44
+ useEffect(() => {
45
+ setModalFormData(configData);
46
+ }, [configData]);
47
+ useEffect(() => {
48
+ setFormParams(params);
49
+ }, [params]);
50
+ useEffect(() => {
51
+ setModalTitle(title);
52
+ }, [title]);
53
+ useEffect(() => {
54
+ setInitValue(initialValues);
55
+ }, [initialValues]);
56
+ useEffect(() => {
57
+ dialogForm.show = (showParams = {}) => {
58
+ const {
59
+ configData: changeConfigData,
60
+ initialValues: changeInitialValues = {},
61
+ params: changeParams = {},
62
+ title: changeTitle,
63
+ } = showParams;
64
+ if (!!changeConfigData) {
65
+ setModalFormData(changeConfigData);
66
+ }
67
+ setFormParams(changeParams);
68
+ if (!!changeTitle) {
69
+ setModalTitle(changeTitle);
70
+ }
71
+ const relChangeInitVal = autoClear
72
+ ? changeInitialValues
73
+ : { ...saveOldParamsObj.old, ...changeInitialValues };
74
+ setInitValue(relChangeInitVal);
75
+ setModalVisible(true);
76
+ };
77
+ dialogForm.hide = () => {
78
+ setModalVisible(false);
79
+ onAfterClose();
80
+ };
81
+ }, [afterClose, autoClear]);
82
+ return {
83
+ modalFormData,
84
+ modalVisible,
85
+ setModalVisible,
86
+ setModalFormData,
87
+ initValue,
88
+ setInitValue,
89
+ onAfterClose,
90
+ formParams,
91
+ title: modalTitle,
92
+ };
93
+ };
94
+ export const useHDialogForm = () => {
95
+ const hForm = useHForm();
96
+ return useMemo<HDialogFormInstance>(() => {
97
+ return {
98
+ ...hForm,
99
+ show: (params) => {},
100
+ hide: () => {},
101
+ };
102
+ }, []);
103
+ };
104
+
105
+ export const useCurrentForm = (hDialogForm?: HDialogFormInstance) => {
106
+ const defaultHModalForm = useHDialogForm();
107
+ return hDialogForm || defaultHModalForm;
108
+ };
109
+
110
+ export const useSub = ({ request, onFinish }: Partial<DialogFormProps>) => {
111
+ return useRequest(
112
+ async (values, params) => {
113
+ if (onFinish) {
114
+ return onFinish(values, params);
115
+ }
116
+ if (request) {
117
+ return request(values, params);
118
+ }
119
+ },
120
+ { manual: true }
121
+ );
122
+ };
@@ -0,0 +1,44 @@
1
+ import type { ModalProps } from "antd";
2
+ import type { HFormInstance, HItemProps, HFormProps } from "../Form/modal";
3
+ import type { PromiseFnResult } from "../modal";
4
+ import type React from "react";
5
+
6
+ type RootProps = HFormProps & ModalProps;
7
+
8
+ export interface ModifyPropsModal<P = any> {
9
+ configData: HItemProps[];
10
+ visible?: boolean;
11
+ initialValues?: Record<string, any>;
12
+ dialogForm: HDialogFormInstance;
13
+ afterClose?: VoidFunction;
14
+ params?: P;
15
+ title?: DialogFormProps["title"];
16
+ onCancel?: VoidFunction;
17
+ autoClear?: boolean;
18
+ }
19
+ export interface ShowParamsModal<P = any, T = any> {
20
+ configData?: HItemProps[];
21
+ visible?: boolean;
22
+ initialValues?: Record<string, any>;
23
+ infoRequest?: PromiseFnResult<P, T>;
24
+ params?: P;
25
+ title?: DialogFormProps["title"];
26
+ }
27
+
28
+ export interface HDialogFormInstance<P = any, T = any> extends HFormInstance {
29
+ show: (data?: ShowParamsModal<P, T>) => void;
30
+ hide: VoidFunction;
31
+ }
32
+ export interface DialogFormProps<P = any, T = any>
33
+ extends Omit<RootProps, "onFinish" | "onCancel" | "onOk" | "infoRequest"> {
34
+ dialogForm?: HDialogFormInstance;
35
+ onFinish?: (values: T, params: P) => Promise<any>;
36
+ onCancel?: VoidFunction;
37
+ onOk?: (data: T, params: P) => boolean | void;
38
+ infoRequest?: (params: P) => Promise<T>;
39
+ autoClear?: boolean;
40
+ contentRender?: (
41
+ dom: React.ReactNode,
42
+ form: HDialogFormInstance
43
+ ) => React.ReactNode;
44
+ }
@@ -0,0 +1,38 @@
1
+ import { FormConfigContext } from "./index";
2
+ import React, { useContext } from "react";
3
+ import { baseConfig } from "../../config";
4
+ import type { IFormConfigContextProps } from "../modal";
5
+
6
+ export const useFormConfigContext = (key?: string) => {
7
+ const defaultProps = useContext(FormConfigContext);
8
+ if (!key) {
9
+ return Object.keys(defaultProps).length === 0
10
+ ? { ...baseConfig }
11
+ : defaultProps;
12
+ }
13
+ return defaultProps[key] || { ...baseConfig[key] };
14
+ }; //获取配置
15
+ const mergeProps = (props: IFormConfigContextProps) => {
16
+ const newProps = { ...baseConfig };
17
+ const keys = Object.keys(props);
18
+ keys.forEach((key) => {
19
+ const defaultItem = newProps[key];
20
+ if (!defaultItem) {
21
+ return;
22
+ }
23
+ newProps[key] = {
24
+ ...defaultItem,
25
+ ...props[key],
26
+ };
27
+ });
28
+ return newProps;
29
+ };
30
+
31
+ const Index: React.FC<IFormConfigContextProps> = ({ children, ...props }) => {
32
+ return (
33
+ <FormConfigContext.Provider value={mergeProps(props)}>
34
+ {children}
35
+ </FormConfigContext.Provider>
36
+ );
37
+ };
38
+ export default Index;
@@ -0,0 +1,14 @@
1
+ import React, { useContext } from "react";
2
+ import type {
3
+ IFormConfigContextProps,
4
+ FormContextProps,
5
+ } from "@/components/Form/modal";
6
+
7
+ export const FormContext = React.createContext<Partial<FormContextProps>>({});
8
+ export const useFormContext = (): FormContextProps => {
9
+ return useContext(FormContext) as FormContextProps;
10
+ };
11
+
12
+ export const FormConfigContext = React.createContext<IFormConfigContextProps>(
13
+ {}
14
+ );
@@ -0,0 +1,95 @@
1
+ import Label from "../Label";
2
+ import { Form, Space, Col } from "antd";
3
+ import React from "react";
4
+ import Helper from "./Helper";
5
+ import { useClassName } from "../../hooks";
6
+ import { useHide, usePositionClassName } from "./hooks";
7
+ import { useFormContext } from "../Context";
8
+ import type { HItemProps } from "../modal";
9
+ import { useDefaultRender } from "../hooks/useDefaultRender";
10
+ import type { HFormItemProps } from "../modal";
11
+ import { useDefaultComponents } from "../hooks";
12
+ import {useFormConfigContext} from "../Context/FormConfigProvider";
13
+
14
+ interface ContentProps extends Omit<HItemProps, "name"> {
15
+ value?: any;
16
+ onChange?: (val: any) => void;
17
+ }
18
+ const Content: React.FC<ContentProps> = ({
19
+ children,
20
+ helper,
21
+ value,
22
+ onChange,
23
+ }) => {
24
+ const className = useClassName("hw-form-base-item");
25
+ const relChild =
26
+ children && React.cloneElement(children as any, { value, onChange });
27
+ return (
28
+ <Space direction={"vertical"} size={4} style={{ width: "100%" }}>
29
+ <div className={className}>{relChild}</div>
30
+ <Helper helper={helper} />
31
+ </Space>
32
+ );
33
+ };
34
+ const Index: React.FC<HFormItemProps> = (props) => {
35
+ const {
36
+ hover,
37
+ labelWidth,
38
+ required,
39
+ colon = true,
40
+ label,
41
+ itemProps:colItemProps,
42
+ children,
43
+ helper,
44
+ hide,
45
+ render,
46
+ itemSpan = { span: 24 },
47
+ hideLabel = false,
48
+ labelAlign,
49
+ style,
50
+ className:colClassName,
51
+ ...oProps
52
+ } = props;
53
+ const { labelAlign: align = "right",itemProps, ...inProps } = props;
54
+ const { form } = useFormContext();
55
+ const defaultComponent = useDefaultComponents();
56
+ const formItemStyle = useFormConfigContext("formItemStyle");
57
+ const ctxItemProps = useFormConfigContext("itemProps");
58
+ const defaultItemProps={
59
+ ...ctxItemProps,
60
+ ...itemProps
61
+ }
62
+ const defaultRender = useDefaultRender({...inProps,itemProps:defaultItemProps}, defaultComponent);
63
+ const className = usePositionClassName(align);
64
+ const hideItem = useHide({ hide, form });
65
+ if (hideItem) {
66
+ return null;
67
+ }
68
+ return (
69
+ <Col {...itemSpan} className={colClassName}>
70
+ <Form.Item
71
+ className={className}
72
+ label={
73
+ !hideLabel && (
74
+ <Label
75
+ hover={hover}
76
+ labelWidth={labelWidth}
77
+ required={required}
78
+ colon={colon}
79
+ >
80
+ {label}
81
+ </Label>
82
+ )
83
+ }
84
+ {...oProps}
85
+ style={style||formItemStyle}
86
+ colon={false}
87
+ required={false}
88
+ >
89
+ <Content helper={helper}>{defaultRender(form)}</Content>
90
+ </Form.Item>
91
+ </Col>
92
+ );
93
+ };
94
+
95
+ export default Index;
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+ import type { HItemProps, HFormInstance } from "@/components/Form/modal";
3
+ import { Typography } from "antd";
4
+ import { useFormContext } from "../Context";
5
+
6
+ interface HelperProps {
7
+ helper?: HItemProps["helper"];
8
+ }
9
+
10
+ const Index: React.FC<HelperProps> = ({ helper }) => {
11
+ const { form } = useFormContext();
12
+ if (!helper) {
13
+ return null;
14
+ }
15
+ if (typeof helper === "function") {
16
+ return (
17
+ <Typography.Text type={"secondary"}>
18
+ {helper(form as HFormInstance)}
19
+ </Typography.Text>
20
+ );
21
+ }
22
+ return <Typography.Text type={"secondary"}>{helper}</Typography.Text>;
23
+ };
24
+
25
+ export default Index;
@@ -0,0 +1,13 @@
1
+ import BasicItem from "./BasicItem";
2
+ import type { HItemProps } from "../modal";
3
+
4
+ export default (props: HItemProps) => {
5
+ const { type, colon, itemSpan } = props;
6
+ return (
7
+ <BasicItem
8
+ {...props}
9
+ itemSpan={itemSpan}
10
+ colon={type === "submit" ? false : colon}
11
+ />
12
+ );
13
+ };
@@ -0,0 +1,21 @@
1
+ import { Form } from "antd";
2
+ import BasicItem from "./BasicItem";
3
+ import { useShouldUpdate } from "./hooks";
4
+ import type { HFormItemProps } from "../modal";
5
+ const { Item } = Form;
6
+ export default ({
7
+ shouldUpdate,
8
+ dependencies,
9
+ hide,
10
+ itemSpan,
11
+ ...props
12
+ }: HFormItemProps) => {
13
+ const resultShouldUpdate = useShouldUpdate({ shouldUpdate, hide });
14
+ return (
15
+ <Item shouldUpdate={resultShouldUpdate} dependencies={dependencies} noStyle>
16
+ {() => {
17
+ return <BasicItem hide={hide} itemSpan={itemSpan} {...props} />;
18
+ }}
19
+ </Item>
20
+ );
21
+ };
@@ -0,0 +1,54 @@
1
+ import UpFormItem from "./UpFormItem";
2
+ import RegularFormItem from "./RegularFormItem";
3
+ import { useMemo } from "react";
4
+ import type { HFormInstance, HItemProps } from "../modal";
5
+ import type { LabelAlignModal } from "../modal";
6
+ import { useClassName } from "../../hooks";
7
+
8
+ export const useFormItemDomControl = ({
9
+ shouldUpdate,
10
+ hide,
11
+ dependencies,
12
+ }: HItemProps) => {
13
+ return useMemo(() => {
14
+ if (shouldUpdate || typeof hide === "function" || dependencies) {
15
+ return UpFormItem;
16
+ }
17
+ return RegularFormItem;
18
+ }, [shouldUpdate, hide]);
19
+ }; //更新或者不更新组件
20
+
21
+ interface UseHideUpItemModal extends Omit<HItemProps, "name"> {
22
+ form: HFormInstance;
23
+ }
24
+ export const useShouldUpdate = ({
25
+ hide,
26
+ shouldUpdate,
27
+ }: Omit<HItemProps, "name">) => {
28
+ if (typeof hide === "function" && !shouldUpdate) {
29
+ return true;
30
+ }
31
+ return shouldUpdate;
32
+ };
33
+
34
+ export const useHide = ({ hide, form }: UseHideUpItemModal) => {
35
+ if (hide === true) {
36
+ return true;
37
+ }
38
+ if (typeof hide === "function") {
39
+ return hide(form);
40
+ }
41
+ return !!hide;
42
+ };
43
+
44
+ const classNameData = {
45
+ top: "hw-form-base-item-top",
46
+ left: "hw-form-base-item-left",
47
+ right: "hw-form-base-item-right",
48
+ topRight: "hw-form-base-item-top-right",
49
+ topLeft: "hw-form-base-item-top-left",
50
+ };
51
+ export const usePositionClassName = (position: LabelAlignModal) => {
52
+ const className = classNameData[position];
53
+ return useClassName(className);
54
+ };
@@ -0,0 +1,8 @@
1
+ import { useFormItemDomControl } from "./hooks";
2
+ import React from "react";
3
+ import type { HItemProps } from "../modal";
4
+
5
+ export default (props: HItemProps) => {
6
+ const Component = useFormItemDomControl(props);
7
+ return <Component {...props} />;
8
+ };
@@ -0,0 +1,74 @@
1
+ import { useFormContext } from "./Context";
2
+ import type { HFormItemProps } from "@/components/Form/modal";
3
+ import React, { useEffect } from "react";
4
+ import type { ConnectConfigModal } from "@/components/Form/modal";
5
+ import type { addFormatItemModal } from "@/components/Form/modal";
6
+ import type { ConnectResultProps } from "@/components/Form/modal";
7
+ import type { argsFn } from "@/components/Form/modal";
8
+ interface ResultModal {
9
+ inputValue?: (value: Record<string, any>) => Record<string, any>;
10
+ outputValue?: (value: Record<string, any>) => Record<string, any>;
11
+ }
12
+ const formatMaker = (
13
+ itemProps: HFormItemProps,
14
+ formats?: addFormatItemModal
15
+ ) => {
16
+ const { inputValue, outputValue } = formats || {};
17
+ const { initValueProvider = inputValue, subProvider = outputValue } =
18
+ itemProps;
19
+ const resultObj: ResultModal = {};
20
+ if (initValueProvider) {
21
+ resultObj.inputValue = (value) => {
22
+ return initValueProvider(itemProps, value);
23
+ };
24
+ }
25
+ if (subProvider) {
26
+ resultObj.outputValue = (value) => {
27
+ return subProvider(itemProps, value);
28
+ };
29
+ }
30
+ const keysLen = Object.keys(resultObj).length;
31
+ return keysLen === 0 ? undefined : resultObj;
32
+ };
33
+
34
+ export default (
35
+ component:
36
+ | React.FunctionComponent
37
+ | React.ComponentClass
38
+ | React.ForwardRefRenderFunction<any, any>,
39
+ config: ConnectConfigModal = {}
40
+ ) => {
41
+ const { format = {} } = config;
42
+ const Index: React.ForwardRefRenderFunction<any, HFormItemProps> = (
43
+ props: HFormItemProps,
44
+ ref
45
+ ) => {
46
+ const { name = "", dispatch } = props;
47
+
48
+ const { form, valueType = "float" } = useFormContext();
49
+
50
+ useEffect(() => {
51
+ form?.addFormat(name, formatMaker(props, format[valueType]));
52
+ }, [valueType, props]);
53
+
54
+ const addFormat = (aFormat: Record<string, addFormatItemModal>) => {
55
+ form?.addFormat(name, formatMaker(props, aFormat[valueType]));
56
+ };
57
+ const addDispatchListener = (key: string, fn: argsFn) => {
58
+ form?.addDispatchListener({ key, name, dispatch }, fn);
59
+ };
60
+ const Component = component as React.ForwardRefRenderFunction<
61
+ any,
62
+ ConnectResultProps
63
+ >;
64
+ return (
65
+ <Component
66
+ {...props}
67
+ addFormat={addFormat}
68
+ addDispatchListener={addDispatchListener}
69
+ ref={ref}
70
+ />
71
+ );
72
+ };
73
+ return React.forwardRef(Index);
74
+ };
@@ -0,0 +1,10 @@
1
+ import { useFormContext } from "./Context";
2
+ import { useEffect } from "react";
3
+
4
+ export default () => {
5
+ const { form } = useFormContext();
6
+ useEffect(() => {
7
+ form.initValues();
8
+ }, []);
9
+ return <></>;
10
+ };
@@ -0,0 +1,50 @@
1
+ import type { HoverModal } from "./modal";
2
+ import React from "react";
3
+ import { QuestionCircleOutlined } from "@ant-design/icons";
4
+ import { Tooltip } from "antd";
5
+ import { useClassName } from "../hooks";
6
+
7
+ interface IProps {
8
+ labelWidth?: number;
9
+ hover?: string | HoverModal;
10
+ colon?: boolean;
11
+ required?: boolean;
12
+ }
13
+ const useHover = ({ hover }: IProps) => {
14
+ if (!hover || typeof hover === "string") {
15
+ return {
16
+ text: hover,
17
+ icon: <QuestionCircleOutlined />,
18
+ };
19
+ }
20
+ return hover;
21
+ };
22
+ const Index: React.FC<IProps> = ({
23
+ labelWidth,
24
+ children,
25
+ colon,
26
+ required,
27
+ hover,
28
+ }) => {
29
+ const { text, icon } = useHover({ hover });
30
+ const array = [
31
+ colon ? "hw-form-item-colon" : "",
32
+ required ? "hw-form-item-required" : "",
33
+ ];
34
+
35
+ const className = useClassName(array);
36
+ return (
37
+ <div style={{ width: labelWidth }} className={className}>
38
+ {children}
39
+ {text && (
40
+ <span style={{ marginLeft: 4 }}>
41
+ <Tooltip placement="top" title={text}>
42
+ {icon}
43
+ </Tooltip>
44
+ </span>
45
+ )}
46
+ </div>
47
+ );
48
+ };
49
+
50
+ export default Index;
@@ -0,0 +1,58 @@
1
+ import HSelect from "../Select";
2
+ import HInput from "../Input";
3
+ import HInputNumber from "../Input/InputNumber";
4
+ import HSelectInput from "../Input/SelectInput";
5
+ import HButtonInput from "../Input/ButtonInput";
6
+ import HCheckboxGroup from "../CheckboxGroup";
7
+ import HCheckBox from "../CheckboxGroup/CheckBox";
8
+ import HRadioGroup from "../RadioGroup";
9
+ import HSwitch from "../Switch";
10
+ import HDatePicker from "../TDPicker";
11
+ import HRangePicker from "../TDPicker/RangePicker";
12
+ import HTimePicker from "../TDPicker/TimePicker";
13
+ import HUpload from "../Upload";
14
+ import HUrlUpload from "../Upload/UrlUpload";
15
+ import HSubmit from "../Submit";
16
+ import TextArea from "../TextArea";
17
+ import ColorInput from "../Input/ColorInput";
18
+ import Cascader from "../Cascader";
19
+ import VerificationCodeInput from "../Input/VerificationCodeInput";
20
+ import TrimInput from "../Input/TrimInput";
21
+ import TrimTextArea from "../TextArea/TrimTextArea";
22
+ export const placeholderConfig = {
23
+ inputType: [
24
+ "input",
25
+ "inputNumber",
26
+ "selectInput",
27
+ "buttonInput",
28
+ "verificationCodeInput",
29
+ "trimInput",
30
+ "",
31
+ ],
32
+ selectType: ["select", "datePicker", "timePicker", "colorInput"],
33
+ };
34
+ const componentConfig = {
35
+ select: HSelect,
36
+ inputNumber: HInputNumber,
37
+ selectInput: HSelectInput,
38
+ buttonInput: HButtonInput,
39
+ checkboxGroup: HCheckboxGroup,
40
+ checkBox: HCheckBox,
41
+ radioGroup: HRadioGroup,
42
+ switch: HSwitch,
43
+ datePicker: HDatePicker,
44
+ rangePicker: HRangePicker,
45
+ timePicker: HTimePicker,
46
+ input: HInput,
47
+ upload: HUpload,
48
+ urlUpload: HUrlUpload,
49
+ submit: HSubmit,
50
+ textArea: TextArea,
51
+ colorInput: ColorInput,
52
+ cascader: Cascader,
53
+ verificationCodeInput: VerificationCodeInput,
54
+ trimInput: TrimInput,
55
+ trimTextArea: TrimTextArea,
56
+ };
57
+
58
+ export default componentConfig;