@hw-component/form 0.0.1
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/.babelrc +23 -0
- package/.eslintrc.js +8 -0
- package/.husky/pre-commit +4 -0
- package/.stylelintrc.js +5 -0
- package/es/Select/components/AllSelect.d.ts +7 -0
- package/es/Select/components/AllSelect.js +34 -0
- package/es/Select/components/CheckBoxOption.d.ts +7 -0
- package/es/Select/components/CheckBoxOption.js +14 -0
- package/es/Select/components/DropdownComponent.d.ts +9 -0
- package/es/Select/components/DropdownComponent.js +39 -0
- package/es/Select/components/NoFindItem.d.ts +6 -0
- package/es/Select/components/NoFindItem.js +13 -0
- package/es/Select/components/NotFoundContent.d.ts +7 -0
- package/es/Select/components/NotFoundContent.js +40 -0
- package/es/Select/defaultConfig.d.ts +7 -0
- package/es/Select/defaultConfig.js +37 -0
- package/es/Select/hooks/changeHooks.d.ts +5 -0
- package/es/Select/hooks/changeHooks.js +190 -0
- package/es/Select/hooks/norHooks.d.ts +12 -0
- package/es/Select/hooks/norHooks.js +102 -0
- package/es/Select/index.d.ts +4 -0
- package/es/Select/index.js +116 -0
- package/es/Select/index.less.js +5 -0
- package/es/Select/modal.d.ts +30 -0
- package/es/index.css +3 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +3 -0
- package/lib/Select/components/AllSelect.d.ts +7 -0
- package/lib/Select/components/AllSelect.js +37 -0
- package/lib/Select/components/CheckBoxOption.d.ts +7 -0
- package/lib/Select/components/CheckBoxOption.js +17 -0
- package/lib/Select/components/DropdownComponent.d.ts +9 -0
- package/lib/Select/components/DropdownComponent.js +42 -0
- package/lib/Select/components/NoFindItem.d.ts +6 -0
- package/lib/Select/components/NoFindItem.js +16 -0
- package/lib/Select/components/NotFoundContent.d.ts +7 -0
- package/lib/Select/components/NotFoundContent.js +43 -0
- package/lib/Select/defaultConfig.d.ts +7 -0
- package/lib/Select/defaultConfig.js +40 -0
- package/lib/Select/hooks/changeHooks.d.ts +5 -0
- package/lib/Select/hooks/changeHooks.js +191 -0
- package/lib/Select/hooks/norHooks.d.ts +12 -0
- package/lib/Select/hooks/norHooks.js +104 -0
- package/lib/Select/index.d.ts +4 -0
- package/lib/Select/index.js +119 -0
- package/lib/Select/index.less.js +8 -0
- package/lib/Select/modal.d.ts +30 -0
- package/lib/index.css +3 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +8 -0
- package/package.json +80 -0
- package/public/index.html +19 -0
- package/scripts/rollup.config.js +80 -0
- package/scripts/webpack.config.js +72 -0
- package/src/Layout.tsx +61 -0
- package/src/app.tsx +33 -0
- package/src/components/Select/components/AllSelect.tsx +38 -0
- package/src/components/Select/components/CheckBoxOption.tsx +14 -0
- package/src/components/Select/components/DropdownComponent.tsx +35 -0
- package/src/components/Select/components/NoFindItem.tsx +7 -0
- package/src/components/Select/components/NotFoundContent.tsx +25 -0
- package/src/components/Select/defaultConfig.tsx +28 -0
- package/src/components/Select/hooks/changeHooks.tsx +141 -0
- package/src/components/Select/hooks/norHooks.ts +74 -0
- package/src/components/Select/index.less +5 -0
- package/src/components/Select/index.tsx +108 -0
- package/src/components/Select/modal.ts +30 -0
- package/src/components/index.tsx +1 -0
- package/src/components/typings.d.ts +11 -0
- package/src/index.less +20 -0
- package/src/index.tsx +12 -0
- package/src/pages/Select/index.tsx +54 -0
- package/src/routes.tsx +35 -0
- package/tsconfig.json +29 -0
package/.babelrc
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"presets": [
|
|
3
|
+
[
|
|
4
|
+
"@babel/preset-env",
|
|
5
|
+
{
|
|
6
|
+
"modules": false
|
|
7
|
+
}
|
|
8
|
+
],
|
|
9
|
+
"@babel/preset-react",
|
|
10
|
+
"@babel/preset-typescript"
|
|
11
|
+
],
|
|
12
|
+
"plugins": [
|
|
13
|
+
[
|
|
14
|
+
"@babel/plugin-transform-runtime",
|
|
15
|
+
{
|
|
16
|
+
"corejs": {
|
|
17
|
+
"version": 3,
|
|
18
|
+
"proposals": true
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
]
|
|
23
|
+
}
|
package/.eslintrc.js
ADDED
package/.stylelintrc.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { HSelectProps } from "@/components/Select/modal";
|
|
3
|
+
interface IProps extends HSelectProps {
|
|
4
|
+
checked?: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare const _default: ({ allSelect, mode, onChange, value, serviceSearch, options, }: IProps) => JSX.Element | null;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// welcome to ww-building-blocks-tmp
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Space, Checkbox } from 'antd';
|
|
4
|
+
import styles from '../index.less.js';
|
|
5
|
+
|
|
6
|
+
var AllSelect = (function (_ref) {
|
|
7
|
+
var allSelect = _ref.allSelect,
|
|
8
|
+
mode = _ref.mode,
|
|
9
|
+
onChange = _ref.onChange,
|
|
10
|
+
value = _ref.value,
|
|
11
|
+
serviceSearch = _ref.serviceSearch,
|
|
12
|
+
options = _ref.options;
|
|
13
|
+
if (!allSelect || mode !== "multiple" || serviceSearch) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
var opLen = (options === null || options === void 0 ? void 0 : options.length) || 0;
|
|
17
|
+
var checked = (value === null || value === void 0 ? void 0 : value.length) >= opLen;
|
|
18
|
+
var change = function change() {
|
|
19
|
+
if (!checked) {
|
|
20
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(options);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
onChange === null || onChange === void 0 ? void 0 : onChange([]);
|
|
24
|
+
};
|
|
25
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
26
|
+
className: "ant-select-item ant-select-item-option ".concat(styles.option),
|
|
27
|
+
onClick: change
|
|
28
|
+
}, /*#__PURE__*/React.createElement(Space, null, /*#__PURE__*/React.createElement(Checkbox, {
|
|
29
|
+
checked: checked
|
|
30
|
+
}), "\u5168\u90E8"));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export { AllSelect as default };
|
|
34
|
+
// powered by ww
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// welcome to ww-building-blocks-tmp
|
|
2
|
+
import { Space, Checkbox } from 'antd';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
var CheckBoxOption = (function (_ref) {
|
|
6
|
+
var label = _ref.label,
|
|
7
|
+
checked = _ref.checked;
|
|
8
|
+
return /*#__PURE__*/React.createElement(Space, null, /*#__PURE__*/React.createElement(Checkbox, {
|
|
9
|
+
checked: checked
|
|
10
|
+
}), label);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export { CheckBoxOption as default };
|
|
14
|
+
// powered by ww
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// welcome to ww-building-blocks-tmp
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Typography, Row, Space, Spin } from 'antd';
|
|
4
|
+
import NotFoundContent from './NotFoundContent.js';
|
|
5
|
+
|
|
6
|
+
var Text = Typography.Text;
|
|
7
|
+
var Index = function Index(_ref) {
|
|
8
|
+
var loading = _ref.loading,
|
|
9
|
+
error = _ref.error,
|
|
10
|
+
_ref$options = _ref.options,
|
|
11
|
+
options = _ref$options === void 0 ? [] : _ref$options,
|
|
12
|
+
reload = _ref.reload,
|
|
13
|
+
children = _ref.children;
|
|
14
|
+
var len = options === null || options === void 0 ? void 0 : options.length;
|
|
15
|
+
if (loading && len === 0) {
|
|
16
|
+
return /*#__PURE__*/React.createElement(Row, {
|
|
17
|
+
style: {
|
|
18
|
+
height: 125
|
|
19
|
+
},
|
|
20
|
+
justify: "center",
|
|
21
|
+
align: "middle"
|
|
22
|
+
}, /*#__PURE__*/React.createElement(Space, {
|
|
23
|
+
direction: "vertical",
|
|
24
|
+
align: "center"
|
|
25
|
+
}, /*#__PURE__*/React.createElement(Spin, null), /*#__PURE__*/React.createElement(Text, {
|
|
26
|
+
type: "secondary"
|
|
27
|
+
}, "\u62FC\u547D\u52A0\u8F7D\u4E2D...")));
|
|
28
|
+
}
|
|
29
|
+
if (error && len === 0) {
|
|
30
|
+
return /*#__PURE__*/React.createElement(NotFoundContent, {
|
|
31
|
+
error: error,
|
|
32
|
+
reload: reload
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { Index as default };
|
|
39
|
+
// powered by ww
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// welcome to ww-building-blocks-tmp
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Typography } from 'antd';
|
|
4
|
+
|
|
5
|
+
var NoFindItem = (function (_ref) {
|
|
6
|
+
var label = _ref.label;
|
|
7
|
+
return /*#__PURE__*/React.createElement(Typography.Text, {
|
|
8
|
+
type: "danger"
|
|
9
|
+
}, label);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export { NoFindItem as default };
|
|
13
|
+
// powered by ww
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// welcome to ww-building-blocks-tmp
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Typography, Row, Space, Button, Empty } from 'antd';
|
|
4
|
+
import { ExclamationCircleOutlined } from '@ant-design/icons';
|
|
5
|
+
|
|
6
|
+
var Text = Typography.Text;
|
|
7
|
+
var NotFoundContent = (function (_ref) {
|
|
8
|
+
var error = _ref.error,
|
|
9
|
+
reload = _ref.reload;
|
|
10
|
+
if (error) {
|
|
11
|
+
return /*#__PURE__*/React.createElement(Row, {
|
|
12
|
+
justify: "center",
|
|
13
|
+
align: "middle",
|
|
14
|
+
style: {
|
|
15
|
+
height: 125
|
|
16
|
+
}
|
|
17
|
+
}, /*#__PURE__*/React.createElement(Space, {
|
|
18
|
+
align: "center",
|
|
19
|
+
direction: "vertical"
|
|
20
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
21
|
+
type: "danger"
|
|
22
|
+
}, /*#__PURE__*/React.createElement(ExclamationCircleOutlined, {
|
|
23
|
+
style: {
|
|
24
|
+
fontSize: 24
|
|
25
|
+
}
|
|
26
|
+
})), /*#__PURE__*/React.createElement(Text, {
|
|
27
|
+
type: "danger"
|
|
28
|
+
}, error.message), /*#__PURE__*/React.createElement(Button, {
|
|
29
|
+
type: "primary",
|
|
30
|
+
size: "small",
|
|
31
|
+
onClick: reload
|
|
32
|
+
}, "\u91CD\u65B0\u52A0\u8F7D")));
|
|
33
|
+
}
|
|
34
|
+
return /*#__PURE__*/React.createElement(Empty, {
|
|
35
|
+
image: Empty.PRESENTED_IMAGE_SIMPLE
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export { NotFoundContent as default };
|
|
40
|
+
// powered by ww
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { HSelectProps } from "@/components/Select/modal";
|
|
3
|
+
export declare const defaultModeConfig: HSelectProps["modeConfig"];
|
|
4
|
+
export declare const defaultFieldNames: HSelectProps["fieldNames"];
|
|
5
|
+
export declare const defaultSelectConfig: {
|
|
6
|
+
noMatchItemRender: () => JSX.Element;
|
|
7
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// welcome to ww-building-blocks-tmp
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
|
|
4
|
+
import _indexOfInstanceProperty from '@babel/runtime-corejs3/core-js/instance/index-of';
|
|
5
|
+
import CheckBoxOption from './components/CheckBoxOption.js';
|
|
6
|
+
import NoFindItem from './components/NoFindItem.js';
|
|
7
|
+
|
|
8
|
+
var defaultModeConfig = {
|
|
9
|
+
multiple: {
|
|
10
|
+
icon: null,
|
|
11
|
+
render: function render(item, value) {
|
|
12
|
+
var checkVal = value === null || value === void 0 ? void 0 : _mapInstanceProperty(value).call(value, function (itemVal) {
|
|
13
|
+
return itemVal.value;
|
|
14
|
+
});
|
|
15
|
+
var newVal = checkVal || [];
|
|
16
|
+
var checked = _indexOfInstanceProperty(newVal).call(newVal, item.value) !== -1;
|
|
17
|
+
return /*#__PURE__*/React.createElement(CheckBoxOption, {
|
|
18
|
+
label: item.label,
|
|
19
|
+
checked: checked
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var defaultFieldNames = {
|
|
25
|
+
label: "label",
|
|
26
|
+
value: "value"
|
|
27
|
+
};
|
|
28
|
+
var defaultSelectConfig = {
|
|
29
|
+
noMatchItemRender: function noMatchItemRender() {
|
|
30
|
+
return /*#__PURE__*/React.createElement(NoFindItem, {
|
|
31
|
+
label: "选项被删除,请重新选择"
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { defaultFieldNames, defaultModeConfig, defaultSelectConfig };
|
|
37
|
+
// powered by ww
|
|
@@ -0,0 +1,190 @@
|
|
|
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 _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js/object/get-own-property-descriptors';
|
|
7
|
+
import _Object$defineProperties from '@babel/runtime-corejs3/core-js/object/define-properties';
|
|
8
|
+
import _Object$defineProperty from '@babel/runtime-corejs3/core-js/object/define-property';
|
|
9
|
+
import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
|
|
10
|
+
import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
|
|
11
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
|
|
12
|
+
import _findIndexInstanceProperty from '@babel/runtime-corejs3/core-js/instance/find-index';
|
|
13
|
+
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js/instance/for-each';
|
|
14
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
|
|
15
|
+
import _Array$isArray from '@babel/runtime-corejs3/core-js/array/is-array';
|
|
16
|
+
import { useState, useEffect } from 'react';
|
|
17
|
+
|
|
18
|
+
var _excluded = ["index"],
|
|
19
|
+
_excluded2 = ["index"];
|
|
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 single = function single(_ref) {
|
|
23
|
+
var options = _ref.options,
|
|
24
|
+
value = _ref.value,
|
|
25
|
+
noMatchItemRender = _ref.noMatchItemRender;
|
|
26
|
+
var newOptions = options || [];
|
|
27
|
+
var index = _findIndexInstanceProperty(newOptions).call(newOptions, function (item) {
|
|
28
|
+
return item.value === value;
|
|
29
|
+
});
|
|
30
|
+
if (index !== -1) {
|
|
31
|
+
var label = newOptions[index].label;
|
|
32
|
+
return {
|
|
33
|
+
value: value,
|
|
34
|
+
label: label
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
value: value,
|
|
39
|
+
label: (noMatchItemRender === null || noMatchItemRender === void 0 ? void 0 : noMatchItemRender({
|
|
40
|
+
value: value
|
|
41
|
+
})) || value
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
var findNewValInOldVal = function findNewValInOldVal(val, oldVal) {
|
|
45
|
+
if (!oldVal) {
|
|
46
|
+
return -1;
|
|
47
|
+
}
|
|
48
|
+
return _findIndexInstanceProperty(oldVal).call(oldVal, function (item) {
|
|
49
|
+
return item.value === val;
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
var sourceDataProvider = function sourceDataProvider(_ref2, oldVal) {
|
|
53
|
+
_ref2.options;
|
|
54
|
+
var value = _ref2.value;
|
|
55
|
+
var oldData = [];
|
|
56
|
+
var newData = [];
|
|
57
|
+
_forEachInstanceProperty(value).call(value, function (item, i) {
|
|
58
|
+
var index = findNewValInOldVal(item, oldVal);
|
|
59
|
+
if (index === -1) {
|
|
60
|
+
newData.push({
|
|
61
|
+
value: item,
|
|
62
|
+
index: i
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
var newVal = oldVal === null || oldVal === void 0 ? void 0 : oldVal[index];
|
|
67
|
+
oldData.push(_objectSpread(_objectSpread({}, newVal), {}, {
|
|
68
|
+
index: i
|
|
69
|
+
}));
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
oldData: oldData,
|
|
73
|
+
newData: newData
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
var resultProvider = function resultProvider(newData, oldData, value) {
|
|
77
|
+
var newResult = new Array(value.length);
|
|
78
|
+
_forEachInstanceProperty(oldData).call(oldData, function (item) {
|
|
79
|
+
var index = item.index,
|
|
80
|
+
val = _objectWithoutProperties(item, _excluded);
|
|
81
|
+
newResult[index] = _objectSpread({}, val);
|
|
82
|
+
});
|
|
83
|
+
_forEachInstanceProperty(newData).call(newData, function (item) {
|
|
84
|
+
var index = item.index,
|
|
85
|
+
val = _objectWithoutProperties(item, _excluded2);
|
|
86
|
+
newResult[index] = _objectSpread({}, val);
|
|
87
|
+
});
|
|
88
|
+
return newResult;
|
|
89
|
+
};
|
|
90
|
+
var multiple = function multiple(_ref3, oldVal) {
|
|
91
|
+
var options = _ref3.options,
|
|
92
|
+
value = _ref3.value,
|
|
93
|
+
noMatchItemRender = _ref3.noMatchItemRender;
|
|
94
|
+
var _sourceDataProvider = sourceDataProvider({
|
|
95
|
+
options: options,
|
|
96
|
+
value: value
|
|
97
|
+
}, oldVal),
|
|
98
|
+
newData = _sourceDataProvider.newData,
|
|
99
|
+
oldData = _sourceDataProvider.oldData;
|
|
100
|
+
var newMatchVal = _mapInstanceProperty(newData).call(newData, function (item) {
|
|
101
|
+
var itemVal = item.value,
|
|
102
|
+
index = item.index;
|
|
103
|
+
var newItem = single({
|
|
104
|
+
options: options,
|
|
105
|
+
value: itemVal,
|
|
106
|
+
noMatchItemRender: noMatchItemRender
|
|
107
|
+
});
|
|
108
|
+
return _objectSpread(_objectSpread({}, newItem), {}, {
|
|
109
|
+
index: index
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
return resultProvider(newMatchVal, oldData, value);
|
|
113
|
+
};
|
|
114
|
+
var tag = function tag(_ref4, oldVal) {
|
|
115
|
+
var options = _ref4.options,
|
|
116
|
+
value = _ref4.value;
|
|
117
|
+
var _sourceDataProvider2 = sourceDataProvider({
|
|
118
|
+
options: options,
|
|
119
|
+
value: value
|
|
120
|
+
}, oldVal),
|
|
121
|
+
newData = _sourceDataProvider2.newData,
|
|
122
|
+
oldData = _sourceDataProvider2.oldData;
|
|
123
|
+
return resultProvider(newData, oldData, value);
|
|
124
|
+
};
|
|
125
|
+
var matchNotFind = function matchNotFind(_ref5, oldVale) {
|
|
126
|
+
var options = _ref5.options,
|
|
127
|
+
value = _ref5.value,
|
|
128
|
+
mode = _ref5.mode,
|
|
129
|
+
noMatchItemRender = _ref5.noMatchItemRender;
|
|
130
|
+
if (!mode) {
|
|
131
|
+
return single({
|
|
132
|
+
options: options,
|
|
133
|
+
value: value,
|
|
134
|
+
noMatchItemRender: noMatchItemRender
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (mode === "multiple") {
|
|
138
|
+
return multiple({
|
|
139
|
+
options: options,
|
|
140
|
+
value: value,
|
|
141
|
+
noMatchItemRender: noMatchItemRender
|
|
142
|
+
}, oldVale);
|
|
143
|
+
}
|
|
144
|
+
return tag({
|
|
145
|
+
options: options,
|
|
146
|
+
value: value
|
|
147
|
+
}, oldVale);
|
|
148
|
+
};
|
|
149
|
+
var useValueChange = function useValueChange(params) {
|
|
150
|
+
var labelInValue = params.labelInValue,
|
|
151
|
+
onChange = params.onChange,
|
|
152
|
+
value = params.value,
|
|
153
|
+
options = params.options,
|
|
154
|
+
mode = params.mode,
|
|
155
|
+
noMatchItemRender = params.noMatchItemRender;
|
|
156
|
+
var _useState = useState(),
|
|
157
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
158
|
+
val = _useState2[0],
|
|
159
|
+
setVal = _useState2[1];
|
|
160
|
+
var change = function change(changeVal) {
|
|
161
|
+
if (!onChange) {
|
|
162
|
+
setVal(changeVal);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
var newChangeVal = changeVal.value;
|
|
166
|
+
if (labelInValue) {
|
|
167
|
+
newChangeVal = changeVal;
|
|
168
|
+
}
|
|
169
|
+
if (_Array$isArray(changeVal)) {
|
|
170
|
+
newChangeVal = _mapInstanceProperty(changeVal).call(changeVal, function (item) {
|
|
171
|
+
return item.value;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
onChange(newChangeVal);
|
|
175
|
+
};
|
|
176
|
+
useEffect(function () {
|
|
177
|
+
if (options && value) {
|
|
178
|
+
setVal(function (oldVale) {
|
|
179
|
+
return matchNotFind(params, oldVale);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}, [value, options, mode, noMatchItemRender]);
|
|
183
|
+
return {
|
|
184
|
+
val: val,
|
|
185
|
+
change: change
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export { useValueChange };
|
|
190
|
+
// powered by ww
|
|
@@ -0,0 +1,12 @@
|
|
|
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>;
|
|
7
|
+
loading: boolean;
|
|
8
|
+
error: Error | undefined;
|
|
9
|
+
data: OptionType[] | undefined;
|
|
10
|
+
onSearch: (inputValue: string) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare const useFilterOption: ({ filterOption, serviceSearch, }: PartialHSelectProps) => boolean | import("rc-select/lib/Select").FilterFunc<import("rc-select/lib/Select").DefaultOptionType> | undefined;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// welcome to ww-building-blocks-tmp
|
|
2
|
+
import _asyncToGenerator from '@babel/runtime-corejs3/helpers/asyncToGenerator';
|
|
3
|
+
import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
|
|
4
|
+
import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
|
|
5
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
|
|
6
|
+
import _Promise from '@babel/runtime-corejs3/core-js/promise';
|
|
7
|
+
import { useState } from 'react';
|
|
8
|
+
import { useRequest } from 'ahooks';
|
|
9
|
+
|
|
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;
|
|
29
|
+
var _useState = useState(),
|
|
30
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
31
|
+
data = _useState2[0],
|
|
32
|
+
setData = _useState2[1];
|
|
33
|
+
var _useRequest = useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
34
|
+
var params,
|
|
35
|
+
type,
|
|
36
|
+
result,
|
|
37
|
+
resultOpt,
|
|
38
|
+
_args = arguments;
|
|
39
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
40
|
+
while (1) switch (_context.prev = _context.next) {
|
|
41
|
+
case 0:
|
|
42
|
+
params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
43
|
+
type = _args.length > 1 && _args[1] !== undefined ? _args[1] : "init";
|
|
44
|
+
if (type === "init") {
|
|
45
|
+
setData(undefined);
|
|
46
|
+
}
|
|
47
|
+
if (!request) {
|
|
48
|
+
_context.next = 8;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
_context.next = 6;
|
|
52
|
+
return request(params);
|
|
53
|
+
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
|
+
case "end":
|
|
61
|
+
return _context.stop();
|
|
62
|
+
}
|
|
63
|
+
}, _callee);
|
|
64
|
+
})), {
|
|
65
|
+
manual: manual,
|
|
66
|
+
debounceInterval: 300,
|
|
67
|
+
onSuccess: function onSuccess(resultData) {
|
|
68
|
+
setData(resultData);
|
|
69
|
+
}
|
|
70
|
+
}),
|
|
71
|
+
run = _useRequest.run,
|
|
72
|
+
loading = _useRequest.loading,
|
|
73
|
+
error = _useRequest.error;
|
|
74
|
+
var onSearch = function onSearch(inputValue) {
|
|
75
|
+
if (!serviceSearch) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
run({
|
|
79
|
+
inputValue: inputValue
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
run: run,
|
|
84
|
+
loading: loading,
|
|
85
|
+
error: error,
|
|
86
|
+
data: data,
|
|
87
|
+
onSearch: onSearch
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
var useFilterOption = function useFilterOption(_ref4) {
|
|
91
|
+
var filterOption = _ref4.filterOption,
|
|
92
|
+
serviceSearch = _ref4.serviceSearch;
|
|
93
|
+
if (serviceSearch) {
|
|
94
|
+
return function () {
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return filterOption;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export { useFilterOption, useOptionReq };
|
|
102
|
+
// powered by ww
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { HSelectProps } from "./modal";
|
|
3
|
+
declare const _default: ({ style, mode, options, modeConfig, value, onChange, fieldNames, request, manual, optionLabelProp, filterProvider, optionFilterProp, serviceSearch, onSearch: propsOnSearch, filterOption, showSearch, labelInValue, noMatchItemRender, allSelect, ...props }: HSelectProps) => JSX.Element;
|
|
4
|
+
export default _default;
|