@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,67 @@
1
+ // welcome to ww-building-blocks-tmp
2
+ import React from 'react';
3
+ import _Object$keys from '@babel/runtime-corejs3/core-js/object/keys';
4
+ import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js/object/get-own-property-symbols';
5
+ import _filterInstanceProperty from '@babel/runtime-corejs3/core-js/instance/filter';
6
+ import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js/object/get-own-property-descriptor';
7
+ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js/instance/for-each';
8
+ import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js/object/get-own-property-descriptors';
9
+ import _Object$defineProperties from '@babel/runtime-corejs3/core-js/object/define-properties';
10
+ import _Object$defineProperty from '@babel/runtime-corejs3/core-js/object/define-property';
11
+ import _extends from '@babel/runtime-corejs3/helpers/extends';
12
+ import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
13
+ import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
14
+ import { Input } from 'antd';
15
+ import HSelect from '../Select/index.js';
16
+ import { defaultValueName, defaultSelectStyle } from './defaultConfig.js';
17
+
18
+ var _excluded = ["selectProps", "value", "onChange", "valueName"],
19
+ _excluded2 = ["style"];
20
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
22
+ var SelectInputType;
23
+ (function (SelectInputType) {
24
+ SelectInputType[SelectInputType["input"] = 0] = "input";
25
+ SelectInputType[SelectInputType["select"] = 1] = "select";
26
+ })(SelectInputType || (SelectInputType = {}));
27
+ var SelectInput = (function (_ref) {
28
+ var _ref$selectProps = _ref.selectProps,
29
+ selectProps = _ref$selectProps === void 0 ? {} : _ref$selectProps,
30
+ _ref$value = _ref.value,
31
+ value = _ref$value === void 0 ? {} : _ref$value,
32
+ onChange = _ref.onChange,
33
+ _ref$valueName = _ref.valueName,
34
+ valueName = _ref$valueName === void 0 ? defaultValueName : _ref$valueName,
35
+ props = _objectWithoutProperties(_ref, _excluded);
36
+ var _valueName$input = valueName.input,
37
+ input = _valueName$input === void 0 ? "" : _valueName$input,
38
+ _valueName$select = valueName.select,
39
+ select = _valueName$select === void 0 ? "" : _valueName$select;
40
+ var inputVal = value[input],
41
+ selectVal = value[select];
42
+ var _selectProps$style = selectProps.style,
43
+ style = _selectProps$style === void 0 ? defaultSelectStyle : _selectProps$style,
44
+ sProps = _objectWithoutProperties(selectProps, _excluded2);
45
+ var change = function change(val, key) {
46
+ var newVal = _objectSpread({}, value);
47
+ newVal[key] = val;
48
+ var type = key === input ? SelectInputType.input : SelectInputType.select;
49
+ onChange === null || onChange === void 0 ? void 0 : onChange(newVal, type);
50
+ };
51
+ return /*#__PURE__*/React.createElement(Input, _extends({
52
+ value: inputVal,
53
+ onChange: function onChange(e) {
54
+ change(e.target.value, input);
55
+ },
56
+ addonBefore: /*#__PURE__*/React.createElement(HSelect, _extends({}, sProps, {
57
+ style: style,
58
+ value: selectVal,
59
+ onChange: function onChange(val) {
60
+ change(val, select);
61
+ }
62
+ }))
63
+ }, props));
64
+ });
65
+
66
+ export { SelectInputType, SelectInput as default };
67
+ // powered by ww
@@ -0,0 +1,7 @@
1
+ export declare const defaultSelectStyle: {
2
+ width: number;
3
+ };
4
+ export declare const defaultValueName: {
5
+ input: string;
6
+ select: string;
7
+ };
@@ -0,0 +1,11 @@
1
+ // welcome to ww-building-blocks-tmp
2
+ var defaultSelectStyle = {
3
+ width: 128
4
+ };
5
+ var defaultValueName = {
6
+ input: "input",
7
+ select: "select"
8
+ };
9
+
10
+ export { defaultSelectStyle, defaultValueName };
11
+ // powered by ww
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { HInputProps } from "./modal";
3
+ declare const _default: ({ ...props }: HInputProps) => JSX.Element;
4
+ export default _default;
@@ -0,0 +1,13 @@
1
+ // welcome to ww-building-blocks-tmp
2
+ import React from 'react';
3
+ import _objectDestructuringEmpty from '@babel/runtime-corejs3/helpers/objectDestructuringEmpty';
4
+ import _extends from '@babel/runtime-corejs3/helpers/extends';
5
+ import { Input } from 'antd';
6
+
7
+ var index = (function (_ref) {
8
+ var props = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
9
+ return /*#__PURE__*/React.createElement(Input, props);
10
+ });
11
+
12
+ export { index as default };
13
+ // powered by ww
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import type { SelectProps, RadioGroupProps } from "antd/es";
3
+ interface IProps extends Omit<RadioGroupProps, "onChange" | "options"> {
4
+ onChange?: (value: any) => void;
5
+ fieldNames?: SelectProps["fieldNames"];
6
+ options?: (Record<string, any> | string | number)[];
7
+ }
8
+ declare const _default: ({ value, options, onChange, fieldNames, ...props }: IProps) => JSX.Element;
9
+ export default _default;
@@ -0,0 +1,44 @@
1
+ // welcome to ww-building-blocks-tmp
2
+ import React, { useMemo } from 'react';
3
+ import _extends from '@babel/runtime-corejs3/helpers/extends';
4
+ import _typeof from '@babel/runtime-corejs3/helpers/typeof';
5
+ import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
6
+ import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
7
+ import { Radio } from 'antd';
8
+ import { baseConfig } from '../config.js';
9
+
10
+ var _excluded = ["value", "options", "onChange", "fieldNames"];
11
+ var index = (function (_ref) {
12
+ var value = _ref.value,
13
+ options = _ref.options,
14
+ _onChange = _ref.onChange,
15
+ _ref$fieldNames = _ref.fieldNames,
16
+ fieldNames = _ref$fieldNames === void 0 ? baseConfig.defaultFieldNames : _ref$fieldNames,
17
+ props = _objectWithoutProperties(_ref, _excluded);
18
+ var relOptions = useMemo(function () {
19
+ return options === null || options === void 0 ? void 0 : _mapInstanceProperty(options).call(options, function (item) {
20
+ var type = _typeof(item);
21
+ if (type === "string" || type === "number") {
22
+ return item;
23
+ }
24
+ var _fieldNames$label = fieldNames.label,
25
+ labelKey = _fieldNames$label === void 0 ? "" : _fieldNames$label,
26
+ _fieldNames$value = fieldNames.value,
27
+ valueKey = _fieldNames$value === void 0 ? "" : _fieldNames$value;
28
+ return {
29
+ label: item[labelKey],
30
+ value: item[valueKey]
31
+ };
32
+ });
33
+ }, [options, fieldNames]);
34
+ return /*#__PURE__*/React.createElement(Radio.Group, _extends({
35
+ options: relOptions,
36
+ value: value,
37
+ onChange: function onChange(e) {
38
+ _onChange === null || _onChange === void 0 ? void 0 : _onChange(e.target.value);
39
+ }
40
+ }, props));
41
+ });
42
+
43
+ export { index as default };
44
+ // powered by ww
@@ -1,7 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import type { HSelectProps } from "@/components/Select/modal";
3
+ import "../index.less";
3
4
  interface IProps extends HSelectProps {
4
5
  checked?: boolean;
5
6
  }
6
- declare const _default: ({ allSelect, mode, onChange, value, serviceSearch, options, }: IProps) => JSX.Element | null;
7
+ declare const _default: ({ allSelect, mode, onChange, value, serviceSearch, options, fieldNames, }: IProps) => JSX.Element | null;
7
8
  export default _default;
@@ -1,7 +1,8 @@
1
1
  // welcome to ww-building-blocks-tmp
2
2
  import React from 'react';
3
3
  import { Space, Checkbox } from 'antd';
4
- import styles from '../index.less.js';
4
+ import { itemOpProvider } from '../utils.js';
5
+ import { useClassName } from '../../hooks/useClassName.js';
5
6
 
6
7
  var AllSelect = (function (_ref) {
7
8
  var allSelect = _ref.allSelect,
@@ -9,21 +10,24 @@ var AllSelect = (function (_ref) {
9
10
  onChange = _ref.onChange,
10
11
  value = _ref.value,
11
12
  serviceSearch = _ref.serviceSearch,
12
- options = _ref.options;
13
+ options = _ref.options,
14
+ fieldNames = _ref.fieldNames;
13
15
  if (!allSelect || mode !== "multiple" || serviceSearch) {
14
16
  return null;
15
17
  }
16
18
  var opLen = (options === null || options === void 0 ? void 0 : options.length) || 0;
17
19
  var checked = (value === null || value === void 0 ? void 0 : value.length) >= opLen;
20
+ var optionsClassName = useClassName("option");
18
21
  var change = function change() {
19
22
  if (!checked) {
20
- onChange === null || onChange === void 0 ? void 0 : onChange(options);
23
+ var subItemOps = itemOpProvider(options, fieldNames);
24
+ onChange === null || onChange === void 0 ? void 0 : onChange(options, subItemOps);
21
25
  return;
22
26
  }
23
- onChange === null || onChange === void 0 ? void 0 : onChange([]);
27
+ onChange === null || onChange === void 0 ? void 0 : onChange([], []);
24
28
  };
25
29
  return /*#__PURE__*/React.createElement("div", {
26
- className: "ant-select-item ant-select-item-option ".concat(styles.option),
30
+ className: "ant-select-item ant-select-item-option ".concat(optionsClassName),
27
31
  onClick: change
28
32
  }, /*#__PURE__*/React.createElement(Space, null, /*#__PURE__*/React.createElement(Checkbox, {
29
33
  checked: checked
@@ -1,7 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { HSelectProps } from "@/components/Select/modal";
3
3
  export declare const defaultModeConfig: HSelectProps["modeConfig"];
4
- export declare const defaultFieldNames: HSelectProps["fieldNames"];
5
4
  export declare const defaultSelectConfig: {
6
5
  noMatchItemRender: () => JSX.Element;
7
6
  };
@@ -21,10 +21,6 @@ var defaultModeConfig = {
21
21
  }
22
22
  }
23
23
  };
24
- var defaultFieldNames = {
25
- label: "label",
26
- value: "value"
27
- };
28
24
  var defaultSelectConfig = {
29
25
  noMatchItemRender: function noMatchItemRender() {
30
26
  return /*#__PURE__*/React.createElement(NoFindItem, {
@@ -33,5 +29,5 @@ var defaultSelectConfig = {
33
29
  }
34
30
  };
35
31
 
36
- export { defaultFieldNames, defaultModeConfig, defaultSelectConfig };
32
+ export { defaultModeConfig, defaultSelectConfig };
37
33
  // powered by ww
@@ -1,5 +1,5 @@
1
1
  import type { PartialHSelectProps } from "@/components/Select/modal";
2
2
  export declare const useValueChange: (params: PartialHSelectProps) => {
3
3
  val: any;
4
- change: (changeVal: any) => void;
4
+ change: (changeVal: any, itemOps: any) => void;
5
5
  };
@@ -14,6 +14,8 @@ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js/instance/fo
14
14
  import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
15
15
  import _Array$isArray from '@babel/runtime-corejs3/core-js/array/is-array';
16
16
  import { useState, useEffect } from 'react';
17
+ import { itemOpProvider } from '../utils.js';
18
+ import { baseConfig } from '../../config.js';
17
19
 
18
20
  var _excluded = ["index"],
19
21
  _excluded2 = ["index"];
@@ -152,12 +154,14 @@ var useValueChange = function useValueChange(params) {
152
154
  value = params.value,
153
155
  options = params.options,
154
156
  mode = params.mode,
155
- noMatchItemRender = params.noMatchItemRender;
157
+ noMatchItemRender = params.noMatchItemRender,
158
+ _params$fieldNames = params.fieldNames,
159
+ fieldNames = _params$fieldNames === void 0 ? baseConfig.defaultFieldNames : _params$fieldNames;
156
160
  var _useState = useState(),
157
161
  _useState2 = _slicedToArray(_useState, 2),
158
162
  val = _useState2[0],
159
163
  setVal = _useState2[1];
160
- var change = function change(changeVal) {
164
+ var change = function change(changeVal, itemOps) {
161
165
  if (!onChange) {
162
166
  setVal(changeVal);
163
167
  return;
@@ -171,7 +175,8 @@ var useValueChange = function useValueChange(params) {
171
175
  return item.value;
172
176
  });
173
177
  }
174
- onChange(newChangeVal);
178
+ var subItemOps = itemOpProvider(itemOps, fieldNames);
179
+ onChange(newChangeVal, subItemOps);
175
180
  };
176
181
  useEffect(function () {
177
182
  if (options && value) {
@@ -1,9 +1,6 @@
1
1
  import type { OptionType, PartialHSelectProps } from "@/components/Select/modal";
2
- export declare const useOptionReq: ({ manual, fieldNames, request, options, serviceSearch, }: PartialHSelectProps) => {
3
- run: (params?: any, type?: any) => Promise<{
4
- label: any;
5
- value: any;
6
- }[] | undefined>;
2
+ export declare const useOptionReq: ({ manual, request, options, serviceSearch, }: PartialHSelectProps) => {
3
+ run: (params?: any, type?: any) => Promise<OptionType[] | undefined>;
7
4
  loading: boolean;
8
5
  error: Error | undefined;
9
6
  data: OptionType[] | undefined;
@@ -2,30 +2,15 @@
2
2
  import _asyncToGenerator from '@babel/runtime-corejs3/helpers/asyncToGenerator';
3
3
  import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
4
4
  import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
5
- import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
6
5
  import _Promise from '@babel/runtime-corejs3/core-js/promise';
7
6
  import { useState } from 'react';
8
7
  import { useRequest } from 'ahooks';
9
8
 
10
- var resultProvider = function resultProvider(data, fieldNames) {
11
- return data === null || data === void 0 ? void 0 : _mapInstanceProperty(data).call(data, function (item) {
12
- var _ref = fieldNames || {},
13
- _ref$label = _ref.label,
14
- label = _ref$label === void 0 ? "label" : _ref$label,
15
- _ref$value = _ref.value,
16
- value = _ref$value === void 0 ? "value" : _ref$value;
17
- return {
18
- label: item[label],
19
- value: item[value]
20
- };
21
- });
22
- };
23
- var useOptionReq = function useOptionReq(_ref2) {
24
- var manual = _ref2.manual,
25
- fieldNames = _ref2.fieldNames,
26
- request = _ref2.request,
27
- options = _ref2.options,
28
- serviceSearch = _ref2.serviceSearch;
9
+ var useOptionReq = function useOptionReq(_ref) {
10
+ var manual = _ref.manual,
11
+ request = _ref.request,
12
+ options = _ref.options,
13
+ serviceSearch = _ref.serviceSearch;
29
14
  var _useState = useState(),
30
15
  _useState2 = _slicedToArray(_useState, 2),
31
16
  data = _useState2[0],
@@ -33,8 +18,6 @@ var useOptionReq = function useOptionReq(_ref2) {
33
18
  var _useRequest = useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
34
19
  var params,
35
20
  type,
36
- result,
37
- resultOpt,
38
21
  _args = arguments;
39
22
  return _regeneratorRuntime.wrap(function _callee$(_context) {
40
23
  while (1) switch (_context.prev = _context.next) {
@@ -45,18 +28,13 @@ var useOptionReq = function useOptionReq(_ref2) {
45
28
  setData(undefined);
46
29
  }
47
30
  if (!request) {
48
- _context.next = 8;
31
+ _context.next = 5;
49
32
  break;
50
33
  }
51
- _context.next = 6;
52
- return request(params);
34
+ return _context.abrupt("return", request(params));
35
+ case 5:
36
+ return _context.abrupt("return", _Promise.resolve(options));
53
37
  case 6:
54
- result = _context.sent;
55
- return _context.abrupt("return", resultProvider(result, fieldNames));
56
- case 8:
57
- resultOpt = resultProvider(options, fieldNames);
58
- return _context.abrupt("return", _Promise.resolve(resultOpt));
59
- case 10:
60
38
  case "end":
61
39
  return _context.stop();
62
40
  }
@@ -87,9 +65,9 @@ var useOptionReq = function useOptionReq(_ref2) {
87
65
  onSearch: onSearch
88
66
  };
89
67
  };
90
- var useFilterOption = function useFilterOption(_ref4) {
91
- var filterOption = _ref4.filterOption,
92
- serviceSearch = _ref4.serviceSearch;
68
+ var useFilterOption = function useFilterOption(_ref3) {
69
+ var filterOption = _ref3.filterOption,
70
+ serviceSearch = _ref3.serviceSearch;
93
71
  if (serviceSearch) {
94
72
  return function () {
95
73
  return true;
@@ -7,13 +7,14 @@ import { Select } from 'antd';
7
7
  import React from 'react';
8
8
  import { useFilterOption, useOptionReq } from './hooks/norHooks.js';
9
9
  import { useValueChange } from './hooks/changeHooks.js';
10
- import { defaultModeConfig, defaultFieldNames, defaultSelectConfig } from './defaultConfig.js';
10
+ import { defaultModeConfig, defaultSelectConfig } from './defaultConfig.js';
11
11
  import Index from './components/DropdownComponent.js';
12
12
  import AllSelect from './components/AllSelect.js';
13
+ import { useChangeOptions } from '../hooks/useChangeOptions.js';
13
14
 
14
15
  var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect"];
15
16
  var Option = Select.Option;
16
- var index = (function (_ref) {
17
+ var HSelect = (function (_ref) {
17
18
  var _ref$style = _ref.style,
18
19
  style = _ref$style === void 0 ? {
19
20
  width: "100%"
@@ -24,8 +25,7 @@ var index = (function (_ref) {
24
25
  modeConfig = _ref$modeConfig === void 0 ? defaultModeConfig : _ref$modeConfig,
25
26
  value = _ref.value,
26
27
  onChange = _ref.onChange,
27
- _ref$fieldNames = _ref.fieldNames,
28
- fieldNames = _ref$fieldNames === void 0 ? defaultFieldNames : _ref$fieldNames,
28
+ fieldNames = _ref.fieldNames,
29
29
  request = _ref.request,
30
30
  manual = _ref.manual,
31
31
  _ref$optionLabelProp = _ref.optionLabelProp,
@@ -58,16 +58,21 @@ var index = (function (_ref) {
58
58
  }),
59
59
  run = _useOptionReq.run,
60
60
  loading = _useOptionReq.loading,
61
- data = _useOptionReq.data,
61
+ resultData = _useOptionReq.data,
62
62
  error = _useOptionReq.error,
63
63
  onSearch = _useOptionReq.onSearch;
64
+ var data = useChangeOptions({
65
+ options: resultData,
66
+ fieldNames: fieldNames
67
+ });
64
68
  var _useValueChange = useValueChange({
65
69
  labelInValue: labelInValue,
66
70
  onChange: onChange,
67
71
  value: value,
68
72
  options: data,
69
73
  mode: mode,
70
- noMatchItemRender: noMatchItemRender
74
+ noMatchItemRender: noMatchItemRender,
75
+ fieldNames: fieldNames
71
76
  }),
72
77
  val = _useValueChange.val,
73
78
  change = _useValueChange.change;
@@ -112,5 +117,5 @@ var index = (function (_ref) {
112
117
  }));
113
118
  });
114
119
 
115
- export { index as default };
120
+ export { HSelect as default };
116
121
  // powered by ww
@@ -13,10 +13,9 @@ export interface ModeConfig {
13
13
  }
14
14
  export interface HSelectProps extends Omit<SelectProps, "options"> {
15
15
  style?: React.CSSProperties;
16
- request?: (params: any) => Promise<OptionType[]>;
16
+ request?: PromiseFnResult<any, OptionType[]>;
17
17
  manual?: boolean;
18
18
  modeConfig?: ModeConfig;
19
- onChange?: (val: any) => void;
20
19
  filterProvider?: (item: any) => string;
21
20
  serviceSearch?: boolean;
22
21
  options?: OptionType[];
@@ -0,0 +1,2 @@
1
+ export declare const itemOpMaker: (itemOp: any, fieldNames: any) => any;
2
+ export declare const itemOpProvider: (itemOps: any, fieldNames: any) => any;
@@ -0,0 +1,39 @@
1
+ // welcome to ww-building-blocks-tmp
2
+ import _Object$keys from '@babel/runtime-corejs3/core-js/object/keys';
3
+ import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js/object/get-own-property-symbols';
4
+ import _filterInstanceProperty from '@babel/runtime-corejs3/core-js/instance/filter';
5
+ import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js/object/get-own-property-descriptor';
6
+ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js/instance/for-each';
7
+ import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js/object/get-own-property-descriptors';
8
+ import _Object$defineProperties from '@babel/runtime-corejs3/core-js/object/define-properties';
9
+ import _Object$defineProperty from '@babel/runtime-corejs3/core-js/object/define-property';
10
+ import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
11
+ import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
12
+ import _Array$isArray from '@babel/runtime-corejs3/core-js/array/is-array';
13
+ import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
14
+
15
+ var _excluded = ["label", "value"];
16
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
18
+ var itemOpMaker = function itemOpMaker(itemOp, fieldNames) {
19
+ var _objectSpread2;
20
+ var label = itemOp.label,
21
+ itemVal = itemOp.value,
22
+ oItemOp = _objectWithoutProperties(itemOp, _excluded);
23
+ var _fieldNames$label = fieldNames.label,
24
+ labelKey = _fieldNames$label === void 0 ? "" : _fieldNames$label,
25
+ _fieldNames$value = fieldNames.value,
26
+ valKey = _fieldNames$value === void 0 ? "" : _fieldNames$value;
27
+ return _objectSpread((_objectSpread2 = {}, _defineProperty(_objectSpread2, labelKey, label), _defineProperty(_objectSpread2, valKey, itemVal), _objectSpread2), oItemOp);
28
+ };
29
+ var itemOpProvider = function itemOpProvider(itemOps, fieldNames) {
30
+ if (_Array$isArray(itemOps)) {
31
+ return _mapInstanceProperty(itemOps).call(itemOps, function (item) {
32
+ return itemOpMaker(item, fieldNames);
33
+ });
34
+ }
35
+ return itemOpMaker(itemOps, fieldNames);
36
+ };
37
+
38
+ export { itemOpMaker, itemOpProvider };
39
+ // powered by ww
@@ -0,0 +1,10 @@
1
+ import type { SwitchProps } from "antd";
2
+ import React from "react";
3
+ interface IProps extends Omit<SwitchProps, "onChange"> {
4
+ valueCheckMap?: ValueCheckMapModal;
5
+ value?: any;
6
+ onChange?: (val: any) => void;
7
+ beforeText?: React.ReactNode;
8
+ }
9
+ declare const Index: React.FC<IProps>;
10
+ export default Index;
@@ -0,0 +1,41 @@
1
+ // welcome to ww-building-blocks-tmp
2
+ import _extends from '@babel/runtime-corejs3/helpers/extends';
3
+ import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
4
+ import { Space, Switch } from 'antd';
5
+ import React, { useMemo } from 'react';
6
+ import { baseConfig } from '../config.js';
7
+
8
+ var _excluded = ["value", "onChange", "valueCheckMap", "children", "unCheckedChildren", "checkedChildren", "beforeText"];
9
+ var Index = function Index(_ref) {
10
+ var value = _ref.value,
11
+ onChange = _ref.onChange,
12
+ _ref$valueCheckMap = _ref.valueCheckMap,
13
+ valueCheckMap = _ref$valueCheckMap === void 0 ? baseConfig.defaultValueSwitchMap : _ref$valueCheckMap,
14
+ children = _ref.children,
15
+ _ref$unCheckedChildre = _ref.unCheckedChildren,
16
+ unCheckedChildren = _ref$unCheckedChildre === void 0 ? "关闭" : _ref$unCheckedChildre,
17
+ _ref$checkedChildren = _ref.checkedChildren,
18
+ checkedChildren = _ref$checkedChildren === void 0 ? "开启" : _ref$checkedChildren,
19
+ beforeText = _ref.beforeText,
20
+ props = _objectWithoutProperties(_ref, _excluded);
21
+ var swChecked = useMemo(function () {
22
+ var checked = valueCheckMap.checked;
23
+ return value === checked;
24
+ }, [value]);
25
+ var change = function change(checked) {
26
+ var subVal = valueCheckMap === null || valueCheckMap === void 0 ? void 0 : valueCheckMap.noChecked;
27
+ if (checked) {
28
+ subVal = valueCheckMap === null || valueCheckMap === void 0 ? void 0 : valueCheckMap.checked;
29
+ }
30
+ onChange === null || onChange === void 0 ? void 0 : onChange(subVal);
31
+ };
32
+ return /*#__PURE__*/React.createElement(Space, null, beforeText, /*#__PURE__*/React.createElement(Switch, _extends({
33
+ checked: swChecked,
34
+ checkedChildren: checkedChildren,
35
+ unCheckedChildren: unCheckedChildren,
36
+ onChange: change
37
+ }, props)), /*#__PURE__*/React.createElement("span", null, children));
38
+ };
39
+
40
+ export { Index as default };
41
+ // powered by ww
@@ -0,0 +1,2 @@
1
+ declare const _default: () => void;
2
+ export default _default;
package/es/config.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ export declare const baseConfig: {
2
+ defaultFieldNames: {
3
+ label: string;
4
+ value: string;
5
+ };
6
+ defaultValueCheckMap: {
7
+ checked: boolean;
8
+ noChecked: boolean;
9
+ };
10
+ defaultValueSwitchMap: {
11
+ checked: boolean;
12
+ noChecked: boolean;
13
+ };
14
+ prefixCls: string;
15
+ };
package/es/config.js ADDED
@@ -0,0 +1,19 @@
1
+ // welcome to ww-building-blocks-tmp
2
+ var baseConfig = {
3
+ defaultFieldNames: {
4
+ label: "label",
5
+ value: "value"
6
+ },
7
+ defaultValueCheckMap: {
8
+ checked: true,
9
+ noChecked: false
10
+ },
11
+ defaultValueSwitchMap: {
12
+ checked: true,
13
+ noChecked: false
14
+ },
15
+ prefixCls: "hw"
16
+ };
17
+
18
+ export { baseConfig };
19
+ // powered by ww
@@ -0,0 +1,10 @@
1
+ import type { SelectProps } from "antd";
2
+ interface UseChangeOptionsParams {
3
+ options?: Record<string, any>[];
4
+ fieldNames?: SelectProps["fieldNames"];
5
+ }
6
+ export declare const useChangeOptions: ({ options, fieldNames, }: UseChangeOptionsParams) => {
7
+ label: any;
8
+ value: any;
9
+ }[] | undefined;
10
+ export {};
@@ -0,0 +1,25 @@
1
+ // welcome to ww-building-blocks-tmp
2
+ import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
3
+ import { useMemo } from 'react';
4
+ import { baseConfig } from '../config.js';
5
+
6
+ var useChangeOptions = function useChangeOptions(_ref) {
7
+ var options = _ref.options,
8
+ _ref$fieldNames = _ref.fieldNames,
9
+ fieldNames = _ref$fieldNames === void 0 ? baseConfig.defaultFieldNames : _ref$fieldNames;
10
+ return useMemo(function () {
11
+ return options === null || options === void 0 ? void 0 : _mapInstanceProperty(options).call(options, function (item) {
12
+ var _fieldNames$label = fieldNames.label,
13
+ label = _fieldNames$label === void 0 ? "" : _fieldNames$label,
14
+ _fieldNames$value = fieldNames.value,
15
+ value = _fieldNames$value === void 0 ? "" : _fieldNames$value;
16
+ return {
17
+ label: item[label],
18
+ value: item[value]
19
+ };
20
+ });
21
+ }, [options]);
22
+ };
23
+
24
+ export { useChangeOptions };
25
+ // powered by ww
@@ -0,0 +1 @@
1
+ export declare const useClassName: (className: string) => string;
@@ -0,0 +1,14 @@
1
+ // welcome to ww-building-blocks-tmp
2
+ import _concatInstanceProperty from '@babel/runtime-corejs3/core-js/instance/concat';
3
+ import { useMemo } from 'react';
4
+ import { baseConfig } from '../config.js';
5
+
6
+ var useClassName = function useClassName(className) {
7
+ return useMemo(function () {
8
+ var _context;
9
+ return _concatInstanceProperty(_context = "".concat(baseConfig.prefixCls, "-")).call(_context, className);
10
+ }, [className]);
11
+ };
12
+
13
+ export { useClassName };
14
+ // powered by ww