@commercetools-uikit/dropdown-menu 20.5.0 → 20.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/commercetools-uikit-dropdown-menu.cjs.dev.js +13 -22
- package/dist/commercetools-uikit-dropdown-menu.cjs.prod.js +13 -22
- package/dist/commercetools-uikit-dropdown-menu.esm.js +13 -21
- package/dist/declarations/src/menu/dropdown-menu-menu.d.ts +1 -1
- package/package.json +27 -14
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->
|
|
2
|
-
<!-- This file is created by the `
|
|
2
|
+
<!-- This file is created by the `pnpm generate-readme` script. -->
|
|
3
3
|
|
|
4
4
|
# DropdownMenu
|
|
5
5
|
|
|
@@ -16,7 +16,7 @@ Something to bear in mind is that, when the panel is open, the document scroll i
|
|
|
16
16
|
## Installation
|
|
17
17
|
|
|
18
18
|
```
|
|
19
|
-
|
|
19
|
+
pnpm add @commercetools-uikit/dropdown-menu
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
```
|
|
@@ -26,7 +26,7 @@ npm --save install @commercetools-uikit/dropdown-menu
|
|
|
26
26
|
Additionally install the peer dependencies (if not present)
|
|
27
27
|
|
|
28
28
|
```
|
|
29
|
-
|
|
29
|
+
pnpm add react
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
```
|
|
@@ -18,7 +18,6 @@ var react = require('react');
|
|
|
18
18
|
var utils = require('@commercetools-uikit/utils');
|
|
19
19
|
var hooks = require('@commercetools-uikit/hooks');
|
|
20
20
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
21
|
-
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
22
21
|
var _setTimeout = require('@babel/runtime-corejs3/core-js-stable/set-timeout');
|
|
23
22
|
var react$1 = require('@emotion/react');
|
|
24
23
|
var designSystem = require('@commercetools-uikit/design-system');
|
|
@@ -37,7 +36,6 @@ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_O
|
|
|
37
36
|
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
38
37
|
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
39
38
|
var _styled__default = /*#__PURE__*/_interopDefault(_styled);
|
|
40
|
-
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
41
39
|
var _setTimeout__default = /*#__PURE__*/_interopDefault(_setTimeout);
|
|
42
40
|
var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
43
41
|
var SpacingsStack__default = /*#__PURE__*/_interopDefault(SpacingsStack);
|
|
@@ -69,7 +67,7 @@ DropDownTrigger.displayName = 'DropDownTrigger';
|
|
|
69
67
|
var DropdownTrigger = DropDownTrigger;
|
|
70
68
|
|
|
71
69
|
function ownKeys$2(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
72
|
-
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
70
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys$2(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys$2(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
73
71
|
const boxShadowBottomSize = '5px';
|
|
74
72
|
const outerMargin = designSystem.designTokens.spacing20;
|
|
75
73
|
function getDropdownMenuBaseStyles(params) {
|
|
@@ -90,10 +88,9 @@ function DropdownBaseMenu(props) {
|
|
|
90
88
|
// By default, the menu is not exceeding the viewport, this can change though
|
|
91
89
|
let menuIsExceedingViewport = false;
|
|
92
90
|
if (menuDOMRect.width >= document.body.scrollWidth) {
|
|
93
|
-
var _context;
|
|
94
91
|
// If the menu width is greater than the body width, we need to set the width of the menu to the body width
|
|
95
92
|
// to prevent the menu from overflowing, this happens usually when the horizontalConstraint is set to 'auto'
|
|
96
|
-
menuEl.style.width =
|
|
93
|
+
menuEl.style.width = `calc(${document.body.scrollWidth}px - 2 * ${outerMargin})`;
|
|
97
94
|
menuIsExceedingViewport = true;
|
|
98
95
|
}
|
|
99
96
|
|
|
@@ -132,40 +129,36 @@ function DropdownBaseMenu(props) {
|
|
|
132
129
|
// the trigger
|
|
133
130
|
const scrollWidthDiff = (document.body.scrollWidth - scrollWidthBefore) * 0.5;
|
|
134
131
|
if (menuIsExceedingViewport) {
|
|
135
|
-
|
|
136
|
-
menuEl.style.left = _concatInstanceProperty__default["default"](_context2 = "calc( ".concat(outerMargin, " + ")).call(_context2, scrollWidthDiff, "px)");
|
|
132
|
+
menuEl.style.left = `calc( ${outerMargin} + ${scrollWidthDiff}px)`;
|
|
137
133
|
} else if (menuXPosition === 'left') {
|
|
138
|
-
menuEl.style.left =
|
|
134
|
+
menuEl.style.left = `${triggerDOMRect.left + scrollWidthDiff}px`;
|
|
139
135
|
menuEl.style.removeProperty('right');
|
|
140
136
|
} else {
|
|
141
|
-
menuEl.style.right =
|
|
137
|
+
menuEl.style.right = `${window.innerWidth - triggerDOMRect.right - scrollWidthDiff}px`;
|
|
142
138
|
menuEl.style.removeProperty('left');
|
|
143
139
|
}
|
|
144
140
|
if (menuYPosition === 'below') {
|
|
145
|
-
|
|
146
|
-
menuEl.style.top = _concatInstanceProperty__default["default"](_context3 = "calc(".concat(triggerDOMRect.top + triggerDOMRect.height, "px + ")).call(_context3, outerMargin, ")");
|
|
141
|
+
menuEl.style.top = `calc(${triggerDOMRect.top + triggerDOMRect.height}px + ${outerMargin})`;
|
|
147
142
|
} else {
|
|
148
|
-
var _context4;
|
|
149
143
|
// Need to re-request getBoundingClientRect() because the menu height
|
|
150
144
|
// might have changed when the dropdown is in 'auto' mode;
|
|
151
145
|
let desiredMenuHeight = menuMaxHeight || menuEl.getBoundingClientRect().height;
|
|
152
|
-
menuEl.style.top =
|
|
146
|
+
menuEl.style.top = `calc(${triggerDOMRect.top - desiredMenuHeight}px - ${outerMargin})`;
|
|
153
147
|
}
|
|
154
148
|
if (menuMaxHeight) {
|
|
155
149
|
// Apply the manual max-width
|
|
156
150
|
menuEl.style.maxHeight = menuMaxHeight + 'px';
|
|
157
151
|
} else {
|
|
158
|
-
var _context5, _context6, _context7, _context8;
|
|
159
152
|
// Make sure max-height does not exceed the available top- or bottom-space
|
|
160
|
-
menuEl.style.maxHeight = menuYPosition === 'below' ?
|
|
153
|
+
menuEl.style.maxHeight = menuYPosition === 'below' ? `calc(${window.innerHeight - triggerDOMRect.bottom}px - ${outerMargin} - ${boxShadowBottomSize})` : `calc(${triggerDOMRect.top}px - ${outerMargin} - ${boxShadowBottomSize})`;
|
|
161
154
|
}
|
|
162
155
|
|
|
163
156
|
// All positioning operations done, make menu visible again
|
|
164
157
|
menuEl.style.visibility = 'visible';
|
|
165
158
|
}, 0);
|
|
166
159
|
return () => {
|
|
167
|
-
var
|
|
168
|
-
_forEachInstanceProperty__default["default"](
|
|
160
|
+
var _context;
|
|
161
|
+
_forEachInstanceProperty__default["default"](_context = ['top', 'left', 'right', 'bottom', 'width', 'height', 'maxHeight', 'visibility']).call(_context, prop => {
|
|
169
162
|
menuEl.style.removeProperty(prop);
|
|
170
163
|
});
|
|
171
164
|
};
|
|
@@ -218,9 +211,8 @@ function DropdownListMenuItem(props) {
|
|
|
218
211
|
return jsxRuntime.jsx(AccessibleButton__default["default"], _objectSpread$1(_objectSpread$1({
|
|
219
212
|
label: props.children,
|
|
220
213
|
onClick: () => {
|
|
221
|
-
var _props$onClick;
|
|
222
214
|
toggle();
|
|
223
|
-
|
|
215
|
+
props.onClick?.();
|
|
224
216
|
},
|
|
225
217
|
isDisabled: props.isDisabled,
|
|
226
218
|
css: getDropdownListMenuItemStyles(props)
|
|
@@ -303,9 +295,8 @@ function DropdownMenu(_ref) {
|
|
|
303
295
|
|
|
304
296
|
// Close the dropdown when clicking outside of it
|
|
305
297
|
const handleGlobalClick = react.useCallback(event => {
|
|
306
|
-
var _triggerElement$paren;
|
|
307
298
|
const triggerElement = triggerRef.current;
|
|
308
|
-
if (isOpen && triggerElement && event.target !== triggerElement && window.document.contains(event.target) && !
|
|
299
|
+
if (isOpen && triggerElement && event.target !== triggerElement && window.document.contains(event.target) && !triggerElement.parentElement?.contains(event.target)) {
|
|
309
300
|
toggle(false);
|
|
310
301
|
}
|
|
311
302
|
}, [triggerRef, toggle, isOpen]);
|
|
@@ -345,7 +336,7 @@ function DropdownMenu(_ref) {
|
|
|
345
336
|
DropdownMenu.ListMenuItem = DropdownListMenuItem;
|
|
346
337
|
|
|
347
338
|
// NOTE: This string will be replaced on build time with the package version.
|
|
348
|
-
var version = "20.
|
|
339
|
+
var version = "20.6.1";
|
|
349
340
|
|
|
350
341
|
exports["default"] = DropdownMenu;
|
|
351
342
|
exports.useDropdownMenuContext = useDropdownMenuContext;
|
|
@@ -18,7 +18,6 @@ var react = require('react');
|
|
|
18
18
|
var utils = require('@commercetools-uikit/utils');
|
|
19
19
|
var hooks = require('@commercetools-uikit/hooks');
|
|
20
20
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
21
|
-
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
22
21
|
var _setTimeout = require('@babel/runtime-corejs3/core-js-stable/set-timeout');
|
|
23
22
|
var react$1 = require('@emotion/react');
|
|
24
23
|
var designSystem = require('@commercetools-uikit/design-system');
|
|
@@ -37,7 +36,6 @@ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_O
|
|
|
37
36
|
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
38
37
|
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
39
38
|
var _styled__default = /*#__PURE__*/_interopDefault(_styled);
|
|
40
|
-
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
41
39
|
var _setTimeout__default = /*#__PURE__*/_interopDefault(_setTimeout);
|
|
42
40
|
var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
43
41
|
var SpacingsStack__default = /*#__PURE__*/_interopDefault(SpacingsStack);
|
|
@@ -69,7 +67,7 @@ DropDownTrigger.displayName = 'DropDownTrigger';
|
|
|
69
67
|
var DropdownTrigger = DropDownTrigger;
|
|
70
68
|
|
|
71
69
|
function ownKeys$2(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
72
|
-
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
70
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys$2(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys$2(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
73
71
|
const boxShadowBottomSize = '5px';
|
|
74
72
|
const outerMargin = designSystem.designTokens.spacing20;
|
|
75
73
|
function getDropdownMenuBaseStyles(params) {
|
|
@@ -90,10 +88,9 @@ function DropdownBaseMenu(props) {
|
|
|
90
88
|
// By default, the menu is not exceeding the viewport, this can change though
|
|
91
89
|
let menuIsExceedingViewport = false;
|
|
92
90
|
if (menuDOMRect.width >= document.body.scrollWidth) {
|
|
93
|
-
var _context;
|
|
94
91
|
// If the menu width is greater than the body width, we need to set the width of the menu to the body width
|
|
95
92
|
// to prevent the menu from overflowing, this happens usually when the horizontalConstraint is set to 'auto'
|
|
96
|
-
menuEl.style.width =
|
|
93
|
+
menuEl.style.width = `calc(${document.body.scrollWidth}px - 2 * ${outerMargin})`;
|
|
97
94
|
menuIsExceedingViewport = true;
|
|
98
95
|
}
|
|
99
96
|
|
|
@@ -132,40 +129,36 @@ function DropdownBaseMenu(props) {
|
|
|
132
129
|
// the trigger
|
|
133
130
|
const scrollWidthDiff = (document.body.scrollWidth - scrollWidthBefore) * 0.5;
|
|
134
131
|
if (menuIsExceedingViewport) {
|
|
135
|
-
|
|
136
|
-
menuEl.style.left = _concatInstanceProperty__default["default"](_context2 = "calc( ".concat(outerMargin, " + ")).call(_context2, scrollWidthDiff, "px)");
|
|
132
|
+
menuEl.style.left = `calc( ${outerMargin} + ${scrollWidthDiff}px)`;
|
|
137
133
|
} else if (menuXPosition === 'left') {
|
|
138
|
-
menuEl.style.left =
|
|
134
|
+
menuEl.style.left = `${triggerDOMRect.left + scrollWidthDiff}px`;
|
|
139
135
|
menuEl.style.removeProperty('right');
|
|
140
136
|
} else {
|
|
141
|
-
menuEl.style.right =
|
|
137
|
+
menuEl.style.right = `${window.innerWidth - triggerDOMRect.right - scrollWidthDiff}px`;
|
|
142
138
|
menuEl.style.removeProperty('left');
|
|
143
139
|
}
|
|
144
140
|
if (menuYPosition === 'below') {
|
|
145
|
-
|
|
146
|
-
menuEl.style.top = _concatInstanceProperty__default["default"](_context3 = "calc(".concat(triggerDOMRect.top + triggerDOMRect.height, "px + ")).call(_context3, outerMargin, ")");
|
|
141
|
+
menuEl.style.top = `calc(${triggerDOMRect.top + triggerDOMRect.height}px + ${outerMargin})`;
|
|
147
142
|
} else {
|
|
148
|
-
var _context4;
|
|
149
143
|
// Need to re-request getBoundingClientRect() because the menu height
|
|
150
144
|
// might have changed when the dropdown is in 'auto' mode;
|
|
151
145
|
let desiredMenuHeight = menuMaxHeight || menuEl.getBoundingClientRect().height;
|
|
152
|
-
menuEl.style.top =
|
|
146
|
+
menuEl.style.top = `calc(${triggerDOMRect.top - desiredMenuHeight}px - ${outerMargin})`;
|
|
153
147
|
}
|
|
154
148
|
if (menuMaxHeight) {
|
|
155
149
|
// Apply the manual max-width
|
|
156
150
|
menuEl.style.maxHeight = menuMaxHeight + 'px';
|
|
157
151
|
} else {
|
|
158
|
-
var _context5, _context6, _context7, _context8;
|
|
159
152
|
// Make sure max-height does not exceed the available top- or bottom-space
|
|
160
|
-
menuEl.style.maxHeight = menuYPosition === 'below' ?
|
|
153
|
+
menuEl.style.maxHeight = menuYPosition === 'below' ? `calc(${window.innerHeight - triggerDOMRect.bottom}px - ${outerMargin} - ${boxShadowBottomSize})` : `calc(${triggerDOMRect.top}px - ${outerMargin} - ${boxShadowBottomSize})`;
|
|
161
154
|
}
|
|
162
155
|
|
|
163
156
|
// All positioning operations done, make menu visible again
|
|
164
157
|
menuEl.style.visibility = 'visible';
|
|
165
158
|
}, 0);
|
|
166
159
|
return () => {
|
|
167
|
-
var
|
|
168
|
-
_forEachInstanceProperty__default["default"](
|
|
160
|
+
var _context;
|
|
161
|
+
_forEachInstanceProperty__default["default"](_context = ['top', 'left', 'right', 'bottom', 'width', 'height', 'maxHeight', 'visibility']).call(_context, prop => {
|
|
169
162
|
menuEl.style.removeProperty(prop);
|
|
170
163
|
});
|
|
171
164
|
};
|
|
@@ -218,9 +211,8 @@ function DropdownListMenuItem(props) {
|
|
|
218
211
|
return jsxRuntime.jsx(AccessibleButton__default["default"], _objectSpread$1(_objectSpread$1({
|
|
219
212
|
label: props.children,
|
|
220
213
|
onClick: () => {
|
|
221
|
-
var _props$onClick;
|
|
222
214
|
toggle();
|
|
223
|
-
|
|
215
|
+
props.onClick?.();
|
|
224
216
|
},
|
|
225
217
|
isDisabled: props.isDisabled,
|
|
226
218
|
css: getDropdownListMenuItemStyles(props)
|
|
@@ -295,9 +287,8 @@ function DropdownMenu(_ref) {
|
|
|
295
287
|
|
|
296
288
|
// Close the dropdown when clicking outside of it
|
|
297
289
|
const handleGlobalClick = react.useCallback(event => {
|
|
298
|
-
var _triggerElement$paren;
|
|
299
290
|
const triggerElement = triggerRef.current;
|
|
300
|
-
if (isOpen && triggerElement && event.target !== triggerElement && window.document.contains(event.target) && !
|
|
291
|
+
if (isOpen && triggerElement && event.target !== triggerElement && window.document.contains(event.target) && !triggerElement.parentElement?.contains(event.target)) {
|
|
301
292
|
toggle(false);
|
|
302
293
|
}
|
|
303
294
|
}, [triggerRef, toggle, isOpen]);
|
|
@@ -337,7 +328,7 @@ function DropdownMenu(_ref) {
|
|
|
337
328
|
DropdownMenu.ListMenuItem = DropdownListMenuItem;
|
|
338
329
|
|
|
339
330
|
// NOTE: This string will be replaced on build time with the package version.
|
|
340
|
-
var version = "20.
|
|
331
|
+
var version = "20.6.1";
|
|
341
332
|
|
|
342
333
|
exports["default"] = DropdownMenu;
|
|
343
334
|
exports.useDropdownMenuContext = useDropdownMenuContext;
|
|
@@ -14,7 +14,6 @@ import { useContext, createContext, forwardRef, useRef, useLayoutEffect, useMemo
|
|
|
14
14
|
import { filterDataAttributes } from '@commercetools-uikit/utils';
|
|
15
15
|
import { useToggleState } from '@commercetools-uikit/hooks';
|
|
16
16
|
import { jsx, jsxs } from '@emotion/react/jsx-runtime';
|
|
17
|
-
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
18
17
|
import _setTimeout from '@babel/runtime-corejs3/core-js-stable/set-timeout';
|
|
19
18
|
import { css } from '@emotion/react';
|
|
20
19
|
import { designTokens } from '@commercetools-uikit/design-system';
|
|
@@ -48,7 +47,7 @@ DropDownTrigger.displayName = 'DropDownTrigger';
|
|
|
48
47
|
var DropdownTrigger = DropDownTrigger;
|
|
49
48
|
|
|
50
49
|
function ownKeys$2(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
51
|
-
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
50
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context2 = ownKeys$2(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context3 = ownKeys$2(Object(t))).call(_context3, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
52
51
|
const boxShadowBottomSize = '5px';
|
|
53
52
|
const outerMargin = designTokens.spacing20;
|
|
54
53
|
function getDropdownMenuBaseStyles(params) {
|
|
@@ -69,10 +68,9 @@ function DropdownBaseMenu(props) {
|
|
|
69
68
|
// By default, the menu is not exceeding the viewport, this can change though
|
|
70
69
|
let menuIsExceedingViewport = false;
|
|
71
70
|
if (menuDOMRect.width >= document.body.scrollWidth) {
|
|
72
|
-
var _context;
|
|
73
71
|
// If the menu width is greater than the body width, we need to set the width of the menu to the body width
|
|
74
72
|
// to prevent the menu from overflowing, this happens usually when the horizontalConstraint is set to 'auto'
|
|
75
|
-
menuEl.style.width =
|
|
73
|
+
menuEl.style.width = `calc(${document.body.scrollWidth}px - 2 * ${outerMargin})`;
|
|
76
74
|
menuIsExceedingViewport = true;
|
|
77
75
|
}
|
|
78
76
|
|
|
@@ -111,40 +109,36 @@ function DropdownBaseMenu(props) {
|
|
|
111
109
|
// the trigger
|
|
112
110
|
const scrollWidthDiff = (document.body.scrollWidth - scrollWidthBefore) * 0.5;
|
|
113
111
|
if (menuIsExceedingViewport) {
|
|
114
|
-
|
|
115
|
-
menuEl.style.left = _concatInstanceProperty(_context2 = "calc( ".concat(outerMargin, " + ")).call(_context2, scrollWidthDiff, "px)");
|
|
112
|
+
menuEl.style.left = `calc( ${outerMargin} + ${scrollWidthDiff}px)`;
|
|
116
113
|
} else if (menuXPosition === 'left') {
|
|
117
|
-
menuEl.style.left =
|
|
114
|
+
menuEl.style.left = `${triggerDOMRect.left + scrollWidthDiff}px`;
|
|
118
115
|
menuEl.style.removeProperty('right');
|
|
119
116
|
} else {
|
|
120
|
-
menuEl.style.right =
|
|
117
|
+
menuEl.style.right = `${window.innerWidth - triggerDOMRect.right - scrollWidthDiff}px`;
|
|
121
118
|
menuEl.style.removeProperty('left');
|
|
122
119
|
}
|
|
123
120
|
if (menuYPosition === 'below') {
|
|
124
|
-
|
|
125
|
-
menuEl.style.top = _concatInstanceProperty(_context3 = "calc(".concat(triggerDOMRect.top + triggerDOMRect.height, "px + ")).call(_context3, outerMargin, ")");
|
|
121
|
+
menuEl.style.top = `calc(${triggerDOMRect.top + triggerDOMRect.height}px + ${outerMargin})`;
|
|
126
122
|
} else {
|
|
127
|
-
var _context4;
|
|
128
123
|
// Need to re-request getBoundingClientRect() because the menu height
|
|
129
124
|
// might have changed when the dropdown is in 'auto' mode;
|
|
130
125
|
let desiredMenuHeight = menuMaxHeight || menuEl.getBoundingClientRect().height;
|
|
131
|
-
menuEl.style.top =
|
|
126
|
+
menuEl.style.top = `calc(${triggerDOMRect.top - desiredMenuHeight}px - ${outerMargin})`;
|
|
132
127
|
}
|
|
133
128
|
if (menuMaxHeight) {
|
|
134
129
|
// Apply the manual max-width
|
|
135
130
|
menuEl.style.maxHeight = menuMaxHeight + 'px';
|
|
136
131
|
} else {
|
|
137
|
-
var _context5, _context6, _context7, _context8;
|
|
138
132
|
// Make sure max-height does not exceed the available top- or bottom-space
|
|
139
|
-
menuEl.style.maxHeight = menuYPosition === 'below' ?
|
|
133
|
+
menuEl.style.maxHeight = menuYPosition === 'below' ? `calc(${window.innerHeight - triggerDOMRect.bottom}px - ${outerMargin} - ${boxShadowBottomSize})` : `calc(${triggerDOMRect.top}px - ${outerMargin} - ${boxShadowBottomSize})`;
|
|
140
134
|
}
|
|
141
135
|
|
|
142
136
|
// All positioning operations done, make menu visible again
|
|
143
137
|
menuEl.style.visibility = 'visible';
|
|
144
138
|
}, 0);
|
|
145
139
|
return () => {
|
|
146
|
-
var
|
|
147
|
-
_forEachInstanceProperty(
|
|
140
|
+
var _context;
|
|
141
|
+
_forEachInstanceProperty(_context = ['top', 'left', 'right', 'bottom', 'width', 'height', 'maxHeight', 'visibility']).call(_context, prop => {
|
|
148
142
|
menuEl.style.removeProperty(prop);
|
|
149
143
|
});
|
|
150
144
|
};
|
|
@@ -197,9 +191,8 @@ function DropdownListMenuItem(props) {
|
|
|
197
191
|
return jsx(AccessibleButton, _objectSpread$1(_objectSpread$1({
|
|
198
192
|
label: props.children,
|
|
199
193
|
onClick: () => {
|
|
200
|
-
var _props$onClick;
|
|
201
194
|
toggle();
|
|
202
|
-
|
|
195
|
+
props.onClick?.();
|
|
203
196
|
},
|
|
204
197
|
isDisabled: props.isDisabled,
|
|
205
198
|
css: getDropdownListMenuItemStyles(props)
|
|
@@ -282,9 +275,8 @@ function DropdownMenu(_ref) {
|
|
|
282
275
|
|
|
283
276
|
// Close the dropdown when clicking outside of it
|
|
284
277
|
const handleGlobalClick = useCallback(event => {
|
|
285
|
-
var _triggerElement$paren;
|
|
286
278
|
const triggerElement = triggerRef.current;
|
|
287
|
-
if (isOpen && triggerElement && event.target !== triggerElement && window.document.contains(event.target) && !
|
|
279
|
+
if (isOpen && triggerElement && event.target !== triggerElement && window.document.contains(event.target) && !triggerElement.parentElement?.contains(event.target)) {
|
|
288
280
|
toggle(false);
|
|
289
281
|
}
|
|
290
282
|
}, [triggerRef, toggle, isOpen]);
|
|
@@ -324,6 +316,6 @@ function DropdownMenu(_ref) {
|
|
|
324
316
|
DropdownMenu.ListMenuItem = DropdownListMenuItem;
|
|
325
317
|
|
|
326
318
|
// NOTE: This string will be replaced on build time with the package version.
|
|
327
|
-
var version = "20.
|
|
319
|
+
var version = "20.6.1";
|
|
328
320
|
|
|
329
321
|
export { DropdownMenu as default, useDropdownMenuContext, version };
|
|
@@ -3,7 +3,7 @@ import { type TMaxProp } from '@commercetools-uikit/constraints';
|
|
|
3
3
|
export declare function getDropdownMenuBaseStyles(params: {
|
|
4
4
|
isOpen: boolean;
|
|
5
5
|
horizontalConstraint: TMaxProp;
|
|
6
|
-
}): import("@emotion/
|
|
6
|
+
}): import("@emotion/react").SerializedStyles;
|
|
7
7
|
export type TDropdownContentMenuProps = {
|
|
8
8
|
children: ReactNode;
|
|
9
9
|
horizontalConstraint: TMaxProp;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-uikit/dropdown-menu",
|
|
3
3
|
"description": "The Dropdown Menu component represents a component that triggers the rendering of a floating menu.",
|
|
4
|
-
"version": "20.
|
|
4
|
+
"version": "20.6.1",
|
|
5
5
|
"bugs": "https://github.com/commercetools/ui-kit/issues",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -9,7 +9,13 @@
|
|
|
9
9
|
"directory": "packages/components/dropdowns/dropdown-menu"
|
|
10
10
|
},
|
|
11
11
|
"homepage": "https://uikit.commercetools.com",
|
|
12
|
-
"keywords": [
|
|
12
|
+
"keywords": [
|
|
13
|
+
"javascript",
|
|
14
|
+
"typescript",
|
|
15
|
+
"design-system",
|
|
16
|
+
"react",
|
|
17
|
+
"uikit"
|
|
18
|
+
],
|
|
13
19
|
"license": "MIT",
|
|
14
20
|
"publishConfig": {
|
|
15
21
|
"access": "public"
|
|
@@ -17,26 +23,33 @@
|
|
|
17
23
|
"sideEffects": false,
|
|
18
24
|
"main": "dist/commercetools-uikit-dropdown-menu.cjs.js",
|
|
19
25
|
"module": "dist/commercetools-uikit-dropdown-menu.esm.js",
|
|
20
|
-
"files": [
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
21
29
|
"dependencies": {
|
|
22
30
|
"@babel/runtime": "^7.20.13",
|
|
23
31
|
"@babel/runtime-corejs3": "^7.20.13",
|
|
24
|
-
"@commercetools-uikit/accessible-button": "20.5.0",
|
|
25
|
-
"@commercetools-uikit/constraints": "20.5.0",
|
|
26
|
-
"@commercetools-uikit/design-system": "20.5.0",
|
|
27
|
-
"@commercetools-uikit/hooks": "20.5.0",
|
|
28
|
-
"@commercetools-uikit/secondary-button": "20.5.0",
|
|
29
|
-
"@commercetools-uikit/spacings-inline": "20.5.0",
|
|
30
|
-
"@commercetools-uikit/spacings-stack": "20.5.0",
|
|
31
|
-
"@commercetools-uikit/utils": "20.5.0",
|
|
32
32
|
"@emotion/react": "^11.10.5",
|
|
33
33
|
"@emotion/styled": "^11.10.5",
|
|
34
|
-
"react-intl": "^7.1.4"
|
|
34
|
+
"react-intl": "^7.1.4",
|
|
35
|
+
"@commercetools-uikit/accessible-button": "^20.6.1",
|
|
36
|
+
"@commercetools-uikit/constraints": "^20.6.1",
|
|
37
|
+
"@commercetools-uikit/design-system": "^20.6.1",
|
|
38
|
+
"@commercetools-uikit/hooks": "^20.6.1",
|
|
39
|
+
"@commercetools-uikit/secondary-button": "^20.6.1",
|
|
40
|
+
"@commercetools-uikit/spacings-inline": "^20.6.1",
|
|
41
|
+
"@commercetools-uikit/spacings-stack": "^20.6.1",
|
|
42
|
+
"@commercetools-uikit/utils": "^20.6.1"
|
|
35
43
|
},
|
|
36
44
|
"devDependencies": {
|
|
37
|
-
"react": "19.2.
|
|
45
|
+
"react": "19.2.6",
|
|
46
|
+
"@commercetools-uikit/buttons": "^20.6.1",
|
|
47
|
+
"@commercetools-uikit/checkbox-input": "^20.6.1",
|
|
48
|
+
"@commercetools-uikit/icons": "^20.6.1",
|
|
49
|
+
"@commercetools-uikit/select-input": "^20.6.1",
|
|
50
|
+
"@commercetools-uikit/text": "^20.6.1"
|
|
38
51
|
},
|
|
39
52
|
"peerDependencies": {
|
|
40
53
|
"react": "19.x"
|
|
41
54
|
}
|
|
42
|
-
}
|
|
55
|
+
}
|