@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.
Files changed (134) hide show
  1. package/LICENSE +201 -0
  2. package/es/CheckboxGroup/CheckBox/index.d.ts +7 -0
  3. package/es/CheckboxGroup/CheckBox/index.js +36 -0
  4. package/es/CheckboxGroup/hooks.d.ts +5 -0
  5. package/es/CheckboxGroup/hooks.js +124 -0
  6. package/es/CheckboxGroup/index.d.ts +4 -0
  7. package/es/CheckboxGroup/index.js +49 -0
  8. package/es/DatePicker/RangePicker.d.ts +4 -0
  9. package/es/DatePicker/RangePicker.js +23 -0
  10. package/es/DatePicker/index.d.ts +4 -0
  11. package/es/DatePicker/index.js +39 -0
  12. package/es/Input/ButtonInput.d.ts +4 -0
  13. package/es/Input/ButtonInput.js +80 -0
  14. package/es/Input/InputNumber.d.ts +4 -0
  15. package/es/Input/InputNumber.js +20 -0
  16. package/es/Input/SelectInput.d.ts +8 -0
  17. package/es/Input/SelectInput.js +67 -0
  18. package/es/Input/defaultConfig.d.ts +7 -0
  19. package/es/Input/defaultConfig.js +11 -0
  20. package/es/Input/index.d.ts +4 -0
  21. package/es/Input/index.js +13 -0
  22. package/es/RadioGroup/index.d.ts +9 -0
  23. package/es/RadioGroup/index.js +44 -0
  24. package/es/Select/components/AllSelect.d.ts +2 -1
  25. package/es/Select/components/AllSelect.js +9 -5
  26. package/es/Select/defaultConfig.d.ts +0 -1
  27. package/es/Select/defaultConfig.js +1 -5
  28. package/es/Select/hooks/changeHooks.d.ts +1 -1
  29. package/es/Select/hooks/changeHooks.js +8 -3
  30. package/es/Select/hooks/norHooks.d.ts +2 -5
  31. package/es/Select/hooks/norHooks.js +12 -34
  32. package/es/Select/index.js +12 -7
  33. package/es/Select/modal.d.ts +1 -2
  34. package/es/Select/utils.d.ts +2 -0
  35. package/es/Select/utils.js +39 -0
  36. package/es/Switch/index.d.ts +10 -0
  37. package/es/Switch/index.js +41 -0
  38. package/es/TimePicker/index.d.ts +2 -0
  39. package/es/config.d.ts +15 -0
  40. package/es/config.js +19 -0
  41. package/es/hooks/useChangeOptions.d.ts +10 -0
  42. package/es/hooks/useChangeOptions.js +25 -0
  43. package/es/hooks/useClassName.d.ts +1 -0
  44. package/es/hooks/useClassName.js +14 -0
  45. package/es/index.css +1 -1
  46. package/es/index.d.ts +11 -1
  47. package/es/index.js +10 -0
  48. package/lib/CheckboxGroup/CheckBox/index.d.ts +7 -0
  49. package/lib/CheckboxGroup/CheckBox/index.js +39 -0
  50. package/lib/CheckboxGroup/hooks.d.ts +5 -0
  51. package/lib/CheckboxGroup/hooks.js +125 -0
  52. package/lib/CheckboxGroup/index.d.ts +4 -0
  53. package/lib/CheckboxGroup/index.js +52 -0
  54. package/lib/DatePicker/RangePicker.d.ts +4 -0
  55. package/lib/DatePicker/RangePicker.js +26 -0
  56. package/lib/DatePicker/index.d.ts +4 -0
  57. package/lib/DatePicker/index.js +42 -0
  58. package/lib/Input/ButtonInput.d.ts +4 -0
  59. package/lib/Input/ButtonInput.js +83 -0
  60. package/lib/Input/InputNumber.d.ts +4 -0
  61. package/lib/Input/InputNumber.js +23 -0
  62. package/lib/Input/SelectInput.d.ts +8 -0
  63. package/lib/Input/SelectInput.js +70 -0
  64. package/lib/Input/defaultConfig.d.ts +7 -0
  65. package/lib/Input/defaultConfig.js +13 -0
  66. package/lib/Input/index.d.ts +4 -0
  67. package/lib/Input/index.js +16 -0
  68. package/lib/RadioGroup/index.d.ts +9 -0
  69. package/lib/RadioGroup/index.js +47 -0
  70. package/lib/Select/components/AllSelect.d.ts +2 -1
  71. package/lib/Select/components/AllSelect.js +9 -5
  72. package/lib/Select/defaultConfig.d.ts +0 -1
  73. package/lib/Select/defaultConfig.js +0 -5
  74. package/lib/Select/hooks/changeHooks.d.ts +1 -1
  75. package/lib/Select/hooks/changeHooks.js +8 -3
  76. package/lib/Select/hooks/norHooks.d.ts +2 -5
  77. package/lib/Select/hooks/norHooks.js +12 -34
  78. package/lib/Select/index.js +11 -6
  79. package/lib/Select/modal.d.ts +1 -2
  80. package/lib/Select/utils.d.ts +2 -0
  81. package/lib/Select/utils.js +41 -0
  82. package/lib/Switch/index.d.ts +10 -0
  83. package/lib/Switch/index.js +44 -0
  84. package/lib/TimePicker/index.d.ts +2 -0
  85. package/lib/config.d.ts +15 -0
  86. package/lib/config.js +20 -0
  87. package/lib/hooks/useChangeOptions.d.ts +10 -0
  88. package/lib/hooks/useChangeOptions.js +26 -0
  89. package/lib/hooks/useClassName.d.ts +1 -0
  90. package/lib/hooks/useClassName.js +15 -0
  91. package/lib/index.css +1 -1
  92. package/lib/index.d.ts +11 -1
  93. package/lib/index.js +20 -0
  94. package/package.json +2 -2
  95. package/scripts/rollup.config.js +1 -4
  96. package/src/components/CheckboxGroup/CheckBox/index.tsx +38 -0
  97. package/src/components/CheckboxGroup/hooks.ts +103 -0
  98. package/src/components/CheckboxGroup/index.tsx +46 -0
  99. package/src/components/CheckboxGroup/modal.d.ts +12 -0
  100. package/src/components/DatePicker/RangePicker.tsx +7 -0
  101. package/src/components/DatePicker/index.tsx +38 -0
  102. package/src/components/DatePicker/modal.d.ts +16 -0
  103. package/src/components/Input/ButtonInput.tsx +41 -0
  104. package/src/components/Input/InputNumber.tsx +5 -0
  105. package/src/components/Input/SelectInput.tsx +45 -0
  106. package/src/components/Input/defaultConfig.ts +8 -0
  107. package/src/components/Input/index.tsx +6 -0
  108. package/src/components/Input/modal.d.ts +26 -0
  109. package/src/components/RadioGroup/index.tsx +41 -0
  110. package/src/components/Select/components/AllSelect.tsx +9 -4
  111. package/src/components/Select/defaultConfig.tsx +0 -5
  112. package/src/components/Select/hooks/changeHooks.tsx +15 -4
  113. package/src/components/Select/hooks/norHooks.ts +2 -18
  114. package/src/components/Select/index.less +2 -1
  115. package/src/components/Select/index.tsx +14 -10
  116. package/src/components/Select/modal.ts +1 -2
  117. package/src/components/Select/utils.ts +18 -0
  118. package/src/components/Switch/index.tsx +47 -0
  119. package/src/components/TimePicker/index.tsx +1 -0
  120. package/src/components/config.less +1 -0
  121. package/src/components/config.ts +15 -0
  122. package/src/components/hooks/useChangeOptions.ts +22 -0
  123. package/src/components/hooks/useClassName.ts +8 -0
  124. package/src/components/index.tsx +12 -1
  125. package/src/components/typings.d.ts +5 -0
  126. package/src/pages/Checkbox/index.tsx +16 -0
  127. package/src/pages/DatePicker/index.tsx +15 -0
  128. package/src/pages/Input/index.tsx +22 -0
  129. package/src/pages/Radio/index.tsx +18 -0
  130. package/src/pages/Select/index.tsx +1 -2
  131. package/src/pages/Switch/index.tsx +18 -0
  132. package/src/routes.tsx +33 -12
  133. package/es/Select/index.less.js +0 -5
  134. 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
+ };
@@ -0,0 +1,8 @@
1
+ import {useMemo} from "react";
2
+ import {baseConfig} from "@/components/config";
3
+
4
+ export const useClassName=(className:string)=>{
5
+ return useMemo(()=>{
6
+ return `${baseConfig.prefixCls}-${className}`
7
+ },[className])
8
+ }
@@ -1 +1,12 @@
1
- export {default as HSelect} from './Select'
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
+
@@ -9,3 +9,8 @@ declare module "*.jpeg";
9
9
  declare module "*.gif";
10
10
  declare module "*.bmp";
11
11
  declare module "*.tiff";
12
+ type PromiseFnResult<T = any, R = any> = (params: T) => Promise<R>;
13
+ interface ValueCheckMapModal {
14
+ checked?: any;
15
+ noChecked?: any;
16
+ }
@@ -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
+ };
@@ -1,6 +1,5 @@
1
1
  import { HSelect } from "../../components";
2
- import { Space, Card } from "antd";
3
- import { useState } from "react";
2
+ import { Space } from "antd";
4
3
  export default () => {
5
4
  return (
6
5
  <Space size={"large"} direction={"vertical"} style={{ width: "100%" }}>
@@ -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="/form/select" replace={true} />,
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: "/form",
20
- name: "表单",
21
- children: [
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: "/table",
31
- name: "列表",
50
+ path: "/datePicker",
51
+ name: "时间",
52
+ element: <DatePicker />,
32
53
  },
33
54
  ];
34
55
 
@@ -1,5 +0,0 @@
1
- // welcome to ww-building-blocks-tmp
2
- var styles = undefined;
3
-
4
- export { styles as default };
5
- // powered by ww
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var styles = undefined;
6
-
7
- exports.default = styles;
8
- // powered by h