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