@zykj2024/much-library 1.0.9 → 1.0.10
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/README.md +23 -23
- package/dist/McLazyLoader/demo/basic.d.ts +2 -0
- package/dist/McLazyLoader/demo/basic.js +33 -0
- package/dist/McLazyLoader/demo/form.d.ts +2 -0
- package/dist/McLazyLoader/demo/form.js +38 -0
- package/dist/McLazyLoader/demo/has-root.d.ts +2 -0
- package/dist/McLazyLoader/demo/has-root.js +44 -0
- package/dist/McLazyLoader/index.d.ts +28 -0
- package/dist/McLazyLoader/index.js +75 -0
- package/dist/McProSelect/demo/async.d.ts +2 -0
- package/dist/McProSelect/demo/async.js +66 -0
- package/dist/McProSelect/demo/base.d.ts +2 -0
- package/dist/McProSelect/demo/base.js +29 -0
- package/dist/McProSelect/demo/exclusion-async-rename.d.ts +3 -0
- package/dist/McProSelect/demo/exclusion-async-rename.js +103 -0
- package/dist/McProSelect/demo/exclusion-rename.d.ts +3 -0
- package/dist/McProSelect/demo/exclusion-rename.js +74 -0
- package/dist/McProSelect/demo/exclusion.d.ts +3 -0
- package/dist/McProSelect/demo/exclusion.js +70 -0
- package/dist/McProSelect/demo/require.d.ts +2 -0
- package/dist/McProSelect/demo/require.js +82 -0
- package/dist/McProSelect/index.d.ts +35 -0
- package/dist/McProSelect/index.js +152 -0
- package/dist/McSelect/demo/exclusion.d.ts +3 -0
- package/dist/McSelect/demo/exclusion.js +64 -0
- package/dist/McSelect/index.d.ts +2 -2
- package/dist/McSelect/index.js +8 -6
- package/dist/McTag/demo/demo1.d.ts +2 -0
- package/dist/McTag/demo/demo1.js +18 -0
- package/dist/McTag/demo/demo2.d.ts +2 -0
- package/dist/McTag/demo/demo2.js +20 -0
- package/dist/McTag/demo/demo3.d.ts +2 -0
- package/dist/McTag/demo/demo3.js +19 -0
- package/dist/McTag/demo/demo4.d.ts +2 -0
- package/dist/McTag/demo/demo4.js +22 -0
- package/dist/McTag/index.d.ts +22 -0
- package/dist/McTag/index.js +59 -0
- package/dist/McThemeConfig/customToken.json +2 -1
- package/dist/McThemeConfig/demo/radio.js +39 -0
- package/dist/McThemeConfig/globalStyle.js +2 -4
- package/dist/Utils/index.d.ts +5 -4
- package/dist/Utils/index.js +6 -26
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/package.json +3 -1
@@ -0,0 +1,82 @@
|
|
1
|
+
/**
|
2
|
+
* title: 内置为空校验
|
3
|
+
* description: 为空校验。required为true时,会自动校验是否为空。可通过设置required为string类型,自定义提示信息。
|
4
|
+
*/
|
5
|
+
import { Flex, Form } from 'antd';
|
6
|
+
import { McProSelect } from "../..";
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
8
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
9
|
+
var requireDemo = function requireDemo() {
|
10
|
+
return /*#__PURE__*/_jsx(Form, {
|
11
|
+
children: /*#__PURE__*/_jsxs(Flex, {
|
12
|
+
gap: "middle",
|
13
|
+
justify: "space-between",
|
14
|
+
children: [/*#__PURE__*/_jsx(McProSelect, {
|
15
|
+
name: "select1",
|
16
|
+
label: "select1",
|
17
|
+
fieldProps: {
|
18
|
+
defaultValue: 'lucy',
|
19
|
+
options: [{
|
20
|
+
value: 'jack',
|
21
|
+
label: 'Jack'
|
22
|
+
}, {
|
23
|
+
value: 'lucy',
|
24
|
+
label: 'Lucy'
|
25
|
+
}, {
|
26
|
+
value: 'Yiminghe',
|
27
|
+
label: 'yiminghe'
|
28
|
+
}, {
|
29
|
+
value: 'disabled',
|
30
|
+
label: 'Disabled',
|
31
|
+
disabled: true
|
32
|
+
}]
|
33
|
+
},
|
34
|
+
required: "\u8BF7\u9009\u62E9select1"
|
35
|
+
}), /*#__PURE__*/_jsx(McProSelect, {
|
36
|
+
name: "select2",
|
37
|
+
label: "select2",
|
38
|
+
fieldProps: {
|
39
|
+
defaultValue: 'lucy',
|
40
|
+
options: [{
|
41
|
+
value: 'jack',
|
42
|
+
label: 'Jack'
|
43
|
+
}, {
|
44
|
+
value: 'lucy',
|
45
|
+
label: 'Lucy'
|
46
|
+
}, {
|
47
|
+
value: 'Yiminghe',
|
48
|
+
label: 'yiminghe'
|
49
|
+
}, {
|
50
|
+
value: 'disabled',
|
51
|
+
label: 'Disabled',
|
52
|
+
disabled: true
|
53
|
+
}]
|
54
|
+
},
|
55
|
+
required: true
|
56
|
+
}), /*#__PURE__*/_jsx(McProSelect, {
|
57
|
+
name: "select3",
|
58
|
+
label: "select3",
|
59
|
+
multiple: true,
|
60
|
+
fieldProps: {
|
61
|
+
defaultValue: 'lucy',
|
62
|
+
options: [{
|
63
|
+
value: 'jack',
|
64
|
+
label: 'Jack'
|
65
|
+
}, {
|
66
|
+
value: 'lucy',
|
67
|
+
label: 'Lucy'
|
68
|
+
}, {
|
69
|
+
value: 'Yiminghe',
|
70
|
+
label: 'yiminghe'
|
71
|
+
}, {
|
72
|
+
value: 'disabled',
|
73
|
+
label: 'Disabled',
|
74
|
+
disabled: true
|
75
|
+
}]
|
76
|
+
},
|
77
|
+
required: true
|
78
|
+
})]
|
79
|
+
})
|
80
|
+
});
|
81
|
+
};
|
82
|
+
export default requireDemo;
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { FormItemProps } from 'antd/es/form/FormItem';
|
2
|
+
import { McSelectProps, Option } from '../McSelect';
|
3
|
+
type McProselectOptions<T> = (T & Partial<Pick<Option, 'title' | 'disabled'>> & {
|
4
|
+
extra?: T;
|
5
|
+
})[] | undefined;
|
6
|
+
type McProSelectProps<T = {
|
7
|
+
label: string;
|
8
|
+
value: string;
|
9
|
+
}> = Omit<FormItemProps, 'required'> & {
|
10
|
+
multiple?: boolean;
|
11
|
+
/** 默认为keyword */
|
12
|
+
searchKey?: string;
|
13
|
+
/** 为string时表示未填写时的提示文案 */
|
14
|
+
required?: boolean | string;
|
15
|
+
disabled?: boolean;
|
16
|
+
excludeIds?: (string | number)[];
|
17
|
+
fieldNames?: {
|
18
|
+
label?: keyof T;
|
19
|
+
value?: keyof T;
|
20
|
+
};
|
21
|
+
fieldProps?: Omit<McSelectProps, 'multiple' | 'fetchOption' | 'toFilterOptions' | 'options'> & {
|
22
|
+
options: McProselectOptions<T>;
|
23
|
+
};
|
24
|
+
request?: (params: {
|
25
|
+
current: number;
|
26
|
+
pageSize: number;
|
27
|
+
[key: string]: number | string;
|
28
|
+
}) => Promise<{
|
29
|
+
records: T[];
|
30
|
+
total: number;
|
31
|
+
[key: string]: any;
|
32
|
+
}>;
|
33
|
+
};
|
34
|
+
declare const McProSelect: <T extends Record<string, any>>({ label, name, fieldNames, required, request, multiple, disabled, searchKey, excludeIds, fieldProps, ...restProps }: McProSelectProps<T>) => import("react/jsx-runtime").JSX.Element;
|
35
|
+
export default McProSelect;
|
@@ -0,0 +1,152 @@
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
3
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
4
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
5
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
6
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
7
|
+
var _excluded = ["label", "name", "fieldNames", "required", "request", "multiple", "disabled", "searchKey", "excludeIds", "fieldProps"],
|
8
|
+
_excluded2 = ["options"],
|
9
|
+
_excluded3 = ["getValueFromEvent", "getValueProps", "rules"],
|
10
|
+
_excluded4 = ["current", "keyword"];
|
11
|
+
import { Form } from 'antd';
|
12
|
+
import { useMemo } from 'react';
|
13
|
+
import McSelect from "../McSelect";
|
14
|
+
import { isEmpty, isNil } from "../Utils";
|
15
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
16
|
+
var McProSelect = function McProSelect(_ref) {
|
17
|
+
var label = _ref.label,
|
18
|
+
name = _ref.name,
|
19
|
+
fieldNames = _ref.fieldNames,
|
20
|
+
required = _ref.required,
|
21
|
+
request = _ref.request,
|
22
|
+
multiple = _ref.multiple,
|
23
|
+
disabled = _ref.disabled,
|
24
|
+
_ref$searchKey = _ref.searchKey,
|
25
|
+
searchKey = _ref$searchKey === void 0 ? 'keyword' : _ref$searchKey,
|
26
|
+
excludeIds = _ref.excludeIds,
|
27
|
+
fieldProps = _ref.fieldProps,
|
28
|
+
restProps = _objectWithoutProperties(_ref, _excluded);
|
29
|
+
var labelKey = (fieldNames === null || fieldNames === void 0 ? void 0 : fieldNames.label) || 'label';
|
30
|
+
var valueKey = (fieldNames === null || fieldNames === void 0 ? void 0 : fieldNames.value) || 'value';
|
31
|
+
var _ref2 = fieldProps !== null && fieldProps !== void 0 ? fieldProps : {},
|
32
|
+
optionsFromFieldProps = _ref2.options,
|
33
|
+
restFieldProps = _objectWithoutProperties(_ref2, _excluded2);
|
34
|
+
var customGetValueFromEvent = restProps.getValueFromEvent,
|
35
|
+
customGetValueProps = restProps.getValueProps,
|
36
|
+
rules = restProps.rules,
|
37
|
+
restFormItemProps = _objectWithoutProperties(restProps, _excluded3);
|
38
|
+
|
39
|
+
// 生成用fieldNames映射后的options
|
40
|
+
var createReflectedOptions = function createReflectedOptions(options) {
|
41
|
+
if (!options) return undefined;
|
42
|
+
return options.map(function (item) {
|
43
|
+
var _item$title;
|
44
|
+
return {
|
45
|
+
label: item[labelKey !== null && labelKey !== void 0 ? labelKey : 'label'],
|
46
|
+
value: item[valueKey !== null && valueKey !== void 0 ? valueKey : 'value'],
|
47
|
+
title: (_item$title = item.title) !== null && _item$title !== void 0 ? _item$title : '',
|
48
|
+
disabled: !!item.disabled,
|
49
|
+
extra: item
|
50
|
+
};
|
51
|
+
});
|
52
|
+
};
|
53
|
+
|
54
|
+
// 静态option
|
55
|
+
var staticOption = useMemo(function () {
|
56
|
+
// 非异步请求时,根据fieldNames转换为label&value格式
|
57
|
+
if (optionsFromFieldProps && optionsFromFieldProps.length > 0) {
|
58
|
+
return createReflectedOptions(optionsFromFieldProps);
|
59
|
+
}
|
60
|
+
return undefined;
|
61
|
+
}, [optionsFromFieldProps]);
|
62
|
+
var getValueProps = function getValueProps(value) {
|
63
|
+
var _label$value;
|
64
|
+
if (customGetValueProps) {
|
65
|
+
return customGetValueProps(value);
|
66
|
+
}
|
67
|
+
if (isNil(value)) return {
|
68
|
+
value: value
|
69
|
+
};
|
70
|
+
return {
|
71
|
+
value: multiple ? (value === null || value === void 0 ? void 0 : value.map(function (x) {
|
72
|
+
return {
|
73
|
+
label: x[labelKey],
|
74
|
+
value: x[valueKey]
|
75
|
+
};
|
76
|
+
})) || [] : (_label$value = {
|
77
|
+
label: value === null || value === void 0 ? void 0 : value[labelKey],
|
78
|
+
value: value === null || value === void 0 ? void 0 : value[valueKey]
|
79
|
+
}) !== null && _label$value !== void 0 ? _label$value : undefined
|
80
|
+
};
|
81
|
+
};
|
82
|
+
var getValueFromEvent = function getValueFromEvent(_selectedValues, options) {
|
83
|
+
var _options$map, _options$extra;
|
84
|
+
if (customGetValueFromEvent) return customGetValueFromEvent(_selectedValues, options);
|
85
|
+
if (!_selectedValues) return undefined;
|
86
|
+
// 如果其他业务要的value是number[], 不是option,需要修改这里。用到的时候再修改吧
|
87
|
+
if (multiple) return (_options$map = options === null || options === void 0 ? void 0 : options.map(function (item) {
|
88
|
+
var _item$extra;
|
89
|
+
return (_item$extra = item.extra) !== null && _item$extra !== void 0 ? _item$extra : item;
|
90
|
+
})) !== null && _options$map !== void 0 ? _options$map : [];
|
91
|
+
return (_options$extra = options === null || options === void 0 ? void 0 : options.extra) !== null && _options$extra !== void 0 ? _options$extra : options;
|
92
|
+
};
|
93
|
+
var requiredMsg = typeof required === 'string' ? required : '请选择';
|
94
|
+
return /*#__PURE__*/_jsx(Form.Item, _objectSpread(_objectSpread({
|
95
|
+
label: label,
|
96
|
+
name: name,
|
97
|
+
getValueProps: getValueProps,
|
98
|
+
getValueFromEvent: getValueFromEvent,
|
99
|
+
rules: required ? [{
|
100
|
+
required: true,
|
101
|
+
message: requiredMsg,
|
102
|
+
validator: function validator(_, value) {
|
103
|
+
if (isNil(value) || isEmpty(value)) return Promise.reject(new Error(requiredMsg));
|
104
|
+
return Promise.resolve();
|
105
|
+
}
|
106
|
+
}].concat(_toConsumableArray(restProps.rules || [])) : rules
|
107
|
+
}, restFormItemProps), {}, {
|
108
|
+
children: /*#__PURE__*/_jsx(McSelect, _objectSpread(_objectSpread({
|
109
|
+
multiple: multiple,
|
110
|
+
showSearch: true,
|
111
|
+
maxTagCount: undefined,
|
112
|
+
toFilterOptions: function toFilterOptions(options) {
|
113
|
+
if (!excludeIds || excludeIds.filter(Boolean).length === 0) return options;
|
114
|
+
return options.filter(function (option) {
|
115
|
+
return !excludeIds.includes(option.value);
|
116
|
+
});
|
117
|
+
},
|
118
|
+
fetchOptions: request ? ( /*#__PURE__*/function () {
|
119
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
120
|
+
var _createReflectedOptio, _result$total;
|
121
|
+
var current, keyword, rest, result;
|
122
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
123
|
+
while (1) switch (_context.prev = _context.next) {
|
124
|
+
case 0:
|
125
|
+
current = params.current, keyword = params.keyword, rest = _objectWithoutProperties(params, _excluded4);
|
126
|
+
_context.next = 3;
|
127
|
+
return request(_objectSpread(_objectSpread({}, rest), {}, _defineProperty({
|
128
|
+
current: current !== null && current !== void 0 ? current : 1
|
129
|
+
}, searchKey, keyword)));
|
130
|
+
case 3:
|
131
|
+
result = _context.sent;
|
132
|
+
return _context.abrupt("return", {
|
133
|
+
data: (_createReflectedOptio = createReflectedOptions(result === null || result === void 0 ? void 0 : result.records)) !== null && _createReflectedOptio !== void 0 ? _createReflectedOptio : [],
|
134
|
+
total: (_result$total = result === null || result === void 0 ? void 0 : result.total) !== null && _result$total !== void 0 ? _result$total : 0
|
135
|
+
});
|
136
|
+
case 5:
|
137
|
+
case "end":
|
138
|
+
return _context.stop();
|
139
|
+
}
|
140
|
+
}, _callee);
|
141
|
+
}));
|
142
|
+
return function (_x) {
|
143
|
+
return _ref3.apply(this, arguments);
|
144
|
+
};
|
145
|
+
}()) : undefined,
|
146
|
+
options: staticOption
|
147
|
+
}, restFieldProps), {}, {
|
148
|
+
disabled: disabled
|
149
|
+
}))
|
150
|
+
}));
|
151
|
+
};
|
152
|
+
export default McProSelect;
|
@@ -0,0 +1,64 @@
|
|
1
|
+
/**
|
2
|
+
* title: 两个互斥的select
|
3
|
+
* description: select1中选择的选项会在select2中被排除,反之亦然。此方法同样支持远程select。
|
4
|
+
*/
|
5
|
+
import { Form } from 'antd';
|
6
|
+
import { McSelect } from "../..";
|
7
|
+
import React from 'react';
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
9
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
10
|
+
var options = [{
|
11
|
+
value: 'gold'
|
12
|
+
}, {
|
13
|
+
value: 'lime'
|
14
|
+
}, {
|
15
|
+
value: 'green'
|
16
|
+
}, {
|
17
|
+
value: 'cyan'
|
18
|
+
}];
|
19
|
+
var App = function App() {
|
20
|
+
return /*#__PURE__*/_jsxs(Form, {
|
21
|
+
name: "exclusion1",
|
22
|
+
children: [/*#__PURE__*/_jsx(Form.Item, {
|
23
|
+
noStyle: true,
|
24
|
+
dependencies: ['select2'],
|
25
|
+
children: function children(_ref) {
|
26
|
+
var getFieldValue = _ref.getFieldValue;
|
27
|
+
return /*#__PURE__*/_jsx(Form.Item, {
|
28
|
+
name: "select1",
|
29
|
+
children: /*#__PURE__*/_jsx(McSelect, {
|
30
|
+
options: options,
|
31
|
+
label: "select1",
|
32
|
+
toFilterOptions: function toFilterOptions(options) {
|
33
|
+
return options.filter(function (option) {
|
34
|
+
return option.value !== getFieldValue('select2');
|
35
|
+
});
|
36
|
+
}
|
37
|
+
})
|
38
|
+
});
|
39
|
+
}
|
40
|
+
}), /*#__PURE__*/_jsx(Form.Item, {
|
41
|
+
noStyle: true,
|
42
|
+
dependencies: ['select1'],
|
43
|
+
children: function children(_ref2) {
|
44
|
+
var getFieldValue = _ref2.getFieldValue;
|
45
|
+
return /*#__PURE__*/_jsx(Form.Item, {
|
46
|
+
label: "select2",
|
47
|
+
name: "select2",
|
48
|
+
children: /*#__PURE__*/_jsx(McSelect, {
|
49
|
+
style: {
|
50
|
+
width: '100%'
|
51
|
+
},
|
52
|
+
options: options,
|
53
|
+
toFilterOptions: function toFilterOptions(options) {
|
54
|
+
return options.filter(function (option) {
|
55
|
+
return option.value !== getFieldValue('select1');
|
56
|
+
});
|
57
|
+
}
|
58
|
+
})
|
59
|
+
});
|
60
|
+
}
|
61
|
+
})]
|
62
|
+
});
|
63
|
+
};
|
64
|
+
export default App;
|
package/dist/McSelect/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { SelectProps } from 'antd';
|
2
2
|
import { CSSProperties, FC, ReactNode } from 'react';
|
3
3
|
import './index.less';
|
4
|
-
interface Option {
|
4
|
+
export interface Option {
|
5
5
|
value: string | number;
|
6
6
|
label?: React.ReactNode;
|
7
7
|
title?: string;
|
@@ -25,6 +25,7 @@ export type FetchOptions = (params: {
|
|
25
25
|
export type McSelectProps = Omit<SelectProps, 'mode' | 'fieldNames'> & {
|
26
26
|
style?: CSSProperties;
|
27
27
|
className?: string;
|
28
|
+
toFilterOptions?: (options: Option[]) => Option[];
|
28
29
|
name?: string;
|
29
30
|
label?: ReactNode;
|
30
31
|
multiple?: boolean;
|
@@ -34,7 +35,6 @@ export type McSelectProps = Omit<SelectProps, 'mode' | 'fieldNames'> & {
|
|
34
35
|
pageSize?: number;
|
35
36
|
extra?: any;
|
36
37
|
options?: Option[];
|
37
|
-
[key: string]: any;
|
38
38
|
};
|
39
39
|
declare const McSelect: FC<McSelectProps>;
|
40
40
|
export default McSelect;
|
package/dist/McSelect/index.js
CHANGED
@@ -3,9 +3,9 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
3
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
4
4
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
5
5
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
6
|
-
var _excluded = ["style", "className", "label", "multiple", "changeOnHidden", "inexistent", "fetchOptions", "pageSize", "extra", "value", "onChange", "labelInValue", "options", "disabled", "maxTagCount", "onSearch", "onPopupScroll", "onBlur", "onDropdownVisibleChange"];
|
6
|
+
var _excluded = ["style", "className", "label", "multiple", "changeOnHidden", "inexistent", "fetchOptions", "pageSize", "extra", "value", "onChange", "labelInValue", "options", "disabled", "maxTagCount", "onSearch", "onPopupScroll", "onBlur", "onDropdownVisibleChange", "toFilterOptions"];
|
7
7
|
import { Empty, Popover, Select, Spin } from 'antd';
|
8
|
-
import {
|
8
|
+
import { debounce } from "../Utils";
|
9
9
|
import { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
10
10
|
import "./index.css";
|
11
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
@@ -32,6 +32,7 @@ var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
32
32
|
onPopupScroll = props.onPopupScroll,
|
33
33
|
onBlur = props.onBlur,
|
34
34
|
onDropdownVisibleChange = props.onDropdownVisibleChange,
|
35
|
+
toFilterOptions = props.toFilterOptions,
|
35
36
|
rest = _objectWithoutProperties(props, _excluded);
|
36
37
|
var _ref = typeof inexistent === 'boolean' ? {} : inexistent,
|
37
38
|
_ref$inexistentText = _ref.inexistentText,
|
@@ -87,6 +88,7 @@ var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
87
88
|
var _oldValue = useRef();
|
88
89
|
var _changeOption = useRef();
|
89
90
|
var _inexistent = useRef(false);
|
91
|
+
var filteredOptions = toFilterOptions ? toFilterOptions(selectOptions) : selectOptions; // 只要有render就需要重新生成options
|
90
92
|
|
91
93
|
// 监听值和备选项的变化(赋值备选项,执行不存在值的判断逻辑)
|
92
94
|
useEffect(function () {
|
@@ -209,7 +211,7 @@ var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
209
211
|
|
210
212
|
// 搜索防抖函数
|
211
213
|
var debounceSearcher = useMemo(function () {
|
212
|
-
return
|
214
|
+
return debounce(loadOptions, 350);
|
213
215
|
}, [loadOptions]);
|
214
216
|
|
215
217
|
// 文本框值变化时回调
|
@@ -231,7 +233,7 @@ var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
231
233
|
_extra.current = extra;
|
232
234
|
}, [extra, loadOptions]);
|
233
235
|
|
234
|
-
//
|
236
|
+
// 滚动触底防抖函数。注意需要pageSize要够大,否则不会触发滚动条滚动,也就不会翻页。建议用默认的20
|
235
237
|
var debounceScrollor = useMemo(function () {
|
236
238
|
var scroll = function scroll(e) {
|
237
239
|
var start = e.target.scrollTop + e.target.offsetHeight;
|
@@ -241,7 +243,7 @@ var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
241
243
|
loadOptions(searchValue, _current.current + 1);
|
242
244
|
}
|
243
245
|
};
|
244
|
-
return
|
246
|
+
return debounce(scroll, 350);
|
245
247
|
}, [loadOptions, searchValue]);
|
246
248
|
|
247
249
|
// 下拉列表滚动时的回调
|
@@ -297,7 +299,7 @@ var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
297
299
|
value: selectValue,
|
298
300
|
onChange: change,
|
299
301
|
labelInValue: labelInValue,
|
300
|
-
options:
|
302
|
+
options: filteredOptions,
|
301
303
|
disabled: disabled,
|
302
304
|
placeholder: "\u8BF7\u9009\u62E9",
|
303
305
|
showSearch: true,
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/**
|
2
|
+
* title: 设置本身宽度以支持ellipsis
|
3
|
+
* description: 在McTag上设置宽度,以支持ellipsis。同时支持复制
|
4
|
+
*/
|
5
|
+
import McTag from "../index";
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
7
|
+
export default (function () {
|
8
|
+
var uri = '/recommend/page/123/page/123/page/123';
|
9
|
+
return /*#__PURE__*/_jsx(McTag, {
|
10
|
+
style: {
|
11
|
+
maxWidth: 150
|
12
|
+
},
|
13
|
+
ellipsis: true,
|
14
|
+
color: "blue",
|
15
|
+
copyable: true,
|
16
|
+
children: uri
|
17
|
+
});
|
18
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/**
|
2
|
+
* title: 设置父组件宽度以支持ellipsis
|
3
|
+
* description: 在McTag上设置宽度,以支持ellipsis。同时支持复制
|
4
|
+
*/
|
5
|
+
import McTag from "../index";
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
7
|
+
export default (function () {
|
8
|
+
var uri = '/recommend/page/123/page/123/page/123';
|
9
|
+
return /*#__PURE__*/_jsx("div", {
|
10
|
+
style: {
|
11
|
+
width: 200
|
12
|
+
},
|
13
|
+
children: /*#__PURE__*/_jsx(McTag, {
|
14
|
+
color: "blue",
|
15
|
+
copyable: true,
|
16
|
+
ellipsis: true,
|
17
|
+
children: uri
|
18
|
+
})
|
19
|
+
});
|
20
|
+
});
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/**
|
2
|
+
* title: 支持复制
|
3
|
+
* description: 普通McTag模式也支持复制
|
4
|
+
*/
|
5
|
+
import { ExclamationCircleOutlined } from 'much-icons';
|
6
|
+
import McTag from "../index";
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
8
|
+
export default (function () {
|
9
|
+
return /*#__PURE__*/_jsx(McTag, {
|
10
|
+
style: {
|
11
|
+
maxWidth: 150
|
12
|
+
},
|
13
|
+
ellipsis: true,
|
14
|
+
color: "warning",
|
15
|
+
icon: /*#__PURE__*/_jsx(ExclamationCircleOutlined, {}),
|
16
|
+
copyable: true,
|
17
|
+
children: "click me to copy"
|
18
|
+
});
|
19
|
+
});
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/**
|
2
|
+
* title: 自定义ellipsis属性
|
3
|
+
*/
|
4
|
+
import McTag from "../index";
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
6
|
+
export default (function () {
|
7
|
+
var uri = '/recommend/page/123/page/123/page/123';
|
8
|
+
return /*#__PURE__*/_jsx("div", {
|
9
|
+
style: {
|
10
|
+
width: 200
|
11
|
+
},
|
12
|
+
children: /*#__PURE__*/_jsx(McTag, {
|
13
|
+
color: "blue",
|
14
|
+
copyable: true,
|
15
|
+
ellipsis: {
|
16
|
+
tooltip: true,
|
17
|
+
suffix: '等'
|
18
|
+
},
|
19
|
+
children: uri
|
20
|
+
})
|
21
|
+
});
|
22
|
+
});
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { TagProps } from 'antd';
|
3
|
+
import { EllipsisConfig } from 'antd/es/typography/Base';
|
4
|
+
interface McTagProps {
|
5
|
+
/**
|
6
|
+
* @description 为true时,使用默认行为,展示tooltip;为对象时,传递给Typography.Text的ellipsis属性
|
7
|
+
* @default undefined
|
8
|
+
*/
|
9
|
+
ellipsis?: true | EllipsisConfig;
|
10
|
+
/**
|
11
|
+
* @description 是否可复制
|
12
|
+
* @default 默认为false
|
13
|
+
*/
|
14
|
+
copyable?: boolean;
|
15
|
+
/**
|
16
|
+
* @description 省略模式时,设置文字样式。(一般用不上)
|
17
|
+
* @default undefined
|
18
|
+
*/
|
19
|
+
ellipsisTextStyle?: React.CSSProperties;
|
20
|
+
}
|
21
|
+
declare const McTag: (props: TagProps & McTagProps) => import("react/jsx-runtime").JSX.Element;
|
22
|
+
export default McTag;
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
3
|
+
var _excluded = ["ellipsis", "children", "copyable", "onClick", "ellipsisTextStyle"],
|
4
|
+
_excluded2 = ["style"];
|
5
|
+
import { message, Tag, Typography } from 'antd';
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
7
|
+
var McTag = function McTag(props) {
|
8
|
+
var ellipsis = props.ellipsis,
|
9
|
+
children = props.children,
|
10
|
+
copyable = props.copyable,
|
11
|
+
_onClick = props.onClick,
|
12
|
+
ellipsisTextStyle = props.ellipsisTextStyle,
|
13
|
+
tagProps = _objectWithoutProperties(props, _excluded);
|
14
|
+
var useEllipsis = typeof children === 'string' && !!ellipsis;
|
15
|
+
var style = tagProps.style,
|
16
|
+
restTagProps = _objectWithoutProperties(tagProps, _excluded2);
|
17
|
+
var renderChildren = function renderChildren() {
|
18
|
+
if (useEllipsis) {
|
19
|
+
return /*#__PURE__*/_jsx(Typography.Text, {
|
20
|
+
style: _objectSpread({
|
21
|
+
color: 'inherit',
|
22
|
+
fontSize: 'inherit'
|
23
|
+
}, ellipsisTextStyle),
|
24
|
+
ellipsis: ellipsis === true ? {
|
25
|
+
tooltip: children
|
26
|
+
} : ellipsis,
|
27
|
+
children: children
|
28
|
+
});
|
29
|
+
}
|
30
|
+
return children;
|
31
|
+
};
|
32
|
+
return /*#__PURE__*/_jsx(Tag, _objectSpread(_objectSpread({
|
33
|
+
onClick: function onClick(e) {
|
34
|
+
if (copyable) {
|
35
|
+
var copyText = typeof copyable === 'string' ? copyable : children;
|
36
|
+
if (!(typeof copyText === 'string')) {
|
37
|
+
if (process.env.NODE_ENV === 'development') throw Error('copyable prop only support string children or string copyable');
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
if (navigator.clipboard) {
|
41
|
+
navigator.clipboard.writeText(copyText).then(function () {
|
42
|
+
return message.success('复制成功!');
|
43
|
+
}, function () {
|
44
|
+
return message.error('复制失败!');
|
45
|
+
});
|
46
|
+
} else {
|
47
|
+
message.error('当前域名无权限使用剪切板');
|
48
|
+
}
|
49
|
+
}
|
50
|
+
if (_onClick) _onClick(e);
|
51
|
+
},
|
52
|
+
style: _objectSpread({
|
53
|
+
maxWidth: useEllipsis ? '100%' : 'none'
|
54
|
+
}, style)
|
55
|
+
}, restTagProps), {}, {
|
56
|
+
children: renderChildren()
|
57
|
+
}));
|
58
|
+
};
|
59
|
+
export default McTag;
|