@arco-design/mobile-react 2.19.2-ee92494.5 → 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 +23 -0
- package/README.en-US.md +4 -4
- package/README.md +4 -4
- 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/demo/style/mobile.less +0 -4
- package/cjs/button/hooks.d.ts +1 -2
- package/cjs/button/hooks.js +5 -3
- package/cjs/button/index.d.ts +1 -1
- package/cjs/button/index.js +28 -33
- package/cjs/button/style/css/index.css +75 -310
- package/cjs/button/style/index.less +32 -38
- 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 +6 -6
- package/cjs/image-picker/index.js +4 -3
- package/cjs/nav-bar/index.js +7 -2
- package/cjs/show-monitor/index.js +31 -3
- package/dist/index.js +644 -604
- package/dist/index.min.js +3 -3
- package/dist/style.css +174 -438
- package/dist/style.min.css +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/demo/style/mobile.less +0 -4
- package/esm/button/hooks.d.ts +1 -2
- package/esm/button/hooks.js +5 -3
- package/esm/button/index.d.ts +1 -1
- package/esm/button/index.js +30 -35
- package/esm/button/style/css/index.css +75 -310
- package/esm/button/style/index.less +32 -38
- 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 +6 -6
- package/esm/image-picker/index.js +4 -3
- package/esm/nav-bar/index.js +6 -2
- package/esm/show-monitor/index.js +31 -3
- 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 +27 -15
- package/tokens/app/arcodesign/default/index.less +2 -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/demo/style/mobile.less +0 -4
- package/umd/button/hooks.d.ts +1 -2
- package/umd/button/hooks.js +5 -3
- package/umd/button/index.d.ts +1 -1
- package/umd/button/index.js +28 -33
- package/umd/button/style/css/index.css +75 -310
- package/umd/button/style/index.less +32 -38
- 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 +6 -6
- package/umd/image-picker/index.js +4 -3
- package/umd/nav-bar/index.js +9 -6
- package/umd/show-monitor/index.js +31 -3
@@ -0,0 +1,306 @@
|
|
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 _reactTransitionGroup = require("react-transition-group");
|
15
|
+
|
16
|
+
var _contextProvider = require("../context-provider");
|
17
|
+
|
18
|
+
var _helpers = require("../_helpers");
|
19
|
+
|
20
|
+
var _portal = _interopRequireDefault(require("../portal"));
|
21
|
+
|
22
|
+
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); }
|
23
|
+
|
24
|
+
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; }
|
25
|
+
|
26
|
+
function componentGenerator(Comp) {
|
27
|
+
return /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
28
|
+
var optionsWrapper = (0, _react.useRef)(null);
|
29
|
+
var domRef = (0, _react.useRef)(null);
|
30
|
+
var _props$className = props.className,
|
31
|
+
className = _props$className === void 0 ? '' : _props$className,
|
32
|
+
_props$style = props.style,
|
33
|
+
style = _props$style === void 0 ? {} : _props$style,
|
34
|
+
_props$options = props.options,
|
35
|
+
options = _props$options === void 0 ? [] : _props$options,
|
36
|
+
_props$showDropdown = props.showDropdown,
|
37
|
+
showDropdown = _props$showDropdown === void 0 ? false : _props$showDropdown,
|
38
|
+
_props$showMask = props.showMask,
|
39
|
+
showMask = _props$showMask === void 0 ? true : _props$showMask,
|
40
|
+
_props$direction = props.direction,
|
41
|
+
direction = _props$direction === void 0 ? 'down' : _props$direction,
|
42
|
+
height = props.height,
|
43
|
+
_props$maxHeight = props.maxHeight,
|
44
|
+
maxHeight = _props$maxHeight === void 0 ? 500 : _props$maxHeight,
|
45
|
+
_props$touchToClose = props.touchToClose,
|
46
|
+
touchToClose = _props$touchToClose === void 0 ? true : _props$touchToClose,
|
47
|
+
useColumn = props.useColumn,
|
48
|
+
optionIcon = props.optionIcon,
|
49
|
+
multiple = props.multiple,
|
50
|
+
defaultSelectedValue = props.defaultSelectedValue,
|
51
|
+
onCancel = props.onCancel,
|
52
|
+
getAnchorElement = props.getAnchorElement,
|
53
|
+
isStopTouchEl = props.isStopTouchEl,
|
54
|
+
getStopTouchElements = props.getStopTouchElements,
|
55
|
+
_props$getScrollConta = props.getScrollContainer,
|
56
|
+
getScrollContainer = _props$getScrollConta === void 0 ? function () {
|
57
|
+
return optionsWrapper.current;
|
58
|
+
} : _props$getScrollConta,
|
59
|
+
getPortalContainer = props.getPortalContainer,
|
60
|
+
_props$clickOtherToCl = props.clickOtherToClose,
|
61
|
+
clickOtherToClose = _props$clickOtherToCl === void 0 ? true : _props$clickOtherToCl,
|
62
|
+
_props$dropdownAnimat = props.dropdownAnimationTimeout,
|
63
|
+
dropdownAnimationTimeout = _props$dropdownAnimat === void 0 ? 300 : _props$dropdownAnimat,
|
64
|
+
_props$dropdownAnimat2 = props.dropdownAnimationFunction,
|
65
|
+
dropdownAnimationFunction = _props$dropdownAnimat2 === void 0 ? 'cubic-bezier(0.32, 0.96, 0.6, 1)' : _props$dropdownAnimat2,
|
66
|
+
_props$maskAnimationT = props.maskAnimationTimeout,
|
67
|
+
maskAnimationTimeout = _props$maskAnimationT === void 0 ? 500 : _props$maskAnimationT,
|
68
|
+
_props$maskAnimationF = props.maskAnimationFunction,
|
69
|
+
maskAnimationFunction = _props$maskAnimationF === void 0 ? 'cubic-bezier(0.32, 0.96, 0.6, 1)' : _props$maskAnimationF,
|
70
|
+
_props$mountOnEnter = props.mountOnEnter,
|
71
|
+
mountOnEnter = _props$mountOnEnter === void 0 ? true : _props$mountOnEnter,
|
72
|
+
_props$unmountOnExit = props.unmountOnExit,
|
73
|
+
unmountOnExit = _props$unmountOnExit === void 0 ? true : _props$unmountOnExit,
|
74
|
+
_props$preventBodyScr = props.preventBodyScroll,
|
75
|
+
preventBodyScroll = _props$preventBodyScr === void 0 ? true : _props$preventBodyScr,
|
76
|
+
initialBodyOverflow = props.initialBodyOverflow;
|
77
|
+
var system = (0, _helpers.useSystem)();
|
78
|
+
|
79
|
+
var _useWindowSize = (0, _helpers.useWindowSize)(),
|
80
|
+
windowHeight = _useWindowSize.windowHeight,
|
81
|
+
windowWidth = _useWindowSize.windowWidth;
|
82
|
+
|
83
|
+
var _useState = (0, _react.useState)({
|
84
|
+
top: '',
|
85
|
+
bottom: ''
|
86
|
+
}),
|
87
|
+
positionStyle = _useState[0],
|
88
|
+
setPositionStyle = _useState[1];
|
89
|
+
|
90
|
+
var _useState2 = (0, _react.useState)(function () {
|
91
|
+
var defaultValue = multiple ? [] : 0;
|
92
|
+
return defaultSelectedValue !== void 0 ? defaultSelectedValue : defaultValue;
|
93
|
+
}),
|
94
|
+
innerValue = _useState2[0],
|
95
|
+
setInnerValue = _useState2[1]; // down=0为向上展开,1为向下展开
|
96
|
+
// @en down=0 is to expand upwards, 1 is to expand downwards
|
97
|
+
|
98
|
+
|
99
|
+
var _useState3 = (0, _react.useState)(direction === 'down'),
|
100
|
+
down = _useState3[0],
|
101
|
+
setDown = _useState3[1];
|
102
|
+
|
103
|
+
var maskHeight = (0, _react.useRef)(0);
|
104
|
+
var optionsContainer = (0, _react.useRef)(null);
|
105
|
+
var dropdownContainer = (0, _react.useRef)(null);
|
106
|
+
|
107
|
+
var _useState4 = (0, _react.useState)(0),
|
108
|
+
optionsWrapperHeight = _useState4[0],
|
109
|
+
setOptionsWrapperHeight = _useState4[1];
|
110
|
+
/**
|
111
|
+
* 判断是否阻止touch事件
|
112
|
+
* @en Determine whether to block touch events
|
113
|
+
* */
|
114
|
+
|
115
|
+
|
116
|
+
var ifStopTouch = function ifStopTouch(el) {
|
117
|
+
var _dropdownContainer$cu;
|
118
|
+
|
119
|
+
if (isStopTouchEl) return isStopTouchEl(el);
|
120
|
+
var tempEl = el;
|
121
|
+
var elements = getStopTouchElements ? getStopTouchElements() : [(_dropdownContainer$cu = dropdownContainer.current) == null ? void 0 : _dropdownContainer$cu.parentElement];
|
122
|
+
|
123
|
+
for (var i = 0; i < elements.length; i++) {
|
124
|
+
while (tempEl && elements[i]) {
|
125
|
+
if (tempEl === elements[i]) {
|
126
|
+
return true;
|
127
|
+
}
|
128
|
+
|
129
|
+
tempEl = tempEl.parentElement;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
return false;
|
134
|
+
};
|
135
|
+
|
136
|
+
(0, _helpers.usePopupScroll)(showDropdown, domRef.current, getScrollContainer);
|
137
|
+
(0, _helpers.usePreventBodyScroll)(showDropdown, preventBodyScroll, initialBodyOverflow);
|
138
|
+
(0, _react.useEffect)(function () {
|
139
|
+
var _dropdownContainer$cu2;
|
140
|
+
|
141
|
+
// 为0的时候不改变
|
142
|
+
// @en Does not change when it is 0
|
143
|
+
if (optionsWrapperHeight === 0) return;
|
144
|
+
var tempEl = getAnchorElement ? getAnchorElement() : (_dropdownContainer$cu2 = dropdownContainer.current) == null ? void 0 : _dropdownContainer$cu2.parentElement;
|
145
|
+
|
146
|
+
var _ref = (tempEl == null ? void 0 : tempEl.getBoundingClientRect()) || {
|
147
|
+
bottom: 0,
|
148
|
+
top: 0
|
149
|
+
},
|
150
|
+
bottom = _ref.bottom,
|
151
|
+
top = _ref.top;
|
152
|
+
|
153
|
+
var tempTop = props.top || bottom;
|
154
|
+
var tempBottom = props.bottom || windowHeight - top;
|
155
|
+
var tempMaskHeight = windowHeight - tempTop; // 没有指定方向,且空间足够时,或向上展开的空间不够,向下展开
|
156
|
+
// @en If there is no specified direction and there is enough space, or there is not enough space to expand upward, expand downward
|
157
|
+
|
158
|
+
var tempDown = direction !== 'up' && optionsWrapperHeight < tempMaskHeight || optionsWrapperHeight > tempTop;
|
159
|
+
|
160
|
+
if (tempDown) {
|
161
|
+
maskHeight.current = tempMaskHeight;
|
162
|
+
setPositionStyle({
|
163
|
+
top: tempTop + "px",
|
164
|
+
bottom: ''
|
165
|
+
});
|
166
|
+
} else {
|
167
|
+
maskHeight.current = windowHeight - tempBottom;
|
168
|
+
setPositionStyle({
|
169
|
+
top: '',
|
170
|
+
bottom: tempBottom + "px"
|
171
|
+
});
|
172
|
+
}
|
173
|
+
|
174
|
+
setDown(tempDown);
|
175
|
+
}, [dropdownContainer, optionsWrapperHeight, props.top, props.bottom, Boolean(getAnchorElement), direction, windowHeight]);
|
176
|
+
/**
|
177
|
+
* 取消选择
|
178
|
+
* @en Cancel selection
|
179
|
+
* */
|
180
|
+
|
181
|
+
var handleCancel = (0, _react.useCallback)(function (e) {
|
182
|
+
var optionsWrapperDom = optionsWrapper.current;
|
183
|
+
|
184
|
+
if (!e || !optionsWrapperDom) {
|
185
|
+
return;
|
186
|
+
}
|
187
|
+
|
188
|
+
var target = e.target;
|
189
|
+
|
190
|
+
if (!optionsWrapperDom.contains(target) && !ifStopTouch(target)) {
|
191
|
+
onCancel();
|
192
|
+
}
|
193
|
+
|
194
|
+
e.stopPropagation();
|
195
|
+
}, [ifStopTouch, onCancel]);
|
196
|
+
/**
|
197
|
+
* 当面板放下时,给body添加事件监听,面板收起时,移除
|
198
|
+
* @en When the panel is down, add an event listener to the body, and when the panel is retracted, remove it
|
199
|
+
* */
|
200
|
+
|
201
|
+
(0, _react.useEffect)(function () {
|
202
|
+
var needBind = showDropdown && clickOtherToClose;
|
203
|
+
var event = touchToClose ? 'touchstart' : 'click';
|
204
|
+
|
205
|
+
if (needBind) {
|
206
|
+
document.addEventListener(event, handleCancel);
|
207
|
+
}
|
208
|
+
|
209
|
+
return function () {
|
210
|
+
if (needBind) {
|
211
|
+
document.removeEventListener(event, handleCancel);
|
212
|
+
}
|
213
|
+
};
|
214
|
+
}, [showDropdown, clickOtherToClose, handleCancel]);
|
215
|
+
(0, _react.useEffect)(function () {
|
216
|
+
(0, _mobileUtils.nextTick)(function () {
|
217
|
+
if (height !== void 0) {
|
218
|
+
// 受控模式下,完全交由外层控制
|
219
|
+
// @en In controlled mode, it is completely controlled by the outer layer
|
220
|
+
setOptionsWrapperHeight(height);
|
221
|
+
} else {
|
222
|
+
if (!optionsContainer.current) return;
|
223
|
+
if (!showDropdown) setOptionsWrapperHeight(0);else {
|
224
|
+
setOptionsWrapperHeight(optionsContainer.current.getBoundingClientRect().height);
|
225
|
+
}
|
226
|
+
}
|
227
|
+
});
|
228
|
+
}, [showDropdown, options.length, height]);
|
229
|
+
(0, _react.useImperativeHandle)(ref, function () {
|
230
|
+
return {
|
231
|
+
dom: domRef.current
|
232
|
+
};
|
233
|
+
});
|
234
|
+
|
235
|
+
function getOptionsStyle() {
|
236
|
+
var trans = down ? 'translateY(-100%)' : 'translateY(100%)';
|
237
|
+
return (0, _helpers.getStyleWithVendor)({
|
238
|
+
// height: `${optionsWrapperHeight}px`,
|
239
|
+
transform: optionsWrapperHeight ? '' : trans,
|
240
|
+
transition: "transform " + dropdownAnimationTimeout + "ms " + dropdownAnimationFunction,
|
241
|
+
overflow: optionsWrapperHeight > maxHeight || height ? 'auto' : 'hidden',
|
242
|
+
maxHeight: maxHeight + "px"
|
243
|
+
});
|
244
|
+
}
|
245
|
+
|
246
|
+
function renderInnerOptions() {
|
247
|
+
var value = props.selectedValue !== void 0 ? props.selectedValue : innerValue;
|
248
|
+
var optionProps = {
|
249
|
+
options: options,
|
250
|
+
useColumn: useColumn,
|
251
|
+
icon: optionIcon,
|
252
|
+
selectedValue: value,
|
253
|
+
multiple: props.multiple,
|
254
|
+
onOptionClick: props.onOptionClick,
|
255
|
+
onOptionChange: function onOptionChange(vals, op) {
|
256
|
+
setInnerValue(vals);
|
257
|
+
props.onOptionChange == null ? void 0 : props.onOptionChange(vals, op);
|
258
|
+
}
|
259
|
+
};
|
260
|
+
return /*#__PURE__*/_react.default.createElement(Comp, optionProps);
|
261
|
+
}
|
262
|
+
|
263
|
+
return /*#__PURE__*/_react.default.createElement(_contextProvider.ContextLayout, null, function (_ref2) {
|
264
|
+
var prefixCls = _ref2.prefixCls;
|
265
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
266
|
+
ref: dropdownContainer
|
267
|
+
}, /*#__PURE__*/_react.default.createElement(_portal.default, {
|
268
|
+
getContainer: getPortalContainer
|
269
|
+
}, /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.CSSTransition, {
|
270
|
+
in: showDropdown,
|
271
|
+
timeout: Math.max(dropdownAnimationTimeout, maskAnimationTimeout),
|
272
|
+
onEnter: function onEnter(el) {
|
273
|
+
el.style.visibility = 'visible';
|
274
|
+
},
|
275
|
+
onExited: function onExited(el) {
|
276
|
+
el.style.visibility = 'hidden';
|
277
|
+
},
|
278
|
+
mountOnEnter: mountOnEnter,
|
279
|
+
unmountOnExit: unmountOnExit
|
280
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
281
|
+
className: (0, _mobileUtils.cls)(prefixCls + "-dropdown all-border-box", system, className, {
|
282
|
+
'drop-up': !down
|
283
|
+
}),
|
284
|
+
ref: domRef,
|
285
|
+
style: (0, _extends2.default)({
|
286
|
+
height: maskHeight.current + "px",
|
287
|
+
maxWidth: windowWidth + "px"
|
288
|
+
}, style, positionStyle)
|
289
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
290
|
+
className: (0, _mobileUtils.cls)(prefixCls + "-dropdown-options"),
|
291
|
+
ref: optionsWrapper,
|
292
|
+
style: getOptionsStyle()
|
293
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
294
|
+
className: (0, _mobileUtils.cls)(prefixCls + "-dropdown-options-container"),
|
295
|
+
ref: optionsContainer
|
296
|
+
}, props.children || renderInnerOptions(), props.extraNode)), showMask && /*#__PURE__*/_react.default.createElement("div", {
|
297
|
+
className: (0, _mobileUtils.cls)(prefixCls + "-dropdown-mask", {
|
298
|
+
'is-show': optionsWrapperHeight
|
299
|
+
}),
|
300
|
+
style: {
|
301
|
+
transition: "opacity " + maskAnimationTimeout + "ms " + maskAnimationFunction
|
302
|
+
}
|
303
|
+
})))));
|
304
|
+
});
|
305
|
+
});
|
306
|
+
}
|
package/cjs/dropdown/index.d.ts
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
|
2
|
-
import { DropdownRef } from './type';
|
1
|
+
/// <reference types="react" />
|
3
2
|
export * from './type';
|
4
|
-
declare const _default:
|
5
|
-
Options:
|
3
|
+
declare const _default: import("react").ForwardRefExoticComponent<(import("./type").DropdownBasicProps & import("./type").SingleOptionProps & import("react").RefAttributes<import("./type").DropdownRef>) | (import("./type").DropdownBasicProps & import("./type").MultipleOptionProps & import("react").RefAttributes<import("./type").DropdownRef>)> & {
|
4
|
+
Options: import("react").ForwardRefExoticComponent<(import("./type").DropdownOptionsBasicProps & import("./type").SingleOptionProps & import("react").RefAttributes<import("./type").DropdownOptionsRef>) | (import("./type").DropdownOptionsBasicProps & import("./type").MultipleOptionProps & import("react").RefAttributes<import("./type").DropdownOptionsRef>)>;
|
6
5
|
};
|
7
6
|
/**
|
8
7
|
* 下拉面板,展示供选择的选择项
|
package/cjs/dropdown/index.js
CHANGED
@@ -6,22 +6,12 @@ exports.__esModule = true;
|
|
6
6
|
var _exportNames = {};
|
7
7
|
exports.default = void 0;
|
8
8
|
|
9
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
10
|
-
|
11
|
-
var _react = _interopRequireWildcard(require("react"));
|
12
|
-
|
13
9
|
var _mobileUtils = require("@arco-design/mobile-utils");
|
14
10
|
|
15
|
-
var _reactTransitionGroup = require("react-transition-group");
|
16
|
-
|
17
|
-
var _contextProvider = require("../context-provider");
|
18
|
-
|
19
|
-
var _helpers = require("../_helpers");
|
20
|
-
|
21
|
-
var _portal = _interopRequireDefault(require("../portal"));
|
22
|
-
|
23
11
|
var _options = _interopRequireDefault(require("./options"));
|
24
12
|
|
13
|
+
var _dropdown = require("./dropdown");
|
14
|
+
|
25
15
|
var _type = require("./type");
|
26
16
|
|
27
17
|
Object.keys(_type).forEach(function (key) {
|
@@ -30,297 +20,7 @@ Object.keys(_type).forEach(function (key) {
|
|
30
20
|
if (key in exports && exports[key] === _type[key]) return;
|
31
21
|
exports[key] = _type[key];
|
32
22
|
});
|
33
|
-
|
34
|
-
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); }
|
35
|
-
|
36
|
-
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; }
|
37
|
-
|
38
|
-
var Dropdown = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
39
|
-
var optionsWrapper = (0, _react.useRef)(null);
|
40
|
-
var domRef = (0, _react.useRef)(null);
|
41
|
-
var _props$className = props.className,
|
42
|
-
className = _props$className === void 0 ? '' : _props$className,
|
43
|
-
_props$style = props.style,
|
44
|
-
style = _props$style === void 0 ? {} : _props$style,
|
45
|
-
_props$options = props.options,
|
46
|
-
options = _props$options === void 0 ? [] : _props$options,
|
47
|
-
_props$showDropdown = props.showDropdown,
|
48
|
-
showDropdown = _props$showDropdown === void 0 ? false : _props$showDropdown,
|
49
|
-
_props$showMask = props.showMask,
|
50
|
-
showMask = _props$showMask === void 0 ? true : _props$showMask,
|
51
|
-
_props$direction = props.direction,
|
52
|
-
direction = _props$direction === void 0 ? 'down' : _props$direction,
|
53
|
-
height = props.height,
|
54
|
-
_props$maxHeight = props.maxHeight,
|
55
|
-
maxHeight = _props$maxHeight === void 0 ? 500 : _props$maxHeight,
|
56
|
-
_props$touchToClose = props.touchToClose,
|
57
|
-
touchToClose = _props$touchToClose === void 0 ? true : _props$touchToClose,
|
58
|
-
useColumn = props.useColumn,
|
59
|
-
multiple = props.multiple,
|
60
|
-
defaultSelectedValue = props.defaultSelectedValue,
|
61
|
-
onCancel = props.onCancel,
|
62
|
-
getAnchorElement = props.getAnchorElement,
|
63
|
-
isStopTouchEl = props.isStopTouchEl,
|
64
|
-
getStopTouchElements = props.getStopTouchElements,
|
65
|
-
_props$getScrollConta = props.getScrollContainer,
|
66
|
-
getScrollContainer = _props$getScrollConta === void 0 ? function () {
|
67
|
-
return optionsWrapper.current;
|
68
|
-
} : _props$getScrollConta,
|
69
|
-
getPortalContainer = props.getPortalContainer,
|
70
|
-
_props$clickOtherToCl = props.clickOtherToClose,
|
71
|
-
clickOtherToClose = _props$clickOtherToCl === void 0 ? true : _props$clickOtherToCl,
|
72
|
-
_props$dropdownAnimat = props.dropdownAnimationTimeout,
|
73
|
-
dropdownAnimationTimeout = _props$dropdownAnimat === void 0 ? 300 : _props$dropdownAnimat,
|
74
|
-
_props$dropdownAnimat2 = props.dropdownAnimationFunction,
|
75
|
-
dropdownAnimationFunction = _props$dropdownAnimat2 === void 0 ? 'cubic-bezier(0.32, 0.96, 0.6, 1)' : _props$dropdownAnimat2,
|
76
|
-
_props$maskAnimationT = props.maskAnimationTimeout,
|
77
|
-
maskAnimationTimeout = _props$maskAnimationT === void 0 ? 500 : _props$maskAnimationT,
|
78
|
-
_props$maskAnimationF = props.maskAnimationFunction,
|
79
|
-
maskAnimationFunction = _props$maskAnimationF === void 0 ? 'cubic-bezier(0.32, 0.96, 0.6, 1)' : _props$maskAnimationF,
|
80
|
-
_props$mountOnEnter = props.mountOnEnter,
|
81
|
-
mountOnEnter = _props$mountOnEnter === void 0 ? true : _props$mountOnEnter,
|
82
|
-
_props$unmountOnExit = props.unmountOnExit,
|
83
|
-
unmountOnExit = _props$unmountOnExit === void 0 ? true : _props$unmountOnExit,
|
84
|
-
_props$preventBodyScr = props.preventBodyScroll,
|
85
|
-
preventBodyScroll = _props$preventBodyScr === void 0 ? true : _props$preventBodyScr,
|
86
|
-
initialBodyOverflow = props.initialBodyOverflow;
|
87
|
-
var system = (0, _helpers.useSystem)();
|
88
|
-
|
89
|
-
var _useWindowSize = (0, _helpers.useWindowSize)(),
|
90
|
-
windowHeight = _useWindowSize.windowHeight,
|
91
|
-
windowWidth = _useWindowSize.windowWidth;
|
92
|
-
|
93
|
-
var _useState = (0, _react.useState)({
|
94
|
-
top: '',
|
95
|
-
bottom: ''
|
96
|
-
}),
|
97
|
-
positionStyle = _useState[0],
|
98
|
-
setPositionStyle = _useState[1];
|
99
|
-
|
100
|
-
var _useState2 = (0, _react.useState)(function () {
|
101
|
-
var defaultValue = multiple ? [] : 0;
|
102
|
-
return defaultSelectedValue !== void 0 ? defaultSelectedValue : defaultValue;
|
103
|
-
}),
|
104
|
-
innerValue = _useState2[0],
|
105
|
-
setInnerValue = _useState2[1]; // down=0为向上展开,1为向下展开
|
106
|
-
// @en down=0 is to expand upwards, 1 is to expand downwards
|
107
|
-
|
108
|
-
|
109
|
-
var _useState3 = (0, _react.useState)(direction === 'down'),
|
110
|
-
down = _useState3[0],
|
111
|
-
setDown = _useState3[1];
|
112
|
-
|
113
|
-
var maskHeight = (0, _react.useRef)(0);
|
114
|
-
var optionsContainer = (0, _react.useRef)(null);
|
115
|
-
var dropdownContainer = (0, _react.useRef)(null);
|
116
|
-
|
117
|
-
var _useState4 = (0, _react.useState)(0),
|
118
|
-
optionsWrapperHeight = _useState4[0],
|
119
|
-
setOptionsWrapperHeight = _useState4[1];
|
120
|
-
/**
|
121
|
-
* 判断是否阻止touch事件
|
122
|
-
* @en Determine whether to block touch events
|
123
|
-
* */
|
124
|
-
|
125
|
-
|
126
|
-
var ifStopTouch = function ifStopTouch(el) {
|
127
|
-
var _dropdownContainer$cu;
|
128
|
-
|
129
|
-
if (isStopTouchEl) return isStopTouchEl(el);
|
130
|
-
var tempEl = el;
|
131
|
-
var elements = getStopTouchElements ? getStopTouchElements() : [(_dropdownContainer$cu = dropdownContainer.current) == null ? void 0 : _dropdownContainer$cu.parentElement];
|
132
|
-
|
133
|
-
for (var i = 0; i < elements.length; i++) {
|
134
|
-
while (tempEl && elements[i]) {
|
135
|
-
if (tempEl === elements[i]) {
|
136
|
-
return true;
|
137
|
-
}
|
138
|
-
|
139
|
-
tempEl = tempEl.parentElement;
|
140
|
-
}
|
141
|
-
}
|
142
|
-
|
143
|
-
return false;
|
144
|
-
};
|
145
|
-
|
146
|
-
(0, _helpers.usePopupScroll)(showDropdown, domRef.current, getScrollContainer);
|
147
|
-
(0, _helpers.usePreventBodyScroll)(showDropdown, preventBodyScroll, initialBodyOverflow);
|
148
|
-
(0, _react.useEffect)(function () {
|
149
|
-
var _dropdownContainer$cu2;
|
150
|
-
|
151
|
-
// 为0的时候不改变
|
152
|
-
// @en Does not change when it is 0
|
153
|
-
if (optionsWrapperHeight === 0) return;
|
154
|
-
var tempEl = getAnchorElement ? getAnchorElement() : (_dropdownContainer$cu2 = dropdownContainer.current) == null ? void 0 : _dropdownContainer$cu2.parentElement;
|
155
|
-
|
156
|
-
var _ref = (tempEl == null ? void 0 : tempEl.getBoundingClientRect()) || {
|
157
|
-
bottom: 0,
|
158
|
-
top: 0
|
159
|
-
},
|
160
|
-
bottom = _ref.bottom,
|
161
|
-
top = _ref.top;
|
162
|
-
|
163
|
-
var tempTop = props.top || bottom;
|
164
|
-
var tempBottom = props.bottom || windowHeight - top;
|
165
|
-
var tempMaskHeight = windowHeight - tempTop; // 没有指定方向,且空间足够时,或向上展开的空间不够,向下展开
|
166
|
-
// @en If there is no specified direction and there is enough space, or there is not enough space to expand upward, expand downward
|
167
|
-
|
168
|
-
var tempDown = direction !== 'up' && optionsWrapperHeight < tempMaskHeight || optionsWrapperHeight > tempTop;
|
169
|
-
|
170
|
-
if (tempDown) {
|
171
|
-
maskHeight.current = tempMaskHeight;
|
172
|
-
setPositionStyle({
|
173
|
-
top: tempTop + "px",
|
174
|
-
bottom: ''
|
175
|
-
});
|
176
|
-
} else {
|
177
|
-
maskHeight.current = windowHeight - tempBottom;
|
178
|
-
setPositionStyle({
|
179
|
-
top: '',
|
180
|
-
bottom: tempBottom + "px"
|
181
|
-
});
|
182
|
-
}
|
183
|
-
|
184
|
-
setDown(tempDown);
|
185
|
-
}, [dropdownContainer, optionsWrapperHeight, props.top, props.bottom, Boolean(getAnchorElement), direction, windowHeight]);
|
186
|
-
/**
|
187
|
-
* 取消选择
|
188
|
-
* @en Cancel selection
|
189
|
-
* */
|
190
|
-
|
191
|
-
var handleCancel = (0, _react.useCallback)(function (e) {
|
192
|
-
var optionsWrapperDom = optionsWrapper.current;
|
193
|
-
|
194
|
-
if (!e || !optionsWrapperDom) {
|
195
|
-
return;
|
196
|
-
}
|
197
|
-
|
198
|
-
var target = e.target;
|
199
|
-
|
200
|
-
if (!optionsWrapperDom.contains(target) && !ifStopTouch(target)) {
|
201
|
-
onCancel();
|
202
|
-
}
|
203
|
-
|
204
|
-
e.stopPropagation();
|
205
|
-
}, [ifStopTouch, onCancel]);
|
206
|
-
/**
|
207
|
-
* 当面板放下时,给body添加事件监听,面板收起时,移除
|
208
|
-
* @en When the panel is down, add an event listener to the body, and when the panel is retracted, remove it
|
209
|
-
* */
|
210
|
-
|
211
|
-
(0, _react.useEffect)(function () {
|
212
|
-
var needBind = showDropdown && clickOtherToClose;
|
213
|
-
var event = touchToClose ? 'touchstart' : 'click';
|
214
|
-
|
215
|
-
if (needBind) {
|
216
|
-
document.addEventListener(event, handleCancel);
|
217
|
-
}
|
218
|
-
|
219
|
-
return function () {
|
220
|
-
if (needBind) {
|
221
|
-
document.removeEventListener(event, handleCancel);
|
222
|
-
}
|
223
|
-
};
|
224
|
-
}, [showDropdown, clickOtherToClose, handleCancel]);
|
225
|
-
(0, _react.useEffect)(function () {
|
226
|
-
(0, _mobileUtils.nextTick)(function () {
|
227
|
-
if (height !== void 0) {
|
228
|
-
// 受控模式下,完全交由外层控制
|
229
|
-
// @en In controlled mode, it is completely controlled by the outer layer
|
230
|
-
setOptionsWrapperHeight(height);
|
231
|
-
} else {
|
232
|
-
if (!optionsContainer.current) return;
|
233
|
-
if (!showDropdown) setOptionsWrapperHeight(0);else {
|
234
|
-
setOptionsWrapperHeight(optionsContainer.current.getBoundingClientRect().height);
|
235
|
-
}
|
236
|
-
}
|
237
|
-
});
|
238
|
-
}, [showDropdown, options.length, height]);
|
239
|
-
(0, _react.useImperativeHandle)(ref, function () {
|
240
|
-
return {
|
241
|
-
dom: domRef.current
|
242
|
-
};
|
243
|
-
});
|
244
|
-
|
245
|
-
function getOptionsStyle() {
|
246
|
-
var trans = down ? 'translateY(-100%)' : 'translateY(100%)';
|
247
|
-
return (0, _helpers.getStyleWithVendor)({
|
248
|
-
// height: `${optionsWrapperHeight}px`,
|
249
|
-
transform: optionsWrapperHeight ? '' : trans,
|
250
|
-
transition: "transform " + dropdownAnimationTimeout + "ms " + dropdownAnimationFunction,
|
251
|
-
overflow: optionsWrapperHeight > maxHeight || height ? 'auto' : 'hidden',
|
252
|
-
maxHeight: maxHeight + "px"
|
253
|
-
});
|
254
|
-
}
|
255
|
-
|
256
|
-
function renderInnerOptions() {
|
257
|
-
var optionProps = {
|
258
|
-
options: options,
|
259
|
-
useColumn: useColumn
|
260
|
-
};
|
261
|
-
var value = props.selectedValue !== void 0 ? props.selectedValue : innerValue;
|
262
|
-
return props.multiple === true ? /*#__PURE__*/_react.default.createElement(_options.default, (0, _extends2.default)({}, optionProps, {
|
263
|
-
multiple: true,
|
264
|
-
selectedValue: value,
|
265
|
-
onOptionClick: props.onOptionClick,
|
266
|
-
onOptionChange: function onOptionChange(vals, op) {
|
267
|
-
setInnerValue(vals);
|
268
|
-
props.onOptionChange == null ? void 0 : props.onOptionChange(vals, op);
|
269
|
-
}
|
270
|
-
})) : /*#__PURE__*/_react.default.createElement(_options.default, (0, _extends2.default)({}, optionProps, {
|
271
|
-
multiple: props.multiple,
|
272
|
-
selectedValue: value,
|
273
|
-
onOptionClick: props.onOptionClick,
|
274
|
-
onOptionChange: function onOptionChange(vals, op) {
|
275
|
-
setInnerValue(vals);
|
276
|
-
props.onOptionChange == null ? void 0 : props.onOptionChange(vals, op);
|
277
|
-
}
|
278
|
-
}));
|
279
|
-
}
|
280
|
-
|
281
|
-
return /*#__PURE__*/_react.default.createElement(_contextProvider.ContextLayout, null, function (_ref2) {
|
282
|
-
var prefixCls = _ref2.prefixCls;
|
283
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
284
|
-
ref: dropdownContainer
|
285
|
-
}, /*#__PURE__*/_react.default.createElement(_portal.default, {
|
286
|
-
getContainer: getPortalContainer
|
287
|
-
}, /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.CSSTransition, {
|
288
|
-
in: showDropdown,
|
289
|
-
timeout: Math.max(dropdownAnimationTimeout, maskAnimationTimeout),
|
290
|
-
onEnter: function onEnter(el) {
|
291
|
-
el.style.visibility = 'visible';
|
292
|
-
},
|
293
|
-
onExited: function onExited(el) {
|
294
|
-
el.style.visibility = 'hidden';
|
295
|
-
},
|
296
|
-
mountOnEnter: mountOnEnter,
|
297
|
-
unmountOnExit: unmountOnExit
|
298
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
299
|
-
className: (0, _mobileUtils.cls)(prefixCls + "-dropdown all-border-box", system, className, {
|
300
|
-
'drop-up': !down
|
301
|
-
}),
|
302
|
-
ref: domRef,
|
303
|
-
style: (0, _extends2.default)({
|
304
|
-
height: maskHeight.current + "px",
|
305
|
-
maxWidth: windowWidth + "px"
|
306
|
-
}, style, positionStyle)
|
307
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
308
|
-
className: (0, _mobileUtils.cls)(prefixCls + "-dropdown-options"),
|
309
|
-
ref: optionsWrapper,
|
310
|
-
style: getOptionsStyle()
|
311
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
312
|
-
className: (0, _mobileUtils.cls)(prefixCls + "-dropdown-options-container"),
|
313
|
-
ref: optionsContainer
|
314
|
-
}, props.children || renderInnerOptions(), props.extraNode)), showMask && /*#__PURE__*/_react.default.createElement("div", {
|
315
|
-
className: (0, _mobileUtils.cls)(prefixCls + "-dropdown-mask", {
|
316
|
-
'is-show': optionsWrapperHeight
|
317
|
-
}),
|
318
|
-
style: {
|
319
|
-
transition: "opacity " + maskAnimationTimeout + "ms " + maskAnimationFunction
|
320
|
-
}
|
321
|
-
})))));
|
322
|
-
});
|
323
|
-
});
|
23
|
+
var Dropdown = (0, _dropdown.componentGenerator)(_options.default);
|
324
24
|
/**
|
325
25
|
* 下拉面板,展示供选择的选择项
|
326
26
|
* @en Dropdown panel, showing options to choose from
|
package/cjs/dropdown/options.js
CHANGED
@@ -20,6 +20,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
20
20
|
var Options = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
21
21
|
var options = props.options,
|
22
22
|
useColumn = props.useColumn,
|
23
|
+
icon = props.icon,
|
23
24
|
selectedValue = props.selectedValue,
|
24
25
|
defaultSelectedValue = props.defaultSelectedValue,
|
25
26
|
multiple = props.multiple;
|
@@ -98,7 +99,7 @@ var Options = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
98
99
|
return handleOptionChange(e, op);
|
99
100
|
},
|
100
101
|
style: minWidthStyle
|
101
|
-
}, op.label, /*#__PURE__*/_react.default.createElement(_IconCheck.default, {
|
102
|
+
}, op.label, icon !== void 0 ? icon : /*#__PURE__*/_react.default.createElement(_IconCheck.default, {
|
102
103
|
className: prefixCls + "-dropdown-options-item-icon"
|
103
104
|
}));
|
104
105
|
}), fakeOpts.map(function (_, i) {
|