@arco-design/mobile-react 2.19.1-941e02b.7 → 2.20.0
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/CHANGELOG.md +36 -0
- package/README.en-US.md +6 -6
- package/README.md +6 -6
- package/cjs/_helpers/type.d.ts +1 -1
- package/cjs/avatar/group.js +1 -1
- package/cjs/avatar/index.js +10 -13
- package/cjs/avatar/style/css/index.css +96 -126
- package/cjs/avatar/style/index.less +54 -72
- package/cjs/badge/index.js +6 -8
- package/cjs/badge/style/css/index.css +5 -5
- package/cjs/badge/style/index.less +5 -5
- package/cjs/button/hooks.d.ts +1 -2
- package/cjs/button/hooks.js +5 -3
- package/cjs/button/index.d.ts +12 -0
- package/cjs/button/index.js +40 -33
- package/cjs/button/style/css/index.css +75 -310
- package/cjs/button/style/index.less +32 -38
- package/cjs/count-down/demo/style/mobile.less +1 -1
- package/cjs/dropdown/dropdown.d.ts +3 -0
- package/cjs/dropdown/dropdown.js +306 -0
- package/cjs/dropdown/index.d.ts +3 -4
- package/cjs/dropdown/index.js +3 -303
- package/cjs/dropdown/options.js +2 -1
- package/cjs/dropdown/type.d.ts +20 -9
- package/cjs/dropdown-menu/dropdown-menu.d.ts +4 -0
- package/cjs/dropdown-menu/dropdown-menu.js +273 -0
- package/cjs/dropdown-menu/helper.d.ts +1 -1
- package/cjs/dropdown-menu/index.d.ts +2 -3
- package/cjs/dropdown-menu/index.js +2 -245
- package/cjs/dropdown-menu/type.d.ts +21 -20
- package/cjs/image/index.js +4 -1
- package/cjs/image/style/css/index.css +2 -1
- package/cjs/image/style/index.less +2 -1
- package/cjs/image-picker/index.d.ts +11 -8
- package/cjs/image-picker/index.js +19 -12
- package/cjs/image-picker/style/index.less +1 -1
- package/cjs/nav-bar/index.js +7 -2
- package/cjs/notify/index.d.ts +1 -0
- package/cjs/notify/index.js +12 -0
- package/cjs/notify/type.d.ts +1 -0
- package/cjs/show-monitor/index.js +31 -3
- package/cjs/transition/index.js +4 -2
- package/dist/index.js +677 -617
- package/dist/index.min.js +4 -4
- package/dist/style.css +174 -438
- package/dist/style.min.css +1 -1
- package/esm/_helpers/type.d.ts +1 -1
- package/esm/avatar/group.js +1 -1
- package/esm/avatar/index.js +10 -13
- package/esm/avatar/style/css/index.css +96 -126
- package/esm/avatar/style/index.less +54 -72
- package/esm/badge/index.js +6 -8
- package/esm/badge/style/css/index.css +5 -5
- package/esm/badge/style/index.less +5 -5
- package/esm/button/hooks.d.ts +1 -2
- package/esm/button/hooks.js +5 -3
- package/esm/button/index.d.ts +12 -0
- package/esm/button/index.js +42 -35
- package/esm/button/style/css/index.css +75 -310
- package/esm/button/style/index.less +32 -38
- package/esm/count-down/demo/style/mobile.less +1 -1
- package/esm/dropdown/dropdown.d.ts +3 -0
- package/esm/dropdown/dropdown.js +288 -0
- package/esm/dropdown/index.d.ts +3 -4
- package/esm/dropdown/index.js +3 -293
- package/esm/dropdown/options.js +2 -1
- package/esm/dropdown/type.d.ts +20 -9
- package/esm/dropdown-menu/dropdown-menu.d.ts +4 -0
- package/esm/dropdown-menu/dropdown-menu.js +256 -0
- package/esm/dropdown-menu/helper.d.ts +1 -1
- package/esm/dropdown-menu/index.d.ts +2 -3
- package/esm/dropdown-menu/index.js +2 -237
- package/esm/dropdown-menu/type.d.ts +21 -20
- package/esm/image/index.js +4 -1
- package/esm/image/style/css/index.css +2 -1
- package/esm/image/style/index.less +2 -1
- package/esm/image-picker/index.d.ts +11 -8
- package/esm/image-picker/index.js +19 -12
- package/esm/image-picker/style/index.less +1 -1
- package/esm/nav-bar/index.js +6 -2
- package/esm/notify/index.d.ts +1 -0
- package/esm/notify/index.js +1 -0
- package/esm/notify/type.d.ts +1 -0
- package/esm/show-monitor/index.js +31 -3
- package/esm/transition/index.js +4 -2
- package/package.json +3 -3
- package/tokens/app/arcodesign/default/css-variables.less +2 -1
- package/tokens/app/arcodesign/default/index.d.ts +2 -1
- package/tokens/app/arcodesign/default/index.js +2 -1
- package/tokens/app/arcodesign/default/index.json +123 -47
- package/tokens/app/arcodesign/default/index.less +2 -1
- package/umd/_helpers/type.d.ts +1 -1
- package/umd/avatar/group.js +1 -1
- package/umd/avatar/index.js +10 -13
- package/umd/avatar/style/css/index.css +96 -126
- package/umd/avatar/style/index.less +54 -72
- package/umd/badge/index.js +6 -8
- package/umd/badge/style/css/index.css +5 -5
- package/umd/badge/style/index.less +5 -5
- package/umd/button/hooks.d.ts +1 -2
- package/umd/button/hooks.js +5 -3
- package/umd/button/index.d.ts +12 -0
- package/umd/button/index.js +40 -33
- package/umd/button/style/css/index.css +75 -310
- package/umd/button/style/index.less +32 -38
- package/umd/count-down/demo/style/mobile.less +1 -1
- package/umd/dropdown/dropdown.d.ts +3 -0
- package/umd/dropdown/dropdown.js +309 -0
- package/umd/dropdown/index.d.ts +3 -4
- package/umd/dropdown/index.js +5 -298
- package/umd/dropdown/options.js +2 -1
- package/umd/dropdown/type.d.ts +20 -9
- package/umd/dropdown-menu/dropdown-menu.d.ts +4 -0
- package/umd/dropdown-menu/dropdown-menu.js +278 -0
- package/umd/dropdown-menu/helper.d.ts +1 -1
- package/umd/dropdown-menu/index.d.ts +2 -3
- package/umd/dropdown-menu/index.js +5 -241
- package/umd/dropdown-menu/type.d.ts +21 -20
- package/umd/image/index.js +4 -1
- package/umd/image/style/css/index.css +2 -1
- package/umd/image/style/index.less +2 -1
- package/umd/image-picker/index.d.ts +11 -8
- package/umd/image-picker/index.js +19 -12
- package/umd/image-picker/style/index.less +1 -1
- package/umd/nav-bar/index.js +9 -6
- package/umd/notify/index.d.ts +1 -0
- package/umd/notify/index.js +13 -4
- package/umd/notify/type.d.ts +1 -0
- package/umd/show-monitor/index.js +31 -3
- package/umd/transition/index.js +4 -2
package/cjs/dropdown/type.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { CSSProperties, ReactNode } from 'react';
|
2
|
+
export declare type OptionValueType = number | string;
|
2
3
|
export interface OptionsItem {
|
3
4
|
/**
|
4
5
|
* 选项名称
|
@@ -9,7 +10,7 @@ export interface OptionsItem {
|
|
9
10
|
* 选项标识
|
10
11
|
* @en option value
|
11
12
|
* */
|
12
|
-
value:
|
13
|
+
value: OptionValueType;
|
13
14
|
/**
|
14
15
|
* 选项是否可用,默认false表示可用
|
15
16
|
* @en Whether the option is available, the default false means available
|
@@ -111,6 +112,11 @@ export interface DropdownCommonProps {
|
|
111
112
|
* @default false
|
112
113
|
*/
|
113
114
|
useColumn?: boolean | number;
|
115
|
+
/**
|
116
|
+
* 选项附带图标
|
117
|
+
* @en Icon in each option
|
118
|
+
*/
|
119
|
+
optionIcon?: ReactNode;
|
114
120
|
/**
|
115
121
|
* 是否在打开下拉框时再加载内容
|
116
122
|
* @en Whether to reload the content when the dropdown box is opened
|
@@ -177,29 +183,29 @@ export interface SingleOptionProps {
|
|
177
183
|
* 默认选中值
|
178
184
|
* @en Default checked value
|
179
185
|
* */
|
180
|
-
defaultSelectedValue?:
|
186
|
+
defaultSelectedValue?: OptionValueType;
|
181
187
|
/**
|
182
188
|
* 当前选择的选项标识
|
183
189
|
* @en The currently selected option value
|
184
190
|
* */
|
185
|
-
selectedValue?:
|
191
|
+
selectedValue?: OptionValueType;
|
186
192
|
/**
|
187
193
|
* 点击选项时触发的回调函数
|
188
194
|
* @en Callback when clicking option
|
189
195
|
* */
|
190
|
-
onOptionClick?: (val:
|
196
|
+
onOptionClick?: (val: OptionValueType, op: OptionsItem) => void;
|
191
197
|
/**
|
192
198
|
* 当选项改变时触发的回调函数
|
193
199
|
* @en Callback when the option changes
|
194
200
|
* */
|
195
|
-
onOptionChange?: (val:
|
201
|
+
onOptionChange?: (val: OptionValueType, op: OptionsItem) => void;
|
196
202
|
}
|
197
203
|
export interface MultipleOptionProps {
|
198
204
|
multiple: true;
|
199
|
-
defaultSelectedValue?:
|
200
|
-
selectedValue?:
|
201
|
-
onOptionClick?: (selected: boolean, val:
|
202
|
-
onOptionChange?: (vals:
|
205
|
+
defaultSelectedValue?: OptionValueType[];
|
206
|
+
selectedValue?: OptionValueType[];
|
207
|
+
onOptionClick?: (selected: boolean, val: OptionValueType, op: OptionsItem) => void;
|
208
|
+
onOptionChange?: (vals: OptionValueType[], op: OptionsItem) => void;
|
203
209
|
}
|
204
210
|
export declare type OptionProps = SingleOptionProps | MultipleOptionProps;
|
205
211
|
export interface DropdownBasicProps extends DropdownCommonProps {
|
@@ -247,6 +253,11 @@ export interface DropdownOptionsBasicProps {
|
|
247
253
|
* @default false
|
248
254
|
*/
|
249
255
|
useColumn?: DropdownCommonProps['useColumn'];
|
256
|
+
/**
|
257
|
+
* 选项列表右侧图标
|
258
|
+
* @en Icon on the right side of the options list
|
259
|
+
*/
|
260
|
+
icon?: ReactNode;
|
250
261
|
}
|
251
262
|
export declare type DropdownOptionsProps = DropdownOptionsBasicProps & OptionProps;
|
252
263
|
export interface DropdownOptionsRef {
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { DropdownMenuRef } from './type';
|
3
|
+
import { DropdownProps, DropdownRef } from '../dropdown';
|
4
|
+
export declare function componentGenerator<P extends DropdownProps = DropdownProps, R extends DropdownRef = DropdownRef>(Comp: React.ForwardRefExoticComponent<P & React.RefAttributes<R>>): React.ForwardRefExoticComponent<(import("./type").DropdownMenuBasicProps & import("./type").SingleOptionProps & React.RefAttributes<DropdownMenuRef>) | (import("./type").DropdownMenuBasicProps & import("./type").MultipleOptionProps & React.RefAttributes<DropdownMenuRef>)>;
|
@@ -0,0 +1,273 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
exports.__esModule = true;
|
6
|
+
exports.componentGenerator = componentGenerator;
|
7
|
+
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
9
|
+
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
11
|
+
|
12
|
+
var _mobileUtils = require("@arco-design/mobile-utils");
|
13
|
+
|
14
|
+
var _contextProvider = require("../context-provider");
|
15
|
+
|
16
|
+
var _helper = require("./helper");
|
17
|
+
|
18
|
+
var _IconTriDown = _interopRequireDefault(require("../icon/IconTriDown"));
|
19
|
+
|
20
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
21
|
+
|
22
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
23
|
+
|
24
|
+
function componentGenerator(Comp) {
|
25
|
+
return /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
26
|
+
var _props$className = props.className,
|
27
|
+
className = _props$className === void 0 ? '' : _props$className,
|
28
|
+
_props$style = props.style,
|
29
|
+
style = _props$style === void 0 ? {} : _props$style,
|
30
|
+
_props$options = props.options,
|
31
|
+
options = _props$options === void 0 ? [] : _props$options,
|
32
|
+
_props$disabled = props.disabled,
|
33
|
+
disabled = _props$disabled === void 0 ? [] : _props$disabled,
|
34
|
+
_props$selectTips = props.selectTips,
|
35
|
+
selectTips = _props$selectTips === void 0 ? [] : _props$selectTips,
|
36
|
+
values = props.values,
|
37
|
+
_props$defaultValues = props.defaultValues,
|
38
|
+
defaultValues = _props$defaultValues === void 0 ? [] : _props$defaultValues,
|
39
|
+
icon = props.icon,
|
40
|
+
_props$chooseAndClose = props.chooseAndClose,
|
41
|
+
chooseAndClose = _props$chooseAndClose === void 0 ? true : _props$chooseAndClose,
|
42
|
+
selectIndex = props.selectIndex,
|
43
|
+
_props$defaultSelectI = props.defaultSelectIndex,
|
44
|
+
defaultSelectIndex = _props$defaultSelectI === void 0 ? 0 : _props$defaultSelectI,
|
45
|
+
showDropdown = props.showDropdown,
|
46
|
+
_props$defaultShowDro = props.defaultShowDropdown,
|
47
|
+
defaultShowDropdown = _props$defaultShowDro === void 0 ? false : _props$defaultShowDro,
|
48
|
+
onValuesChange = props.onValuesChange,
|
49
|
+
onSelectChange = props.onSelectChange,
|
50
|
+
onDropdownChange = props.onDropdownChange,
|
51
|
+
_props$getFormattedOp = props.getFormattedOptions,
|
52
|
+
getFormattedOptions = _props$getFormattedOp === void 0 ? _helper.getFormattedOptions : _props$getFormattedOp,
|
53
|
+
getContainer = props.getContainer,
|
54
|
+
children = props.children,
|
55
|
+
extraForDropdown = props.extraForDropdown;
|
56
|
+
|
57
|
+
var _useContext = (0, _react.useContext)(_contextProvider.GlobalContext),
|
58
|
+
prefixCls = _useContext.prefixCls,
|
59
|
+
locale = _useContext.locale;
|
60
|
+
|
61
|
+
var _useState = (0, _react.useState)(defaultValues),
|
62
|
+
innerValues = _useState[0],
|
63
|
+
setInnerValues = _useState[1];
|
64
|
+
|
65
|
+
var _useState2 = (0, _react.useState)(0),
|
66
|
+
defaultTop = _useState2[0],
|
67
|
+
setDefaultTop = _useState2[1];
|
68
|
+
|
69
|
+
var currentValues = values !== void 0 ? values : innerValues;
|
70
|
+
|
71
|
+
var _useState3 = (0, _react.useState)(defaultShowDropdown),
|
72
|
+
innerShowDropdown = _useState3[0],
|
73
|
+
setInnerShowDropdown = _useState3[1];
|
74
|
+
|
75
|
+
var dropdownShown = showDropdown !== void 0 ? showDropdown : innerShowDropdown;
|
76
|
+
|
77
|
+
var _useState4 = (0, _react.useState)(defaultSelectIndex),
|
78
|
+
innerSelectedIndex = _useState4[0],
|
79
|
+
setInnerSelectedIndex = _useState4[1];
|
80
|
+
|
81
|
+
var selectedIndex = selectIndex !== void 0 ? selectIndex : innerSelectedIndex;
|
82
|
+
var selectWrapper = (0, _react.useRef)(null);
|
83
|
+
var domRef = (0, _react.useRef)(null);
|
84
|
+
var defaultOpItem = {
|
85
|
+
label: locale == null ? void 0 : locale.DropdownMenu.select,
|
86
|
+
value: -1
|
87
|
+
};
|
88
|
+
/**
|
89
|
+
* 更新选项数组和选择情况
|
90
|
+
* @en Update options list and selection
|
91
|
+
*/
|
92
|
+
|
93
|
+
var _useMemo = (0, _react.useMemo)(function () {
|
94
|
+
return getFormattedOptions(options, currentValues);
|
95
|
+
}, [options, currentValues]),
|
96
|
+
formattedOptions = _useMemo.formattedOptions;
|
97
|
+
|
98
|
+
var selectedOptions = (0, _react.useMemo)(function () {
|
99
|
+
return formattedOptions.map(function (ops, index) {
|
100
|
+
if (props.multiple) {
|
101
|
+
var _value = currentValues[index] || [];
|
102
|
+
|
103
|
+
var opItems = ops.reduce(function (acc, op) {
|
104
|
+
return [].concat(acc, _value.includes(op.value) ? [op] : []);
|
105
|
+
}, []);
|
106
|
+
return opItems.length ? opItems : [defaultOpItem];
|
107
|
+
}
|
108
|
+
|
109
|
+
var value = currentValues[index];
|
110
|
+
return ops.find(function (op) {
|
111
|
+
return op.value === value;
|
112
|
+
}) || ops[0];
|
113
|
+
});
|
114
|
+
}, [formattedOptions, currentValues, props.multiple]);
|
115
|
+
/**
|
116
|
+
* 当下拉框的状态变化
|
117
|
+
* @en When the state of the dropdown box changes
|
118
|
+
*/
|
119
|
+
|
120
|
+
var handleShowDropdownChange = function handleShowDropdownChange(show, index) {
|
121
|
+
onDropdownChange && onDropdownChange(show, index);
|
122
|
+
setInnerShowDropdown(show);
|
123
|
+
};
|
124
|
+
|
125
|
+
var handleSelectedIndexChange = function handleSelectedIndexChange(idx) {
|
126
|
+
setInnerSelectedIndex(idx);
|
127
|
+
onSelectChange == null ? void 0 : onSelectChange(idx);
|
128
|
+
};
|
129
|
+
|
130
|
+
var handleValuesChange = function handleValuesChange(val) {
|
131
|
+
var newValue = [].concat(currentValues); // 级联情况下 selectedIndex 之后的选项值重置
|
132
|
+
// @en Option values are reset after selectedIndex in case of cascade
|
133
|
+
|
134
|
+
if ((0, _helper.isCascadeArray)(options)) {
|
135
|
+
newValue = newValue.slice(0, selectedIndex);
|
136
|
+
}
|
137
|
+
|
138
|
+
newValue[selectedIndex] = val;
|
139
|
+
newValue = getFormattedOptions(options, newValue).formattedValue;
|
140
|
+
setInnerValues(newValue);
|
141
|
+
onValuesChange == null ? void 0 : onValuesChange(newValue);
|
142
|
+
};
|
143
|
+
/**
|
144
|
+
* 处理选择框的点击事件
|
145
|
+
* @en Handle click event of dropdown box
|
146
|
+
*/
|
147
|
+
|
148
|
+
|
149
|
+
var handleSelectClick = function handleSelectClick(idx) {
|
150
|
+
if (disabled[idx]) return;
|
151
|
+
|
152
|
+
if (Number(idx) === selectedIndex) {
|
153
|
+
handleShowDropdownChange(!dropdownShown, idx);
|
154
|
+
} else {
|
155
|
+
handleSelectedIndexChange(idx);
|
156
|
+
if (!dropdownShown) handleShowDropdownChange(true, idx);
|
157
|
+
}
|
158
|
+
};
|
159
|
+
/**
|
160
|
+
* 判断是否为当前实例下的选择框
|
161
|
+
* @en Determine whether it is the dropdown box under the current instance
|
162
|
+
*/
|
163
|
+
|
164
|
+
|
165
|
+
var isCurrentSelectEl = function isCurrentSelectEl(target) {
|
166
|
+
var _ref = extraForDropdown || {},
|
167
|
+
isStopTouchEl = _ref.isStopTouchEl;
|
168
|
+
|
169
|
+
return (0, _helper.isRefDom)(target, selectWrapper) && (0, _helper.isClassNameDom)(target, 'select-item') || (isStopTouchEl == null ? void 0 : isStopTouchEl(target)) || false;
|
170
|
+
};
|
171
|
+
|
172
|
+
(0, _react.useImperativeHandle)(ref, function () {
|
173
|
+
return {
|
174
|
+
dom: domRef.current
|
175
|
+
};
|
176
|
+
});
|
177
|
+
(0, _react.useEffect)(function () {
|
178
|
+
var defaultContainer = selectWrapper.current;
|
179
|
+
var container = getContainer ? getContainer() || defaultContainer : defaultContainer;
|
180
|
+
setDefaultTop((container == null ? void 0 : container.getBoundingClientRect().bottom) || 0);
|
181
|
+
}, [getContainer, dropdownShown]);
|
182
|
+
|
183
|
+
var onCancel = props.onCancel || function () {
|
184
|
+
return handleShowDropdownChange(false);
|
185
|
+
};
|
186
|
+
|
187
|
+
var dropdownCommonProps = (0, _extends2.default)({
|
188
|
+
showDropdown: dropdownShown,
|
189
|
+
top: (extraForDropdown == null ? void 0 : extraForDropdown.top) || defaultTop,
|
190
|
+
onCancel: onCancel
|
191
|
+
}, extraForDropdown || {}, {
|
192
|
+
isStopTouchEl: isCurrentSelectEl
|
193
|
+
});
|
194
|
+
|
195
|
+
var renderSelectedLabel = function renderSelectedLabel(op, index) {
|
196
|
+
if (props.multiple === true) {
|
197
|
+
var multipleOp = op || [];
|
198
|
+
return props.renderSelectLabel ? props.renderSelectLabel(multipleOp, index) : /*#__PURE__*/_react.default.createElement("div", {
|
199
|
+
className: (0, _mobileUtils.cls)(prefixCls + "-select-item-label-text")
|
200
|
+
}, multipleOp.map(function (item) {
|
201
|
+
return item.label;
|
202
|
+
}).join(','));
|
203
|
+
}
|
204
|
+
|
205
|
+
var singleOp = op || [];
|
206
|
+
return props.renderSelectLabel ? props.renderSelectLabel(singleOp, index) : /*#__PURE__*/_react.default.createElement("div", {
|
207
|
+
className: (0, _mobileUtils.cls)(prefixCls + "-select-item-label-text")
|
208
|
+
}, singleOp.label);
|
209
|
+
};
|
210
|
+
|
211
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
212
|
+
ref: domRef,
|
213
|
+
className: (0, _mobileUtils.cls)(prefixCls + "-dropdown-menu all-border-box", className, {
|
214
|
+
show: dropdownShown
|
215
|
+
}),
|
216
|
+
style: style
|
217
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
218
|
+
className: (0, _mobileUtils.cls)(prefixCls + "-select"),
|
219
|
+
ref: selectWrapper
|
220
|
+
}, selectedOptions.map(function (op, index) {
|
221
|
+
var tip = selectTips[index] || '';
|
222
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
223
|
+
className: (0, _mobileUtils.cls)(prefixCls + "-select-item", {
|
224
|
+
'is-disabled': disabled[index],
|
225
|
+
'is-selected': dropdownShown && selectedIndex === index
|
226
|
+
}),
|
227
|
+
key: index,
|
228
|
+
"data-idx": index,
|
229
|
+
onClick: function onClick() {
|
230
|
+
return handleSelectClick(index);
|
231
|
+
}
|
232
|
+
}, tip.length > 0 && /*#__PURE__*/_react.default.createElement("span", {
|
233
|
+
className: (0, _mobileUtils.cls)(prefixCls + "-select-item-tip")
|
234
|
+
}, tip), /*#__PURE__*/_react.default.createElement("div", {
|
235
|
+
className: (0, _mobileUtils.cls)(prefixCls + "-select-item-label")
|
236
|
+
}, renderSelectedLabel(op, index), icon === void 0 ? /*#__PURE__*/_react.default.createElement(_IconTriDown.default, {
|
237
|
+
className: (0, _mobileUtils.cls)(prefixCls + "-select-item-icon", {
|
238
|
+
'is-show': dropdownShown && selectedIndex === index
|
239
|
+
})
|
240
|
+
}) : icon));
|
241
|
+
}), props.multiple === true ? /*#__PURE__*/_react.default.createElement(Comp, (0, _extends2.default)({
|
242
|
+
multiple: true,
|
243
|
+
options: formattedOptions[selectedIndex] || [],
|
244
|
+
selectedValue: currentValues[selectedIndex] || [],
|
245
|
+
onOptionClick: function onOptionClick(selected, val, op) {
|
246
|
+
props.onOptionClick == null ? void 0 : props.onOptionClick(selected, val, op, selectedIndex);
|
247
|
+
},
|
248
|
+
onOptionChange: function onOptionChange(val, op) {
|
249
|
+
props.onOptionChange == null ? void 0 : props.onOptionChange(val, op, selectedIndex);
|
250
|
+
handleValuesChange(val);
|
251
|
+
}
|
252
|
+
}, dropdownCommonProps, {
|
253
|
+
children: children
|
254
|
+
})) : /*#__PURE__*/_react.default.createElement(Comp, (0, _extends2.default)({
|
255
|
+
multiple: props.multiple,
|
256
|
+
options: formattedOptions[selectedIndex] || [],
|
257
|
+
selectedValue: currentValues[selectedIndex] || 0,
|
258
|
+
onOptionClick: function onOptionClick(val, op) {
|
259
|
+
props.onOptionClick == null ? void 0 : props.onOptionClick(val, op, selectedIndex);
|
260
|
+
|
261
|
+
if (chooseAndClose) {
|
262
|
+
handleShowDropdownChange(false, selectedIndex);
|
263
|
+
}
|
264
|
+
},
|
265
|
+
onOptionChange: function onOptionChange(val, op) {
|
266
|
+
props.onOptionChange == null ? void 0 : props.onOptionChange(val, op, selectedIndex);
|
267
|
+
handleValuesChange(val);
|
268
|
+
}
|
269
|
+
}, dropdownCommonProps, {
|
270
|
+
children: children
|
271
|
+
}))));
|
272
|
+
});
|
273
|
+
}
|
@@ -25,7 +25,7 @@ export declare function isString(icon: string | ReactNode): icon is string;
|
|
25
25
|
* */
|
26
26
|
export declare const getFormattedOptions: (options: OptionsItem[][] | string[] | CascadeOptions[], currentValues: ValueType) => {
|
27
27
|
formattedOptions: OptionsItem[][];
|
28
|
-
formattedValue: (number | number[])[];
|
28
|
+
formattedValue: (string | number | (string | number)[])[];
|
29
29
|
};
|
30
30
|
/**
|
31
31
|
* 判断是否为指定ref内的元素
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
import { DropdownMenuRef } from './type';
|
1
|
+
/// <reference types="react" />
|
3
2
|
export * from './type';
|
4
3
|
/**
|
5
4
|
* 下拉选择组件,点击选择器(select)展开下拉框(dropdown),展示选择项(options),兼容多个选择器的情况。
|
@@ -9,5 +8,5 @@ export * from './type';
|
|
9
8
|
* @name 下拉选择菜单
|
10
9
|
* @name_en DropdownMenu
|
11
10
|
*/
|
12
|
-
declare const DropdownMenu:
|
11
|
+
declare const DropdownMenu: import("react").ForwardRefExoticComponent<(import("./type").DropdownMenuBasicProps & import("./type").SingleOptionProps & import("react").RefAttributes<import("./type").DropdownMenuRef>) | (import("./type").DropdownMenuBasicProps & import("./type").MultipleOptionProps & import("react").RefAttributes<import("./type").DropdownMenuRef>)>;
|
13
12
|
export default DropdownMenu;
|
@@ -6,20 +6,10 @@ exports.__esModule = true;
|
|
6
6
|
var _exportNames = {};
|
7
7
|
exports.default = void 0;
|
8
8
|
|
9
|
-
var
|
10
|
-
|
11
|
-
var _react = _interopRequireWildcard(require("react"));
|
12
|
-
|
13
|
-
var _mobileUtils = require("@arco-design/mobile-utils");
|
14
|
-
|
15
|
-
var _contextProvider = require("../context-provider");
|
16
|
-
|
17
|
-
var _helper = require("./helper");
|
9
|
+
var _dropdownMenu = require("./dropdown-menu");
|
18
10
|
|
19
11
|
var _dropdown = _interopRequireDefault(require("../dropdown"));
|
20
12
|
|
21
|
-
var _IconTriDown = _interopRequireDefault(require("../icon/IconTriDown"));
|
22
|
-
|
23
13
|
var _type = require("./type");
|
24
14
|
|
25
15
|
Object.keys(_type).forEach(function (key) {
|
@@ -29,10 +19,6 @@ Object.keys(_type).forEach(function (key) {
|
|
29
19
|
exports[key] = _type[key];
|
30
20
|
});
|
31
21
|
|
32
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
33
|
-
|
34
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
35
|
-
|
36
22
|
/**
|
37
23
|
* 下拉选择组件,点击选择器(select)展开下拉框(dropdown),展示选择项(options),兼容多个选择器的情况。
|
38
24
|
* @en Dropdown component, click the selector (select) to expand the dropdown box (dropdown), display the options (options), compatible with multiple selectors.
|
@@ -41,235 +27,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
41
27
|
* @name 下拉选择菜单
|
42
28
|
* @name_en DropdownMenu
|
43
29
|
*/
|
44
|
-
var DropdownMenu =
|
45
|
-
var _props$className = props.className,
|
46
|
-
className = _props$className === void 0 ? '' : _props$className,
|
47
|
-
_props$style = props.style,
|
48
|
-
style = _props$style === void 0 ? {} : _props$style,
|
49
|
-
_props$options = props.options,
|
50
|
-
options = _props$options === void 0 ? [] : _props$options,
|
51
|
-
_props$disabled = props.disabled,
|
52
|
-
disabled = _props$disabled === void 0 ? [] : _props$disabled,
|
53
|
-
_props$selectTips = props.selectTips,
|
54
|
-
selectTips = _props$selectTips === void 0 ? [] : _props$selectTips,
|
55
|
-
values = props.values,
|
56
|
-
_props$defaultValues = props.defaultValues,
|
57
|
-
defaultValues = _props$defaultValues === void 0 ? [] : _props$defaultValues,
|
58
|
-
icon = props.icon,
|
59
|
-
_props$chooseAndClose = props.chooseAndClose,
|
60
|
-
chooseAndClose = _props$chooseAndClose === void 0 ? true : _props$chooseAndClose,
|
61
|
-
selectIndex = props.selectIndex,
|
62
|
-
_props$defaultSelectI = props.defaultSelectIndex,
|
63
|
-
defaultSelectIndex = _props$defaultSelectI === void 0 ? 0 : _props$defaultSelectI,
|
64
|
-
showDropdown = props.showDropdown,
|
65
|
-
_props$defaultShowDro = props.defaultShowDropdown,
|
66
|
-
defaultShowDropdown = _props$defaultShowDro === void 0 ? false : _props$defaultShowDro,
|
67
|
-
renderSelectLabel = props.renderSelectLabel,
|
68
|
-
onValuesChange = props.onValuesChange,
|
69
|
-
onSelectChange = props.onSelectChange,
|
70
|
-
onDropdownChange = props.onDropdownChange,
|
71
|
-
_props$getFormattedOp = props.getFormattedOptions,
|
72
|
-
getFormattedOptions = _props$getFormattedOp === void 0 ? _helper.getFormattedOptions : _props$getFormattedOp,
|
73
|
-
children = props.children,
|
74
|
-
extraForDropdown = props.extraForDropdown;
|
75
|
-
|
76
|
-
var _useContext = (0, _react.useContext)(_contextProvider.GlobalContext),
|
77
|
-
prefixCls = _useContext.prefixCls,
|
78
|
-
locale = _useContext.locale;
|
79
|
-
|
80
|
-
var _useState = (0, _react.useState)(defaultValues),
|
81
|
-
innerValues = _useState[0],
|
82
|
-
setInnerValues = _useState[1];
|
83
|
-
|
84
|
-
var _useState2 = (0, _react.useState)(0),
|
85
|
-
defaultTop = _useState2[0],
|
86
|
-
setDefaultTop = _useState2[1];
|
87
|
-
|
88
|
-
var currentValues = values !== void 0 ? values : innerValues;
|
89
|
-
|
90
|
-
var _useState3 = (0, _react.useState)(defaultShowDropdown),
|
91
|
-
innerShowDropdown = _useState3[0],
|
92
|
-
setInnerShowDropdown = _useState3[1];
|
93
|
-
|
94
|
-
var dropdownShown = showDropdown !== void 0 ? showDropdown : innerShowDropdown;
|
95
|
-
|
96
|
-
var _useState4 = (0, _react.useState)(defaultSelectIndex),
|
97
|
-
innerSelectedIndex = _useState4[0],
|
98
|
-
setInnerSelectedIndex = _useState4[1];
|
99
|
-
|
100
|
-
var selectedIndex = selectIndex !== void 0 ? selectIndex : innerSelectedIndex;
|
101
|
-
var selectWrapper = (0, _react.useRef)(null);
|
102
|
-
var domRef = (0, _react.useRef)(null);
|
103
|
-
var defaultOpItem = {
|
104
|
-
label: locale == null ? void 0 : locale.DropdownMenu.select,
|
105
|
-
value: -1
|
106
|
-
};
|
107
|
-
/**
|
108
|
-
* 下拉框的容器
|
109
|
-
* @en Dropdown container
|
110
|
-
*/
|
111
|
-
|
112
|
-
var getContainer = (0, _react.useCallback)(function () {
|
113
|
-
if (props.getContainer) {
|
114
|
-
return props.getContainer() || selectWrapper.current;
|
115
|
-
}
|
116
|
-
|
117
|
-
return selectWrapper.current;
|
118
|
-
}, [selectWrapper.current]);
|
119
|
-
/**
|
120
|
-
* 更新选项数组和选择情况
|
121
|
-
* @en Update options list and selection
|
122
|
-
*/
|
123
|
-
|
124
|
-
var _useMemo = (0, _react.useMemo)(function () {
|
125
|
-
return getFormattedOptions(options, currentValues);
|
126
|
-
}, [options, currentValues]),
|
127
|
-
formattedOptions = _useMemo.formattedOptions;
|
128
|
-
|
129
|
-
var selectedOptions = (0, _react.useMemo)(function () {
|
130
|
-
return formattedOptions.map(function (ops, index) {
|
131
|
-
return ops.find(function (op) {
|
132
|
-
var value = currentValues[index];
|
133
|
-
return Array.isArray(value) ? value.includes(op.value) : op.value === value;
|
134
|
-
}) || (props.multiple ? defaultOpItem : ops[0]);
|
135
|
-
});
|
136
|
-
}, [formattedOptions, currentValues]);
|
137
|
-
/**
|
138
|
-
* 当下拉框的状态变化
|
139
|
-
* @en When the state of the dropdown box changes
|
140
|
-
*/
|
141
|
-
|
142
|
-
var handleShowDropdownChange = function handleShowDropdownChange(show, index) {
|
143
|
-
onDropdownChange && onDropdownChange(show, index);
|
144
|
-
setInnerShowDropdown(show);
|
145
|
-
};
|
146
|
-
|
147
|
-
var handleSelectedIndexChange = function handleSelectedIndexChange(idx) {
|
148
|
-
setInnerSelectedIndex(idx);
|
149
|
-
onSelectChange == null ? void 0 : onSelectChange(idx);
|
150
|
-
};
|
151
|
-
|
152
|
-
var handleValuesChange = function handleValuesChange(val) {
|
153
|
-
var newValue = [].concat(currentValues); // 级联情况下 selectedIndex 之后的选项值重置
|
154
|
-
// @en Option values are reset after selectedIndex in case of cascade
|
155
|
-
|
156
|
-
if ((0, _helper.isCascadeArray)(options)) {
|
157
|
-
newValue = newValue.slice(0, selectedIndex);
|
158
|
-
}
|
159
|
-
|
160
|
-
newValue[selectedIndex] = val;
|
161
|
-
newValue = getFormattedOptions(options, newValue).formattedValue;
|
162
|
-
setInnerValues(newValue);
|
163
|
-
onValuesChange == null ? void 0 : onValuesChange(newValue);
|
164
|
-
};
|
165
|
-
/**
|
166
|
-
* 处理选择框的点击事件
|
167
|
-
* @en Handle click event of dropdown box
|
168
|
-
*/
|
169
|
-
|
170
|
-
|
171
|
-
var handleSelectClick = function handleSelectClick(idx) {
|
172
|
-
if (disabled[idx]) return;
|
173
|
-
|
174
|
-
if (Number(idx) === selectedIndex) {
|
175
|
-
handleShowDropdownChange(!dropdownShown, idx);
|
176
|
-
} else {
|
177
|
-
handleSelectedIndexChange(idx);
|
178
|
-
if (!dropdownShown) handleShowDropdownChange(true, idx);
|
179
|
-
}
|
180
|
-
};
|
181
|
-
/**
|
182
|
-
* 判断是否为当前实例下的选择框
|
183
|
-
* @en Determine whether it is the dropdown box under the current instance
|
184
|
-
*/
|
185
|
-
|
186
|
-
|
187
|
-
var isCurrentSelectEl = function isCurrentSelectEl(target) {
|
188
|
-
var _ref = extraForDropdown || {},
|
189
|
-
isStopTouchEl = _ref.isStopTouchEl;
|
190
|
-
|
191
|
-
return (0, _helper.isRefDom)(target, selectWrapper) && (0, _helper.isClassNameDom)(target, 'select-item') || (isStopTouchEl == null ? void 0 : isStopTouchEl(target)) || false;
|
192
|
-
};
|
193
|
-
|
194
|
-
(0, _react.useImperativeHandle)(ref, function () {
|
195
|
-
return {
|
196
|
-
dom: domRef.current
|
197
|
-
};
|
198
|
-
});
|
199
|
-
(0, _react.useEffect)(function () {
|
200
|
-
var _getContainer;
|
201
|
-
|
202
|
-
setDefaultTop(((_getContainer = getContainer()) == null ? void 0 : _getContainer.getBoundingClientRect().bottom) || 0);
|
203
|
-
}, [getContainer, dropdownShown]);
|
204
|
-
|
205
|
-
var onCancel = props.onCancel || function () {
|
206
|
-
return handleShowDropdownChange(false);
|
207
|
-
};
|
208
|
-
|
209
|
-
var dropdownCommonProps = (0, _extends2.default)({
|
210
|
-
showDropdown: dropdownShown,
|
211
|
-
top: (extraForDropdown == null ? void 0 : extraForDropdown.top) || defaultTop,
|
212
|
-
onCancel: onCancel
|
213
|
-
}, extraForDropdown || {}, {
|
214
|
-
isStopTouchEl: isCurrentSelectEl
|
215
|
-
});
|
216
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
217
|
-
ref: domRef,
|
218
|
-
className: (0, _mobileUtils.cls)(prefixCls + "-dropdown-menu all-border-box " + (dropdownShown ? 'show' : ''), className),
|
219
|
-
style: style
|
220
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
221
|
-
className: (0, _mobileUtils.cls)(prefixCls + "-select"),
|
222
|
-
ref: selectWrapper
|
223
|
-
}, selectedOptions.map(function (op, index) {
|
224
|
-
var tip = selectTips[index] || '';
|
225
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
226
|
-
className: (0, _mobileUtils.cls)(prefixCls + "-select-item", {
|
227
|
-
'is-disabled': disabled[index],
|
228
|
-
'is-selected': dropdownShown && selectedIndex === index
|
229
|
-
}),
|
230
|
-
key: index,
|
231
|
-
"data-idx": index,
|
232
|
-
onClick: function onClick() {
|
233
|
-
return handleSelectClick(index);
|
234
|
-
}
|
235
|
-
}, tip.length > 0 && /*#__PURE__*/_react.default.createElement("span", {
|
236
|
-
className: (0, _mobileUtils.cls)(prefixCls + "-select-item-tip")
|
237
|
-
}, tip), /*#__PURE__*/_react.default.createElement("div", {
|
238
|
-
className: (0, _mobileUtils.cls)(prefixCls + "-select-item-label")
|
239
|
-
}, renderSelectLabel ? renderSelectLabel(op, index) : /*#__PURE__*/_react.default.createElement("div", {
|
240
|
-
className: (0, _mobileUtils.cls)(prefixCls + "-select-item-label-text")
|
241
|
-
}, op.label), icon === void 0 ? /*#__PURE__*/_react.default.createElement(_IconTriDown.default, {
|
242
|
-
className: (0, _mobileUtils.cls)(prefixCls + "-select-item-icon", {
|
243
|
-
'is-show': dropdownShown && selectedIndex === index
|
244
|
-
})
|
245
|
-
}) : icon));
|
246
|
-
}), props.multiple === true ? /*#__PURE__*/_react.default.createElement(_dropdown.default, (0, _extends2.default)({
|
247
|
-
multiple: true,
|
248
|
-
options: formattedOptions[selectedIndex] || [],
|
249
|
-
selectedValue: currentValues[selectedIndex] || [],
|
250
|
-
onOptionClick: function onOptionClick(selected, val, op) {
|
251
|
-
props.onOptionClick == null ? void 0 : props.onOptionClick(selected, val, op, selectedIndex);
|
252
|
-
},
|
253
|
-
onOptionChange: function onOptionChange(val, op) {
|
254
|
-
props.onOptionChange == null ? void 0 : props.onOptionChange(val, op, selectedIndex);
|
255
|
-
handleValuesChange(val);
|
256
|
-
}
|
257
|
-
}, dropdownCommonProps), children) : /*#__PURE__*/_react.default.createElement(_dropdown.default, (0, _extends2.default)({
|
258
|
-
multiple: props.multiple,
|
259
|
-
options: formattedOptions[selectedIndex] || [],
|
260
|
-
selectedValue: currentValues[selectedIndex] || 0,
|
261
|
-
onOptionClick: function onOptionClick(val, op) {
|
262
|
-
props.onOptionClick == null ? void 0 : props.onOptionClick(val, op, selectedIndex);
|
263
|
-
|
264
|
-
if (chooseAndClose) {
|
265
|
-
handleShowDropdownChange(false, selectedIndex);
|
266
|
-
}
|
267
|
-
},
|
268
|
-
onOptionChange: function onOptionChange(val, op) {
|
269
|
-
props.onOptionChange == null ? void 0 : props.onOptionChange(val, op, selectedIndex);
|
270
|
-
handleValuesChange(val);
|
271
|
-
}
|
272
|
-
}, dropdownCommonProps), children)));
|
273
|
-
});
|
30
|
+
var DropdownMenu = (0, _dropdownMenu.componentGenerator)(_dropdown.default);
|
274
31
|
var _default = DropdownMenu;
|
275
32
|
exports.default = _default;
|