@hw-component/form 0.0.3-beta-v4 → 0.0.3-beta-v6
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/Footer.d.ts +1 -2
- package/es/DialogForm/DrawerForm/Title.d.ts +0 -1
- package/es/DialogForm/DrawerForm/index.d.ts +0 -1
- package/es/DialogForm/ModalForm.d.ts +0 -1
- package/es/DialogForm/ModalForm.js +3 -3
- package/es/DialogForm/hooks.d.ts +1 -1
- package/es/DialogForm/hooks.js +3 -3
- package/es/Form/FormItem/BasicItem.d.ts +2 -2
- package/es/Form/FormItem/BasicItem.js +19 -15
- package/es/Form/FormItem/RegularFormItem.d.ts +2 -3
- package/es/Form/FormItem/UpFormItem.d.ts +2 -3
- package/es/Form/FormItem/hooks.d.ts +2 -4
- package/es/Form/FormItem/index.d.ts +2 -3
- package/es/Form/InitSet.d.ts +0 -1
- package/es/Form/config.d.ts +5 -5
- package/es/Form/config.js +10 -10
- package/es/Form/hooks/index.d.ts +1 -0
- package/es/Form/hooks/index.js +20 -3
- package/es/Form/hooks/useDefaultRender.d.ts +3 -0
- package/es/Form/hooks/useDefaultRender.js +49 -0
- package/es/Form/hooks/useInitConfigData.d.ts +2 -2
- package/es/Form/hooks/useInitConfigData.js +26 -45
- package/es/Form/index.d.ts +0 -1
- package/es/Form/modal.d.ts +20 -13
- package/es/Input/ColorInput/Picker.d.ts +3 -0
- package/es/Input/ColorInput/Picker.js +22 -0
- package/es/Input/ColorInput/data.d.ts +1 -0
- package/es/Input/ColorInput/data.js +5 -0
- package/es/Input/ColorInput/index.d.ts +3 -0
- package/es/Input/ColorInput/index.js +76 -0
- package/es/Input/InputNumber.d.ts +0 -1
- package/es/Input/index.d.ts +0 -1
- package/es/Input/modal.d.ts +4 -1
- package/es/PageHandler/ErrorComponent.d.ts +0 -1
- package/es/PageHandler/LoadingComponent.d.ts +0 -1
- package/es/RadioGroup/index.d.ts +0 -1
- package/es/Select/components/NoFindItem.d.ts +0 -1
- package/es/Select/components/NotFoundContent.d.ts +0 -1
- package/es/Select/defaultConfig.d.ts +0 -1
- package/es/Select/hooks/changeHooks.js +4 -0
- package/es/Select/index.d.ts +0 -1
- package/es/Submit/index.d.ts +0 -1
- package/es/TDPicker/TimePicker.d.ts +0 -1
- package/es/TDPicker/index.d.ts +3 -3
- package/es/TDPicker/index.js +6 -5
- package/es/TextArea/index.d.ts +0 -1
- package/es/Upload/Btn.d.ts +0 -1
- package/es/Upload/MediaTypeEle/TypeEle.d.ts +0 -1
- package/es/Upload/MediaTypeEle/index.d.ts +0 -1
- package/es/Upload/Preview/index.d.ts +0 -1
- package/es/Upload/UrlUpload/index.d.ts +0 -1
- package/es/config.js +2 -1
- package/es/index.css +9 -0
- package/es/index.d.ts +3 -2
- package/es/index.js +19 -18
- package/es/modal.d.ts +5 -4
- package/lib/DialogForm/DrawerForm/Footer.d.ts +1 -2
- package/lib/DialogForm/DrawerForm/Title.d.ts +0 -1
- package/lib/DialogForm/DrawerForm/index.d.ts +0 -1
- package/lib/DialogForm/ModalForm.d.ts +0 -1
- package/lib/DialogForm/ModalForm.js +3 -3
- package/lib/DialogForm/hooks.d.ts +1 -1
- package/lib/DialogForm/hooks.js +3 -3
- package/lib/Form/FormItem/BasicItem.d.ts +2 -2
- package/lib/Form/FormItem/BasicItem.js +21 -17
- package/lib/Form/FormItem/RegularFormItem.d.ts +2 -3
- package/lib/Form/FormItem/UpFormItem.d.ts +2 -3
- package/lib/Form/FormItem/hooks.d.ts +2 -4
- package/lib/Form/FormItem/index.d.ts +2 -3
- package/lib/Form/InitSet.d.ts +0 -1
- package/lib/Form/config.d.ts +5 -5
- package/lib/Form/config.js +6 -6
- package/lib/Form/hooks/index.d.ts +1 -0
- package/lib/Form/hooks/index.js +20 -2
- package/lib/Form/hooks/useDefaultRender.d.ts +3 -0
- package/lib/Form/hooks/useDefaultRender.js +50 -0
- package/lib/Form/hooks/useInitConfigData.d.ts +2 -2
- package/lib/Form/hooks/useInitConfigData.js +24 -43
- package/lib/Form/index.d.ts +0 -1
- package/lib/Form/modal.d.ts +20 -13
- package/lib/Input/ColorInput/Picker.d.ts +3 -0
- package/lib/Input/ColorInput/Picker.js +25 -0
- package/lib/Input/ColorInput/data.d.ts +1 -0
- package/lib/Input/ColorInput/data.js +6 -0
- package/lib/Input/ColorInput/index.d.ts +3 -0
- package/lib/Input/ColorInput/index.js +79 -0
- package/lib/Input/InputNumber.d.ts +0 -1
- package/lib/Input/index.d.ts +0 -1
- package/lib/Input/modal.d.ts +4 -1
- package/lib/PageHandler/ErrorComponent.d.ts +0 -1
- package/lib/PageHandler/LoadingComponent.d.ts +0 -1
- package/lib/RadioGroup/index.d.ts +0 -1
- package/lib/Select/components/NoFindItem.d.ts +0 -1
- package/lib/Select/components/NotFoundContent.d.ts +0 -1
- package/lib/Select/defaultConfig.d.ts +0 -1
- package/lib/Select/hooks/changeHooks.js +4 -0
- package/lib/Select/index.d.ts +0 -1
- package/lib/Submit/index.d.ts +0 -1
- package/lib/TDPicker/TimePicker.d.ts +0 -1
- package/lib/TDPicker/index.d.ts +3 -3
- package/lib/TDPicker/index.js +6 -5
- package/lib/TextArea/index.d.ts +0 -1
- package/lib/Upload/Btn.d.ts +0 -1
- package/lib/Upload/MediaTypeEle/TypeEle.d.ts +0 -1
- package/lib/Upload/MediaTypeEle/index.d.ts +0 -1
- package/lib/Upload/Preview/index.d.ts +0 -1
- package/lib/Upload/UrlUpload/index.d.ts +0 -1
- package/lib/config.js +2 -1
- package/lib/index.css +9 -0
- package/lib/index.d.ts +3 -2
- package/lib/index.js +4 -2
- package/lib/modal.d.ts +5 -4
- package/package.json +5 -3
- package/src/components/DialogForm/DrawerForm/Footer.tsx +5 -9
- package/src/components/DialogForm/DrawerForm/index.tsx +5 -5
- package/src/components/DialogForm/ModalForm.tsx +16 -11
- package/src/components/DialogForm/hooks.ts +12 -12
- package/src/components/DialogForm/modal.ts +2 -2
- package/src/components/Form/FormItem/BasicItem.tsx +22 -16
- package/src/components/Form/FormItem/RegularFormItem.tsx +2 -2
- package/src/components/Form/FormItem/UpFormItem.tsx +2 -2
- package/src/components/Form/FormItem/hooks.tsx +2 -6
- package/src/components/Form/FormItem/index.tsx +2 -2
- package/src/components/Form/config.ts +7 -5
- package/src/components/Form/hooks/index.ts +16 -9
- package/src/components/Form/hooks/useDefaultRender.tsx +42 -0
- package/src/components/Form/hooks/useHForm.ts +2 -2
- package/src/components/Form/hooks/useInitConfigData.tsx +44 -35
- package/src/components/Form/modal.ts +28 -17
- package/src/components/Input/ColorInput/Picker.tsx +18 -0
- package/src/components/Input/ColorInput/data.ts +102 -0
- package/src/components/Input/ColorInput/index.less +10 -0
- package/src/components/Input/ColorInput/index.tsx +48 -0
- package/src/components/Input/modal.ts +5 -2
- package/src/components/Select/hooks/changeHooks.tsx +4 -0
- package/src/components/TDPicker/RangePicker.tsx +1 -1
- package/src/components/TDPicker/index.tsx +6 -9
- package/src/components/config.ts +1 -0
- package/src/components/index.tsx +2 -1
- package/src/components/modal.ts +5 -3
- package/src/components/styles/index.less +1 -0
- package/src/pages/Form/index.tsx +16 -1
- package/src/pages/Input/index.tsx +2 -0
- package/src/pages/ModalForm/index.tsx +9 -9
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import React, { useMemo } from "react";
|
|
2
2
|
import type {
|
|
3
|
-
FormItemWithRender,
|
|
4
3
|
HFormItemProps,
|
|
5
4
|
HFormProps,
|
|
6
5
|
HItemProps,
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
DefaultComponentModal,
|
|
7
|
+
} from "../modal";
|
|
8
|
+
import { placeholderConfig } from "../config";
|
|
9
9
|
import type { Rule } from "rc-field-form/lib/interface";
|
|
10
10
|
import type { FormInstance } from "antd";
|
|
11
|
+
import { useDefaultComponents } from "../hooks";
|
|
12
|
+
import type { ConfigComponentModal } from "../modal";
|
|
11
13
|
|
|
12
|
-
const mathRequired = (
|
|
14
|
+
const mathRequired = (
|
|
15
|
+
configItem: HFormItemProps,
|
|
16
|
+
form: FormInstance,
|
|
17
|
+
defaultComponents: DefaultComponentModal
|
|
18
|
+
) => {
|
|
13
19
|
const { required, placeholder, rules, type = "input" } = configItem;
|
|
14
20
|
let resultRequired = false;
|
|
15
|
-
const dom =
|
|
21
|
+
const dom = defaultComponents[type];
|
|
16
22
|
const resultRules = rules?.map((item) => {
|
|
17
23
|
let eachItem = item;
|
|
18
24
|
if (typeof item === "function") {
|
|
@@ -24,12 +30,15 @@ const mathRequired = (configItem: HFormItemProps, form: FormInstance) => {
|
|
|
24
30
|
resultRequired = itemRequired;
|
|
25
31
|
}
|
|
26
32
|
if (itemRequired && !message) {
|
|
33
|
+
let msg = placeholder;
|
|
34
|
+
const itemDom = dom as ConfigComponentModal;
|
|
35
|
+
if (itemDom?.requiredErrMsg) {
|
|
36
|
+
msg = itemDom.requiredErrMsg(configItem);
|
|
37
|
+
}
|
|
27
38
|
return {
|
|
28
39
|
...eachItem,
|
|
29
40
|
required: itemRequired,
|
|
30
|
-
message:
|
|
31
|
-
? dom.requiredErrMsg(configItem)
|
|
32
|
-
: placeholder,
|
|
41
|
+
message: msg,
|
|
33
42
|
};
|
|
34
43
|
}
|
|
35
44
|
return eachItem;
|
|
@@ -39,50 +48,49 @@ const mathRequired = (configItem: HFormItemProps, form: FormInstance) => {
|
|
|
39
48
|
rules: resultRules as Rule[],
|
|
40
49
|
};
|
|
41
50
|
}; //是否必填
|
|
42
|
-
const matchDefaultPlaceholder = (
|
|
51
|
+
const matchDefaultPlaceholder = (
|
|
52
|
+
props: HFormItemProps,
|
|
53
|
+
defaultComponents: DefaultComponentModal
|
|
54
|
+
) => {
|
|
43
55
|
const { label, placeholder, type = "input" } = props;
|
|
44
|
-
const dom =
|
|
56
|
+
const dom = defaultComponents[type];
|
|
45
57
|
if (placeholder) {
|
|
46
58
|
return placeholder;
|
|
47
59
|
}
|
|
48
|
-
|
|
49
|
-
|
|
60
|
+
const itemDom = dom as ConfigComponentModal;
|
|
61
|
+
if (itemDom?.placeholder) {
|
|
62
|
+
return itemDom.placeholder(props);
|
|
50
63
|
}
|
|
51
64
|
if (placeholderConfig.inputType.indexOf(type) !== -1) {
|
|
52
65
|
return `请输入${label}`;
|
|
53
66
|
}
|
|
54
67
|
return `请选择${label}`;
|
|
55
68
|
}; //自动构建
|
|
56
|
-
const defaultRenderMaker = (props: HFormItemProps) => {
|
|
57
|
-
const { render, type = "input", itemProps = {}, ...componentProps } = props;
|
|
58
|
-
const dom = FormConfig[type];
|
|
59
|
-
return (form: FormInstance) => {
|
|
60
|
-
const Component = !!dom?.Component ? dom.Component : dom;
|
|
61
|
-
const node = Component && (
|
|
62
|
-
<Component {...componentProps} {...itemProps} form={form} />
|
|
63
|
-
);
|
|
64
|
-
if (render) {
|
|
65
|
-
const resultNode=render(props, node, form);
|
|
66
|
-
return React.cloneElement<any>((resultNode as any),{...componentProps,...itemProps,form})
|
|
67
|
-
}
|
|
68
|
-
return node;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
69
|
|
|
72
|
-
const defaultPlaceholderPropsMaker = (
|
|
73
|
-
|
|
70
|
+
const defaultPlaceholderPropsMaker = (
|
|
71
|
+
props: HFormItemProps,
|
|
72
|
+
defaultComponents: DefaultComponentModal
|
|
73
|
+
) => {
|
|
74
|
+
const placeholder = matchDefaultPlaceholder(props, defaultComponents);
|
|
74
75
|
return {
|
|
75
76
|
...props,
|
|
76
77
|
placeholder,
|
|
77
|
-
render: defaultRenderMaker({ ...props, placeholder }),
|
|
78
78
|
};
|
|
79
79
|
}; //组装参数
|
|
80
80
|
const itemControl = (
|
|
81
81
|
item: HItemProps,
|
|
82
|
-
form: FormInstance
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const {
|
|
82
|
+
form: FormInstance,
|
|
83
|
+
defaultComponents: DefaultComponentModal
|
|
84
|
+
): HFormItemProps => {
|
|
85
|
+
const { render, ...defaultProps } = defaultPlaceholderPropsMaker(
|
|
86
|
+
item,
|
|
87
|
+
defaultComponents
|
|
88
|
+
);
|
|
89
|
+
const { rules, required } = mathRequired(
|
|
90
|
+
defaultProps,
|
|
91
|
+
form,
|
|
92
|
+
defaultComponents
|
|
93
|
+
);
|
|
86
94
|
return {
|
|
87
95
|
...defaultProps,
|
|
88
96
|
required,
|
|
@@ -93,9 +101,10 @@ const itemControl = (
|
|
|
93
101
|
type InitConfigModal = Required<Pick<HFormProps, "configData" | "form">>;
|
|
94
102
|
|
|
95
103
|
export default ({ configData, form }: InitConfigModal) => {
|
|
104
|
+
const defaultComponents = useDefaultComponents();
|
|
96
105
|
return useMemo(() => {
|
|
97
106
|
return configData.map((item) => {
|
|
98
|
-
return itemControl(item, form);
|
|
107
|
+
return itemControl(item, form, defaultComponents);
|
|
99
108
|
});
|
|
100
109
|
}, [configData]);
|
|
101
110
|
};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import type { FormInstance, FormItemProps, FormProps } from "antd";
|
|
2
|
-
import type { HCheckboxProps } from "
|
|
2
|
+
import type { HCheckboxProps } from "../CheckboxGroup/modal";
|
|
3
3
|
import type React from "react";
|
|
4
4
|
import type {
|
|
5
5
|
HButtonProps,
|
|
6
6
|
HInputProps,
|
|
7
7
|
HSelectInputProps,
|
|
8
|
-
} from "
|
|
9
|
-
import type { HRadioGroupProps } from "
|
|
10
|
-
import type { HSelectProps } from "
|
|
8
|
+
} from "../Input/modal";
|
|
9
|
+
import type { HRadioGroupProps } from "../RadioGroup";
|
|
10
|
+
import type { HSelectProps } from "../Select/modal";
|
|
11
11
|
import type { ButtonProps } from "antd/es";
|
|
12
|
-
import type { HSwitchProps } from "
|
|
12
|
+
import type { HSwitchProps } from "../Switch";
|
|
13
13
|
import type {
|
|
14
14
|
HDatePickerProps,
|
|
15
15
|
HRangePickerProps,
|
|
16
16
|
HTimePickerProps,
|
|
17
|
-
} from "
|
|
17
|
+
} from "../TDPicker/modal";
|
|
18
18
|
import type { TextAreaProps } from "antd/es/input";
|
|
19
|
-
import type { IUpLoadProps } from "
|
|
19
|
+
import type { IUpLoadProps } from "../Upload/modal";
|
|
20
20
|
import type { SelectProps } from "antd";
|
|
21
21
|
import type { RangePickerProps } from "antd/es/date-picker";
|
|
22
22
|
import type {
|
|
@@ -26,6 +26,7 @@ import type {
|
|
|
26
26
|
DateRangePickerValueMapModal,
|
|
27
27
|
} from "../modal";
|
|
28
28
|
import type { ForwardedRef } from "react";
|
|
29
|
+
import type { DataFnProvider } from "../modal";
|
|
29
30
|
type RenderFun = (
|
|
30
31
|
props: HItemProps,
|
|
31
32
|
node: React.ReactNode,
|
|
@@ -70,15 +71,16 @@ export interface HItemProps extends Omit<FormItemProps, "name"> {
|
|
|
70
71
|
name?: string;
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
export interface HFormProps<T = any, R = any>
|
|
74
|
+
export interface HFormProps<T = any, R = any>
|
|
75
|
+
extends Omit<FormProps, "form" | "onFinish"> {
|
|
74
76
|
configData: HItemProps[];
|
|
75
77
|
labelWidth?: number;
|
|
76
|
-
request?: (values:T,params?:any)=>Promise<R>;
|
|
78
|
+
request?: (values: T, params?: any) => Promise<R>;
|
|
77
79
|
infoRequest?: PromiseFnResult;
|
|
78
80
|
valueType?: string;
|
|
79
81
|
form?: HFormInstance;
|
|
80
82
|
params?: any;
|
|
81
|
-
onFinish?:(values:T,params?:any)=>void;
|
|
83
|
+
onFinish?: (values: T, params?: any) => void;
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
export interface HFormItemProps extends HItemProps {
|
|
@@ -86,9 +88,6 @@ export interface HFormItemProps extends HItemProps {
|
|
|
86
88
|
value?: any;
|
|
87
89
|
onChange?: (val: any, item: any) => void;
|
|
88
90
|
}
|
|
89
|
-
export interface FormItemWithRender extends Omit<HFormItemProps, "render"> {
|
|
90
|
-
render: (form: HFormInstance) => React.ReactNode;
|
|
91
|
-
}
|
|
92
91
|
export type argsFn = (...args: any[]) => void;
|
|
93
92
|
export interface FormContextProps {
|
|
94
93
|
loading?: boolean;
|
|
@@ -100,7 +99,18 @@ interface ConfigUploadProps {
|
|
|
100
99
|
maxSize?: number;
|
|
101
100
|
request?: PromiseFnResult;
|
|
102
101
|
}
|
|
102
|
+
export type ComponentModal =
|
|
103
|
+
| React.FunctionComponent<any>
|
|
104
|
+
| React.ComponentClass<any>
|
|
105
|
+
| React.ForwardRefExoticComponent<any>;
|
|
103
106
|
|
|
107
|
+
export interface ConfigComponentModal {
|
|
108
|
+
Component: ComponentModal;
|
|
109
|
+
placeholder?: DataFnProvider<HItemProps>;
|
|
110
|
+
requiredErrMsg?: DataFnProvider<HItemProps>;
|
|
111
|
+
}
|
|
112
|
+
export type DefaultComponentItemModal = ComponentModal | ConfigComponentModal;
|
|
113
|
+
export type DefaultComponentModal = Record<string, DefaultComponentItemModal>;
|
|
104
114
|
export interface IFormConfigContextProps {
|
|
105
115
|
fieldNames?: SelectProps["fieldNames"];
|
|
106
116
|
valueCheckMap?: ValueCheckMapModal;
|
|
@@ -108,6 +118,7 @@ export interface IFormConfigContextProps {
|
|
|
108
118
|
valueRangePickerValueMap?: DateRangePickerValueMapModal;
|
|
109
119
|
dateRanges?: RangePickerProps["ranges"];
|
|
110
120
|
uploadProps?: ConfigUploadProps;
|
|
121
|
+
defaultComponent?: DefaultComponentModal;
|
|
111
122
|
}
|
|
112
123
|
interface ActionModal {
|
|
113
124
|
key: string;
|
|
@@ -124,7 +135,7 @@ export interface HFormInstance extends FormInstance {
|
|
|
124
135
|
outputValues: (values?: Record<string, any>) => Record<string, any>;
|
|
125
136
|
addDispatchListener: AddDispatchListenerFn;
|
|
126
137
|
removeDispatchListener: (action?: ActionModal, fn?: argsFn) => void;
|
|
127
|
-
reload:PromiseFnResult;
|
|
138
|
+
reload: PromiseFnResult;
|
|
128
139
|
}
|
|
129
140
|
|
|
130
141
|
export interface ConnectConfigModal {
|
|
@@ -138,14 +149,14 @@ export interface FormatItemModal {
|
|
|
138
149
|
outputValue: ValueFormat;
|
|
139
150
|
}
|
|
140
151
|
|
|
141
|
-
type
|
|
152
|
+
type AddValueFormat = (
|
|
142
153
|
item: HFormItemProps,
|
|
143
154
|
value: Record<string, any>
|
|
144
155
|
) => Record<string, any>;
|
|
145
156
|
|
|
146
157
|
export interface addFormatItemModal {
|
|
147
|
-
inputValue:
|
|
148
|
-
outputValue:
|
|
158
|
+
inputValue: AddValueFormat;
|
|
159
|
+
outputValue: AddValueFormat;
|
|
149
160
|
}
|
|
150
161
|
|
|
151
162
|
export interface ConnectResultProps extends HFormItemProps {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SketchPicker } from "react-color";
|
|
2
|
+
import type { HInputProps } from "@/components/Input/modal";
|
|
3
|
+
import { presetColors } from "./data";
|
|
4
|
+
import { useClassName } from "../../hooks";
|
|
5
|
+
|
|
6
|
+
export default ({ value, onChange }: HInputProps) => {
|
|
7
|
+
const classname = useClassName("hw-color-input-picker");
|
|
8
|
+
return (
|
|
9
|
+
<SketchPicker
|
|
10
|
+
width={"250px"}
|
|
11
|
+
styles={{}}
|
|
12
|
+
presetColors={presetColors}
|
|
13
|
+
color={value}
|
|
14
|
+
onChangeComplete={onChange}
|
|
15
|
+
className={classname}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export const presetColors = [
|
|
2
|
+
"#fff1f0",
|
|
3
|
+
"#ffccc7",
|
|
4
|
+
"#ffa39e",
|
|
5
|
+
"#ff7875",
|
|
6
|
+
"#ff4d4f",
|
|
7
|
+
"#f5222d",
|
|
8
|
+
"#cf1322",
|
|
9
|
+
"#a8071a",
|
|
10
|
+
"#820014",
|
|
11
|
+
"#5c0011",
|
|
12
|
+
"#fff7e6",
|
|
13
|
+
"#ffe7ba",
|
|
14
|
+
"#ffd591",
|
|
15
|
+
"#ffc069",
|
|
16
|
+
"#ffa940",
|
|
17
|
+
"#fa8c16",
|
|
18
|
+
"#d46b08",
|
|
19
|
+
"#ad4e00",
|
|
20
|
+
"#873800",
|
|
21
|
+
"#612500",
|
|
22
|
+
"#feffe6",
|
|
23
|
+
"#ffffb8",
|
|
24
|
+
"#fffb8f",
|
|
25
|
+
"#fff566",
|
|
26
|
+
"#ffec3d",
|
|
27
|
+
"#fadb14",
|
|
28
|
+
"#d4b106",
|
|
29
|
+
"#ad8b00",
|
|
30
|
+
"#876800",
|
|
31
|
+
"#614700",
|
|
32
|
+
"#f6ffed",
|
|
33
|
+
"#d9f7be",
|
|
34
|
+
"#b7eb8f",
|
|
35
|
+
"#95de64",
|
|
36
|
+
"#73d13d",
|
|
37
|
+
"#52c41a",
|
|
38
|
+
"#389e0d",
|
|
39
|
+
"#237804",
|
|
40
|
+
"#135200",
|
|
41
|
+
"#092b00",
|
|
42
|
+
"#e6fffb",
|
|
43
|
+
"#b5f5ec",
|
|
44
|
+
"#87e8de",
|
|
45
|
+
"#5cdbd3",
|
|
46
|
+
"#36cfc9",
|
|
47
|
+
"#13c2c2",
|
|
48
|
+
"#08979c",
|
|
49
|
+
"#006d75",
|
|
50
|
+
"#00474f",
|
|
51
|
+
"#002329",
|
|
52
|
+
"#e6f7ff",
|
|
53
|
+
"#bae7ff",
|
|
54
|
+
"#91d5ff",
|
|
55
|
+
"#69c0ff",
|
|
56
|
+
"#40a9ff",
|
|
57
|
+
"#1890ff",
|
|
58
|
+
"#096dd9",
|
|
59
|
+
"#0050b3",
|
|
60
|
+
"#003a8c",
|
|
61
|
+
"#002766",
|
|
62
|
+
"#f0f5ff",
|
|
63
|
+
"#d6e4ff",
|
|
64
|
+
"#adc6ff",
|
|
65
|
+
"#85a5ff",
|
|
66
|
+
"#597ef7",
|
|
67
|
+
"#2f54eb",
|
|
68
|
+
"#1d39c4",
|
|
69
|
+
"#10239e",
|
|
70
|
+
"#061178",
|
|
71
|
+
"#030852",
|
|
72
|
+
"#f9f0ff",
|
|
73
|
+
"#efdbff",
|
|
74
|
+
"#d3adf7",
|
|
75
|
+
"#b37feb",
|
|
76
|
+
"#9254de",
|
|
77
|
+
"#722ed1",
|
|
78
|
+
"#531dab",
|
|
79
|
+
"#391085",
|
|
80
|
+
"#22075e",
|
|
81
|
+
"#120338",
|
|
82
|
+
"#fff0f6",
|
|
83
|
+
"#ffd6e7",
|
|
84
|
+
"#ffadd2",
|
|
85
|
+
"#ff85c0",
|
|
86
|
+
"#f759ab",
|
|
87
|
+
"#eb2f96",
|
|
88
|
+
"#c41d7f",
|
|
89
|
+
"#9e1068",
|
|
90
|
+
"#780650",
|
|
91
|
+
"#520339",
|
|
92
|
+
"#ffffff",
|
|
93
|
+
"#fafafa",
|
|
94
|
+
"#f5f5f5",
|
|
95
|
+
"#f0f0f0",
|
|
96
|
+
"#d9d9d9",
|
|
97
|
+
"#bfbfbf",
|
|
98
|
+
"#8c8c8c",
|
|
99
|
+
"#595959",
|
|
100
|
+
"#434343",
|
|
101
|
+
"#262626",
|
|
102
|
+
];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { HInputProps } from "@/components/Input/modal";
|
|
2
|
+
import { Input, Popover } from "antd";
|
|
3
|
+
import Picker from "./Picker";
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
import { useClassName } from "../../hooks";
|
|
6
|
+
export default ({ value, onChange, ...props }: HInputProps) => {
|
|
7
|
+
const classname = useClassName("hw-color-box");
|
|
8
|
+
const pickerValue = useMemo(() => {
|
|
9
|
+
if (typeof value === "string") {
|
|
10
|
+
if (value.startsWith("#")) {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
const rgbaRegular = /(?<=(rgba\())(?<rgba>.*?)(?=(\)))/;
|
|
14
|
+
const result = value.match(rgbaRegular);
|
|
15
|
+
if (result?.groups?.rgba) {
|
|
16
|
+
const rgbas = result.groups.rgba.split(",");
|
|
17
|
+
return {
|
|
18
|
+
r: Number(rgbas[0]),
|
|
19
|
+
g: Number(rgbas[1]),
|
|
20
|
+
b: Number(rgbas[2]),
|
|
21
|
+
a: Number(rgbas[3]),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return "";
|
|
26
|
+
}, [value]);
|
|
27
|
+
const colorChange = (val) => {
|
|
28
|
+
const { rgb } = val;
|
|
29
|
+
const text = `rgba(${rgb.r},${rgb.g},${rgb.b},${rgb.a})`;
|
|
30
|
+
onChange?.(text);
|
|
31
|
+
};
|
|
32
|
+
return (
|
|
33
|
+
<Input
|
|
34
|
+
{...props}
|
|
35
|
+
value={value}
|
|
36
|
+
onChange={onChange}
|
|
37
|
+
suffix={
|
|
38
|
+
<Popover
|
|
39
|
+
trigger="click"
|
|
40
|
+
content={<Picker value={pickerValue} onChange={colorChange} />}
|
|
41
|
+
placement="topLeft"
|
|
42
|
+
>
|
|
43
|
+
<div style={{ backgroundColor: value }} className={classname} />
|
|
44
|
+
</Popover>
|
|
45
|
+
}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
@@ -4,8 +4,11 @@ import type { SelectInputType } from "./SelectInput";
|
|
|
4
4
|
import type { PromiseFnResult } from "../modal";
|
|
5
5
|
import type { addFormatItemModal } from "../Form/modal";
|
|
6
6
|
import type { AddDispatchListenerFn } from "../Form/modal";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
export interface HInputProps<V = any>
|
|
8
|
+
extends Omit<InputProps, "onChange" | "value"> {
|
|
9
|
+
onChange?: (value: V) => void;
|
|
10
|
+
value?: V;
|
|
11
|
+
}
|
|
9
12
|
|
|
10
13
|
interface ValueNameModal {
|
|
11
14
|
input?: string;
|
|
@@ -138,6 +138,10 @@ export const useValueChange = (params: PartialHSelectProps) => {
|
|
|
138
138
|
onChange(newChangeVal, subItemOps);
|
|
139
139
|
};
|
|
140
140
|
useEffect(() => {
|
|
141
|
+
if (mode === "tags") {
|
|
142
|
+
setVal(value);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
141
145
|
if (options && value) {
|
|
142
146
|
setVal((oldVale) => {
|
|
143
147
|
return matchNotFind(params, oldVale);
|
|
@@ -11,7 +11,7 @@ import { useMatchConfigProps } from "../hooks";
|
|
|
11
11
|
import type { HItemProps } from "../Form/modal";
|
|
12
12
|
import HFormConnect from "../Form/HFormConnect";
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const RangePicker = DatePicker.RangePicker as any;
|
|
15
15
|
|
|
16
16
|
const HRangePicker: React.FC<HRangePickerProps> = ({
|
|
17
17
|
value,
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import { DatePicker } from "antd";
|
|
2
2
|
import type { HDatePickerProps } from "./modal";
|
|
3
3
|
import { useTimeChange, useTimeVal } from "./hooks";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import React from "react";
|
|
5
|
+
const Picker = DatePicker as any;
|
|
6
|
+
const Index: React.FC<HDatePickerProps> = ({
|
|
6
7
|
value,
|
|
7
8
|
onChange,
|
|
8
9
|
showTime = true,
|
|
9
10
|
format = "X",
|
|
10
11
|
...props
|
|
11
|
-
}
|
|
12
|
+
}) => {
|
|
12
13
|
const timeVal = useTimeVal({ value, format });
|
|
13
14
|
const change = useTimeChange({ format, onChange });
|
|
14
15
|
return (
|
|
15
|
-
<
|
|
16
|
-
value={timeVal}
|
|
17
|
-
onChange={change}
|
|
18
|
-
showTime={showTime}
|
|
19
|
-
{...props}
|
|
20
|
-
/>
|
|
16
|
+
<Picker value={timeVal} onChange={change} showTime={showTime} {...props} />
|
|
21
17
|
);
|
|
22
18
|
};
|
|
19
|
+
export default Index;
|
package/src/components/config.ts
CHANGED
package/src/components/index.tsx
CHANGED
|
@@ -5,6 +5,7 @@ export { default as HForm } from "./Form";
|
|
|
5
5
|
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
|
+
export { default as HFormConfigProvider } from "./Form/Context/FormConfigProvider";
|
|
8
9
|
|
|
9
10
|
import ModalForm from "./DialogForm/ModalForm";
|
|
10
11
|
import DrawerForm from "./DialogForm/DrawerForm";
|
|
@@ -23,7 +24,7 @@ export const HRadioGroup = FormConfig.radioGroup;
|
|
|
23
24
|
export const HTimePicker = FormConfig.timePicker;
|
|
24
25
|
export const HInputNumber = FormConfig.inputNumber;
|
|
25
26
|
export const HPageHandler = PageHandler;
|
|
26
|
-
export const HFormConfigProvider = FormConfig.formConfigProvider;
|
|
27
27
|
export const HTextArea = FormConfig.textArea;
|
|
28
|
+
export const HColorInput = FormConfig.colorInput;
|
|
28
29
|
export const HModalForm = ModalForm;
|
|
29
30
|
export const HDrawerForm = DrawerForm;
|
package/src/components/modal.ts
CHANGED
|
@@ -7,9 +7,11 @@ export interface ValueSwitchMapModal {
|
|
|
7
7
|
open?: any;
|
|
8
8
|
close?: any;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
export interface DataFnProvider<P = any, R = any> {
|
|
11
|
+
(name: P): R;
|
|
12
|
+
}
|
|
11
13
|
|
|
12
14
|
export interface DateRangePickerValueMapModal {
|
|
13
|
-
start?: string |
|
|
14
|
-
end?: string |
|
|
15
|
+
start?: string | DataFnProvider<string, string>;
|
|
16
|
+
end?: string | DataFnProvider<string, string>;
|
|
15
17
|
}
|
package/src/pages/Form/index.tsx
CHANGED
|
@@ -96,11 +96,22 @@ const data = [
|
|
|
96
96
|
type: "urlUpload",
|
|
97
97
|
rules: [{ required: true }],
|
|
98
98
|
},
|
|
99
|
+
{
|
|
100
|
+
label: "颜色",
|
|
101
|
+
name: "colorInput",
|
|
102
|
+
type: "colorInput",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
label: "测试",
|
|
106
|
+
type: "test",
|
|
107
|
+
},
|
|
99
108
|
{
|
|
100
109
|
type: "submit",
|
|
101
110
|
},
|
|
102
111
|
];
|
|
103
|
-
|
|
112
|
+
const Test = (props) => {
|
|
113
|
+
return <div>ffff</div>;
|
|
114
|
+
};
|
|
104
115
|
export default () => {
|
|
105
116
|
const form = useHForm();
|
|
106
117
|
return (
|
|
@@ -108,6 +119,9 @@ export default () => {
|
|
|
108
119
|
<HFormConfigProvider
|
|
109
120
|
valueSwitchMap={{ open: 1, close: 2 }}
|
|
110
121
|
valueCheckMap={{ noChecked: 0, checked: 1 }}
|
|
122
|
+
defaultComponent={{
|
|
123
|
+
test: Test,
|
|
124
|
+
}}
|
|
111
125
|
>
|
|
112
126
|
<HForm
|
|
113
127
|
configData={data}
|
|
@@ -128,6 +142,7 @@ export default () => {
|
|
|
128
142
|
testEnd: "1693538359",
|
|
129
143
|
op: 1,
|
|
130
144
|
opInput: "12121",
|
|
145
|
+
colorInput: "rgba(24, 144, 255,1)",
|
|
131
146
|
upload:
|
|
132
147
|
"https://img2.baidu.com/it/u=2048195462,703560066&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=333",
|
|
133
148
|
});
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
HSelectInput,
|
|
4
4
|
HButtonInput,
|
|
5
5
|
HInputNumber,
|
|
6
|
+
HColorInput,
|
|
6
7
|
} from "../../components";
|
|
7
8
|
import { Space } from "antd";
|
|
8
9
|
export default () => {
|
|
@@ -17,6 +18,7 @@ export default () => {
|
|
|
17
18
|
/>
|
|
18
19
|
<HButtonInput>点我</HButtonInput>
|
|
19
20
|
<HInputNumber />
|
|
21
|
+
<HColorInput />
|
|
20
22
|
</Space>
|
|
21
23
|
);
|
|
22
24
|
};
|
|
@@ -97,18 +97,18 @@ const data = [
|
|
|
97
97
|
rules: [{ required: true }],
|
|
98
98
|
},
|
|
99
99
|
];
|
|
100
|
-
let num=0;
|
|
100
|
+
let num = 0;
|
|
101
101
|
export default () => {
|
|
102
102
|
const modalForm = useHDialogForm();
|
|
103
103
|
return (
|
|
104
104
|
<>
|
|
105
105
|
<Button
|
|
106
106
|
onClick={() => {
|
|
107
|
-
num
|
|
107
|
+
num++;
|
|
108
108
|
modalForm.show({
|
|
109
|
-
params:{
|
|
110
|
-
name:num
|
|
111
|
-
}
|
|
109
|
+
params: {
|
|
110
|
+
name: num,
|
|
111
|
+
},
|
|
112
112
|
});
|
|
113
113
|
}}
|
|
114
114
|
>
|
|
@@ -117,18 +117,18 @@ export default () => {
|
|
|
117
117
|
<HModalForm
|
|
118
118
|
configData={data}
|
|
119
119
|
labelWidth={88}
|
|
120
|
-
request={(val,params)=>{
|
|
121
|
-
|
|
120
|
+
request={(val, params) => {
|
|
121
|
+
console.log(val, params);
|
|
122
122
|
}}
|
|
123
123
|
infoRequest={(ppp) => {
|
|
124
|
-
console.log(ppp)
|
|
124
|
+
console.log(ppp);
|
|
125
125
|
return Promise.resolve({
|
|
126
126
|
check1: 1,
|
|
127
127
|
testStart: "1694747960",
|
|
128
128
|
testEnd: "1693538359",
|
|
129
129
|
op: 1,
|
|
130
130
|
opInput: "12121",
|
|
131
|
-
name:ppp.name
|
|
131
|
+
name: ppp.name,
|
|
132
132
|
});
|
|
133
133
|
}}
|
|
134
134
|
dialogForm={modalForm}
|