@hw-component/form 0.0.1 → 0.0.3
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/LICENSE +201 -0
- package/es/CheckboxGroup/CheckBox/index.d.ts +7 -0
- package/es/CheckboxGroup/CheckBox/index.js +36 -0
- package/es/CheckboxGroup/hooks.d.ts +5 -0
- package/es/CheckboxGroup/hooks.js +124 -0
- package/es/CheckboxGroup/index.d.ts +4 -0
- package/es/CheckboxGroup/index.js +49 -0
- package/es/DatePicker/RangePicker.d.ts +4 -0
- package/es/DatePicker/RangePicker.js +23 -0
- package/es/DatePicker/index.d.ts +4 -0
- package/es/DatePicker/index.js +39 -0
- package/es/Input/ButtonInput.d.ts +4 -0
- package/es/Input/ButtonInput.js +80 -0
- package/es/Input/InputNumber.d.ts +4 -0
- package/es/Input/InputNumber.js +20 -0
- package/es/Input/SelectInput.d.ts +8 -0
- package/es/Input/SelectInput.js +67 -0
- package/es/Input/defaultConfig.d.ts +7 -0
- package/es/Input/defaultConfig.js +11 -0
- package/es/Input/index.d.ts +4 -0
- package/es/Input/index.js +13 -0
- package/es/RadioGroup/index.d.ts +9 -0
- package/es/RadioGroup/index.js +44 -0
- package/es/Select/components/AllSelect.d.ts +2 -1
- package/es/Select/components/AllSelect.js +9 -5
- package/es/Select/defaultConfig.d.ts +0 -1
- package/es/Select/defaultConfig.js +1 -5
- package/es/Select/hooks/changeHooks.d.ts +1 -1
- package/es/Select/hooks/changeHooks.js +8 -3
- package/es/Select/hooks/norHooks.d.ts +2 -5
- package/es/Select/hooks/norHooks.js +12 -34
- package/es/Select/index.js +12 -7
- package/es/Select/modal.d.ts +1 -2
- package/es/Select/utils.d.ts +2 -0
- package/es/Select/utils.js +39 -0
- package/es/Switch/index.d.ts +10 -0
- package/es/Switch/index.js +41 -0
- package/es/TimePicker/index.d.ts +2 -0
- package/es/config.d.ts +15 -0
- package/es/config.js +19 -0
- package/es/hooks/useChangeOptions.d.ts +10 -0
- package/es/hooks/useChangeOptions.js +25 -0
- package/es/hooks/useClassName.d.ts +1 -0
- package/es/hooks/useClassName.js +14 -0
- package/es/index.css +1 -1
- package/es/index.d.ts +11 -1
- package/es/index.js +10 -0
- package/lib/CheckboxGroup/CheckBox/index.d.ts +7 -0
- package/lib/CheckboxGroup/CheckBox/index.js +39 -0
- package/lib/CheckboxGroup/hooks.d.ts +5 -0
- package/lib/CheckboxGroup/hooks.js +125 -0
- package/lib/CheckboxGroup/index.d.ts +4 -0
- package/lib/CheckboxGroup/index.js +52 -0
- package/lib/DatePicker/RangePicker.d.ts +4 -0
- package/lib/DatePicker/RangePicker.js +26 -0
- package/lib/DatePicker/index.d.ts +4 -0
- package/lib/DatePicker/index.js +42 -0
- package/lib/Input/ButtonInput.d.ts +4 -0
- package/lib/Input/ButtonInput.js +83 -0
- package/lib/Input/InputNumber.d.ts +4 -0
- package/lib/Input/InputNumber.js +23 -0
- package/lib/Input/SelectInput.d.ts +8 -0
- package/lib/Input/SelectInput.js +70 -0
- package/lib/Input/defaultConfig.d.ts +7 -0
- package/lib/Input/defaultConfig.js +13 -0
- package/lib/Input/index.d.ts +4 -0
- package/lib/Input/index.js +16 -0
- package/lib/RadioGroup/index.d.ts +9 -0
- package/lib/RadioGroup/index.js +47 -0
- package/lib/Select/components/AllSelect.d.ts +2 -1
- package/lib/Select/components/AllSelect.js +9 -5
- package/lib/Select/defaultConfig.d.ts +0 -1
- package/lib/Select/defaultConfig.js +0 -5
- package/lib/Select/hooks/changeHooks.d.ts +1 -1
- package/lib/Select/hooks/changeHooks.js +8 -3
- package/lib/Select/hooks/norHooks.d.ts +2 -5
- package/lib/Select/hooks/norHooks.js +12 -34
- package/lib/Select/index.js +11 -6
- package/lib/Select/modal.d.ts +1 -2
- package/lib/Select/utils.d.ts +2 -0
- package/lib/Select/utils.js +41 -0
- package/lib/Switch/index.d.ts +10 -0
- package/lib/Switch/index.js +44 -0
- package/lib/TimePicker/index.d.ts +2 -0
- package/lib/config.d.ts +15 -0
- package/lib/config.js +20 -0
- package/lib/hooks/useChangeOptions.d.ts +10 -0
- package/lib/hooks/useChangeOptions.js +26 -0
- package/lib/hooks/useClassName.d.ts +1 -0
- package/lib/hooks/useClassName.js +15 -0
- package/lib/index.css +1 -1
- package/lib/index.d.ts +11 -1
- package/lib/index.js +20 -0
- package/package.json +2 -2
- package/scripts/rollup.config.js +1 -4
- package/src/components/CheckboxGroup/CheckBox/index.tsx +38 -0
- package/src/components/CheckboxGroup/hooks.ts +103 -0
- package/src/components/CheckboxGroup/index.tsx +46 -0
- package/src/components/CheckboxGroup/modal.d.ts +12 -0
- package/src/components/DatePicker/RangePicker.tsx +7 -0
- package/src/components/DatePicker/index.tsx +38 -0
- package/src/components/DatePicker/modal.d.ts +16 -0
- package/src/components/Input/ButtonInput.tsx +41 -0
- package/src/components/Input/InputNumber.tsx +5 -0
- package/src/components/Input/SelectInput.tsx +45 -0
- package/src/components/Input/defaultConfig.ts +8 -0
- package/src/components/Input/index.tsx +6 -0
- package/src/components/Input/modal.d.ts +26 -0
- package/src/components/RadioGroup/index.tsx +41 -0
- package/src/components/Select/components/AllSelect.tsx +9 -4
- package/src/components/Select/defaultConfig.tsx +0 -5
- package/src/components/Select/hooks/changeHooks.tsx +15 -4
- package/src/components/Select/hooks/norHooks.ts +2 -18
- package/src/components/Select/index.less +2 -1
- package/src/components/Select/index.tsx +14 -10
- package/src/components/Select/modal.ts +1 -2
- package/src/components/Select/utils.ts +18 -0
- package/src/components/Switch/index.tsx +47 -0
- package/src/components/TimePicker/index.tsx +1 -0
- package/src/components/config.less +1 -0
- package/src/components/config.ts +15 -0
- package/src/components/hooks/useChangeOptions.ts +22 -0
- package/src/components/hooks/useClassName.ts +8 -0
- package/src/components/index.tsx +12 -1
- package/src/components/typings.d.ts +5 -0
- package/src/pages/Checkbox/index.tsx +16 -0
- package/src/pages/DatePicker/index.tsx +15 -0
- package/src/pages/Input/index.tsx +22 -0
- package/src/pages/Radio/index.tsx +18 -0
- package/src/pages/Select/index.tsx +1 -2
- package/src/pages/Switch/index.tsx +18 -0
- package/src/routes.tsx +33 -12
- package/es/Select/index.less.js +0 -5
- package/lib/Select/index.less.js +0 -8
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { SwitchProps } from "antd";
|
|
2
|
+
import { Space, Switch } from "antd";
|
|
3
|
+
import React, { useMemo } from "react";
|
|
4
|
+
import { baseConfig } from "../config";
|
|
5
|
+
interface IProps extends Omit<SwitchProps, "onChange"> {
|
|
6
|
+
valueCheckMap?: ValueCheckMapModal;
|
|
7
|
+
value?: any;
|
|
8
|
+
onChange?: (val: any) => void;
|
|
9
|
+
beforeText?: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
const Index: React.FC<IProps> = ({
|
|
12
|
+
value,
|
|
13
|
+
onChange,
|
|
14
|
+
valueCheckMap = baseConfig.defaultValueSwitchMap,
|
|
15
|
+
children,
|
|
16
|
+
unCheckedChildren = "关闭",
|
|
17
|
+
checkedChildren = "开启",
|
|
18
|
+
beforeText,
|
|
19
|
+
...props
|
|
20
|
+
}) => {
|
|
21
|
+
const swChecked = useMemo(() => {
|
|
22
|
+
const { checked } = valueCheckMap;
|
|
23
|
+
return value === checked;
|
|
24
|
+
}, [value]);
|
|
25
|
+
const change = (checked) => {
|
|
26
|
+
let subVal = valueCheckMap?.noChecked;
|
|
27
|
+
if (checked) {
|
|
28
|
+
subVal = valueCheckMap?.checked;
|
|
29
|
+
}
|
|
30
|
+
onChange?.(subVal);
|
|
31
|
+
};
|
|
32
|
+
return (
|
|
33
|
+
<Space>
|
|
34
|
+
{beforeText}
|
|
35
|
+
<Switch
|
|
36
|
+
checked={swChecked}
|
|
37
|
+
checkedChildren={checkedChildren}
|
|
38
|
+
unCheckedChildren={unCheckedChildren}
|
|
39
|
+
onChange={change}
|
|
40
|
+
{...props}
|
|
41
|
+
/>
|
|
42
|
+
<span>{children}</span>
|
|
43
|
+
</Space>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default Index;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default () => {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@hw-prefix: hw;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const baseConfig = {
|
|
2
|
+
defaultFieldNames: {
|
|
3
|
+
label: "label",
|
|
4
|
+
value: "value",
|
|
5
|
+
},
|
|
6
|
+
defaultValueCheckMap: {
|
|
7
|
+
checked: true,
|
|
8
|
+
noChecked: false,
|
|
9
|
+
},
|
|
10
|
+
defaultValueSwitchMap: {
|
|
11
|
+
checked: true,
|
|
12
|
+
noChecked: false,
|
|
13
|
+
},
|
|
14
|
+
prefixCls:"hw"
|
|
15
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import type { SelectProps } from "antd";
|
|
3
|
+
import { baseConfig } from "../config";
|
|
4
|
+
|
|
5
|
+
interface UseChangeOptionsParams {
|
|
6
|
+
options?: Record<string, any>[];
|
|
7
|
+
fieldNames?: SelectProps["fieldNames"];
|
|
8
|
+
}
|
|
9
|
+
export const useChangeOptions = ({
|
|
10
|
+
options,
|
|
11
|
+
fieldNames = baseConfig.defaultFieldNames,
|
|
12
|
+
}: UseChangeOptionsParams) => {
|
|
13
|
+
return useMemo(() => {
|
|
14
|
+
return options?.map((item) => {
|
|
15
|
+
const { label = "", value = "" } = fieldNames;
|
|
16
|
+
return {
|
|
17
|
+
label: item[label],
|
|
18
|
+
value: item[value],
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}, [options]);
|
|
22
|
+
};
|
package/src/components/index.tsx
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
export {default as HSelect} from
|
|
1
|
+
export { default as HSelect } from "./Select";
|
|
2
|
+
export { default as HInput } from "./Input";
|
|
3
|
+
export { default as HInputNumber } from "./Input/InputNumber";
|
|
4
|
+
export { default as HSelectInput } from "./Input/SelectInput";
|
|
5
|
+
export { default as HButtonInput } from "./Input/ButtonInput";
|
|
6
|
+
export { default as HCheckboxGroup } from "./CheckboxGroup";
|
|
7
|
+
export { default as HCheckBox } from "./CheckboxGroup/CheckBox";
|
|
8
|
+
export { default as HRadioGroup } from "./RadioGroup";
|
|
9
|
+
export { default as HSwitch } from "./Switch";
|
|
10
|
+
export { default as HDatePicker } from "./DatePicker";
|
|
11
|
+
export { default as HRangePicker } from "./DatePicker/RangePicker";
|
|
12
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Space } from "antd";
|
|
2
|
+
import { HCheckboxGroup } from "../../components";
|
|
3
|
+
export default () => {
|
|
4
|
+
return (
|
|
5
|
+
<Space size={"large"} direction={"vertical"} style={{ width: "100%" }}>
|
|
6
|
+
<HCheckboxGroup
|
|
7
|
+
options={[{ label: "测试", value: "uu" }]}
|
|
8
|
+
value={{ uu: 0 }}
|
|
9
|
+
onChange={(value) => {
|
|
10
|
+
console.log(value);
|
|
11
|
+
}}
|
|
12
|
+
valueCheckMap={{ checked: 1, noChecked: 0 }}
|
|
13
|
+
/>
|
|
14
|
+
</Space>
|
|
15
|
+
);
|
|
16
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Space } from "antd";
|
|
2
|
+
import { HDatePicker ,HRangePicker} from "../../components";
|
|
3
|
+
export default () => {
|
|
4
|
+
return (
|
|
5
|
+
<Space size={"large"} direction={"vertical"} style={{ width: "100%" }}>
|
|
6
|
+
<HDatePicker
|
|
7
|
+
value={1691487319}
|
|
8
|
+
onChange={(val) => {
|
|
9
|
+
console.log(val);
|
|
10
|
+
}}
|
|
11
|
+
/>
|
|
12
|
+
<HRangePicker/>
|
|
13
|
+
</Space>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HInput,
|
|
3
|
+
HSelectInput,
|
|
4
|
+
HButtonInput,
|
|
5
|
+
HInputNumber,
|
|
6
|
+
} from "../../components";
|
|
7
|
+
import { Space } from "antd";
|
|
8
|
+
export default () => {
|
|
9
|
+
return (
|
|
10
|
+
<Space size={"large"} direction={"vertical"} style={{ width: "100%" }}>
|
|
11
|
+
<HInput placeholder="基础输入框" />
|
|
12
|
+
<HSelectInput
|
|
13
|
+
placeholder="基础输入框"
|
|
14
|
+
selectProps={{
|
|
15
|
+
options: [{ label: "1", value: 1 }],
|
|
16
|
+
}}
|
|
17
|
+
/>
|
|
18
|
+
<HButtonInput>点我</HButtonInput>
|
|
19
|
+
<HInputNumber />
|
|
20
|
+
</Space>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Space } from "antd";
|
|
2
|
+
import { HRadioGroup } from "../../components";
|
|
3
|
+
export default () => {
|
|
4
|
+
return (
|
|
5
|
+
<Space size={"large"} direction={"vertical"} style={{ width: "100%" }}>
|
|
6
|
+
<HRadioGroup
|
|
7
|
+
options={[
|
|
8
|
+
{ label: "测试2", value: "2" },
|
|
9
|
+
{ label: "测试1", value: "1" },
|
|
10
|
+
]}
|
|
11
|
+
value={"1"}
|
|
12
|
+
onChange={(value) => {
|
|
13
|
+
console.log(value);
|
|
14
|
+
}}
|
|
15
|
+
/>
|
|
16
|
+
</Space>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Space } from "antd";
|
|
2
|
+
import { HSwitch } from "../../components";
|
|
3
|
+
export default () => {
|
|
4
|
+
return (
|
|
5
|
+
<Space size={"large"} direction={"vertical"} style={{ width: "100%" }}>
|
|
6
|
+
<HSwitch
|
|
7
|
+
value={1}
|
|
8
|
+
beforeText="开关"
|
|
9
|
+
valueCheckMap={{ checked: 1, noChecked: 0 }}
|
|
10
|
+
onChange={(val) => {
|
|
11
|
+
console.log(val);
|
|
12
|
+
}}
|
|
13
|
+
>
|
|
14
|
+
打开
|
|
15
|
+
</HSwitch>
|
|
16
|
+
</Space>
|
|
17
|
+
);
|
|
18
|
+
};
|
package/src/routes.tsx
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Navigate } from "react-router-dom";
|
|
3
3
|
import Select from "./pages/Select";
|
|
4
|
+
import Input from "./pages/Input";
|
|
5
|
+
import CheckBox from "./pages/Checkbox";
|
|
6
|
+
import Radio from "./pages/Radio";
|
|
7
|
+
import Switch from "./pages/Switch";
|
|
8
|
+
import DatePicker from "./pages/DatePicker";
|
|
9
|
+
|
|
4
10
|
export interface RouteModal {
|
|
5
11
|
path?: string;
|
|
6
12
|
name?: string;
|
|
@@ -13,22 +19,37 @@ export interface RouteModal {
|
|
|
13
19
|
const routes: RouteModal[] = [
|
|
14
20
|
{
|
|
15
21
|
index: true,
|
|
16
|
-
element: <Navigate to="/
|
|
22
|
+
element: <Navigate to="/select" replace={true} />,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
path: "/select",
|
|
26
|
+
name: "下拉框",
|
|
27
|
+
element: <Select />,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
path: "/input",
|
|
31
|
+
name: "输入框",
|
|
32
|
+
element: <Input />,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
path: "/checkbox",
|
|
36
|
+
name: "多选",
|
|
37
|
+
element: <CheckBox />,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
path: "/radio",
|
|
41
|
+
name: "单选",
|
|
42
|
+
element: <Radio />,
|
|
17
43
|
},
|
|
18
44
|
{
|
|
19
|
-
path: "/
|
|
20
|
-
name: "
|
|
21
|
-
|
|
22
|
-
{
|
|
23
|
-
path: "/form/select",
|
|
24
|
-
name: "下拉框",
|
|
25
|
-
element: <Select />,
|
|
26
|
-
},
|
|
27
|
-
],
|
|
45
|
+
path: "/switch",
|
|
46
|
+
name: "开关",
|
|
47
|
+
element: <Switch />,
|
|
28
48
|
},
|
|
29
49
|
{
|
|
30
|
-
path: "/
|
|
31
|
-
name: "
|
|
50
|
+
path: "/datePicker",
|
|
51
|
+
name: "时间",
|
|
52
|
+
element: <DatePicker />,
|
|
32
53
|
},
|
|
33
54
|
];
|
|
34
55
|
|
package/es/Select/index.less.js
DELETED