@carbon/react 1.23.0 → 1.23.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.
Files changed (47) hide show
  1. package/es/components/Dropdown/Dropdown.Skeleton.d.ts +15 -0
  2. package/es/components/Dropdown/Dropdown.Skeleton.js +1 -2
  3. package/es/components/Dropdown/index.js +1 -0
  4. package/es/components/FluidDropdown/FluidDropdown.js +1 -0
  5. package/es/components/Heading/index.js +11 -4
  6. package/es/components/Menu/Menu.js +164 -216
  7. package/es/components/Menu/MenuContext.js +44 -0
  8. package/es/components/Menu/MenuItem.js +401 -23
  9. package/es/components/MultiSelect/MultiSelect.js +6 -0
  10. package/es/components/OverflowMenu/OverflowMenu.js +2 -2
  11. package/es/components/OverflowMenuV2/index.js +4 -14
  12. package/es/components/Search/Search.js +3 -3
  13. package/es/index.d.ts +1 -1
  14. package/es/index.js +2 -6
  15. package/es/prop-types/isRequiredOneOf.js +2 -2
  16. package/lib/components/Dropdown/Dropdown.Skeleton.d.ts +15 -0
  17. package/lib/components/Dropdown/Dropdown.Skeleton.js +1 -2
  18. package/lib/components/Dropdown/index.js +2 -0
  19. package/lib/components/FluidDropdown/FluidDropdown.js +1 -0
  20. package/lib/components/Heading/index.js +11 -4
  21. package/lib/components/Menu/Menu.js +163 -216
  22. package/lib/components/Menu/MenuContext.js +53 -0
  23. package/lib/components/Menu/MenuItem.js +406 -23
  24. package/lib/components/MultiSelect/MultiSelect.js +6 -0
  25. package/lib/components/OverflowMenu/OverflowMenu.js +2 -2
  26. package/lib/components/OverflowMenuV2/index.js +5 -15
  27. package/lib/components/Search/Search.js +3 -3
  28. package/lib/index.d.ts +1 -1
  29. package/lib/index.js +7 -11
  30. package/lib/prop-types/isRequiredOneOf.js +2 -2
  31. package/package.json +4 -4
  32. package/es/components/Menu/MenuDivider.js +0 -19
  33. package/es/components/Menu/MenuGroup.js +0 -34
  34. package/es/components/Menu/MenuOption.js +0 -250
  35. package/es/components/Menu/MenuRadioGroup.js +0 -50
  36. package/es/components/Menu/MenuRadioGroupOptions.js +0 -64
  37. package/es/components/Menu/MenuSelectableItem.js +0 -57
  38. package/es/components/Menu/_utils.js +0 -177
  39. package/es/components/Menu/index.js +0 -25
  40. package/lib/components/Menu/MenuDivider.js +0 -27
  41. package/lib/components/Menu/MenuGroup.js +0 -43
  42. package/lib/components/Menu/MenuOption.js +0 -260
  43. package/lib/components/Menu/MenuRadioGroup.js +0 -59
  44. package/lib/components/Menu/MenuRadioGroupOptions.js +0 -73
  45. package/lib/components/Menu/MenuSelectableItem.js +0 -66
  46. package/lib/components/Menu/_utils.js +0 -191
  47. package/lib/components/Menu/index.js +0 -31
@@ -1,191 +0,0 @@
1
- /**
2
- * Copyright IBM Corp. 2016, 2022
3
- *
4
- * This source code is licensed under the Apache-2.0 license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- 'use strict';
9
-
10
- Object.defineProperty(exports, '__esModule', { value: true });
11
-
12
- var prefix = 'cds';
13
- function resetFocus(el) {
14
- if (el) {
15
- var _el$querySelectorAll;
16
-
17
- Array.from((_el$querySelectorAll = el.querySelectorAll('[tabindex="0"]')) !== null && _el$querySelectorAll !== void 0 ? _el$querySelectorAll : []).forEach(function (node) {
18
- node.tabIndex = -1;
19
- });
20
- }
21
- }
22
- function focusNode(node) {
23
- if (node) {
24
- node.tabIndex = 0;
25
- node.focus();
26
- }
27
- }
28
- function getValidNodes(list) {
29
- var level = list.dataset.level;
30
- var nodes = [];
31
-
32
- if (level) {
33
- var submenus = Array.from(list.querySelectorAll('[data-level]'));
34
- nodes = Array.from(list.querySelectorAll("li.".concat(prefix, "--menu-option"))).filter(function (child) {
35
- return !submenus.some(function (submenu) {
36
- return submenu.contains(child);
37
- });
38
- });
39
- }
40
-
41
- return nodes.filter(function (node) {
42
- return node.matches(":not(.".concat(prefix, "--menu-option--disabled)"));
43
- });
44
- }
45
- function getNextNode(current, direction) {
46
- var menu = getParentMenu(current);
47
- var nodes = getValidNodes(menu);
48
- var currentIndex = nodes.indexOf(current);
49
- var nextNode = nodes[currentIndex + direction];
50
- return nextNode || null;
51
- }
52
- function getFirstSubNode(node) {
53
- var submenu = node.querySelector("ul.".concat(prefix, "--menu"));
54
-
55
- if (submenu) {
56
- var subnodes = getValidNodes(submenu);
57
- return subnodes[0] || null;
58
- }
59
-
60
- return null;
61
- }
62
- function getParentNode(node) {
63
- if (node) {
64
- var parentNode = node.parentNode.closest("li.".concat(prefix, "--menu-option"));
65
- return parentNode || null;
66
- }
67
-
68
- return null;
69
- }
70
- function getSubMenuOffset(node) {
71
- if (node) {
72
- var nodeStyles = getComputedStyle(node);
73
- var spacings = parseInt(nodeStyles.paddingTop) + parseInt(nodeStyles.paddingBottom); // styles always in px, convert to number
74
-
75
- var elementHeight = node.firstElementChild.offsetHeight;
76
- return elementHeight + spacings || 0;
77
- }
78
-
79
- return 0;
80
- }
81
- function getParentMenu(el) {
82
- if (el) {
83
- var parentMenu = el.parentNode.closest("ul.".concat(prefix, "--menu"));
84
- return parentMenu || null;
85
- }
86
-
87
- return null;
88
- }
89
- function clickedElementHasSubnodes(e) {
90
- if (e) {
91
- var closestFocusableElement = e.target.closest('[tabindex]');
92
-
93
- if ((closestFocusableElement === null || closestFocusableElement === void 0 ? void 0 : closestFocusableElement.tagName) === 'LI') {
94
- return getFirstSubNode(closestFocusableElement) !== null;
95
- }
96
- }
97
-
98
- return false;
99
- }
100
- /**
101
- * @param {number} [value] The value to cap
102
- * @param {number} [min] The minimum of the range
103
- * @param {number} [max] The maximum of the range
104
- * @returns {number} Whether or not the element fits inside the boundaries on the given axis
105
- */
106
-
107
- function capWithinRange(value, min, max) {
108
- if (value > max) {
109
- return max;
110
- }
111
-
112
- if (value < min) {
113
- return min;
114
- }
115
-
116
- return value;
117
- }
118
- /**
119
- * @param {number[]} [elementDimensions] The dimensions of the element: [width, height]
120
- * @param {number[]} [position] The desired position of the element: [x, y]
121
- * @param {number[]} [boundaries] The boundaries of the container the element should be contained in: [minX, minY, maxX, maxY]
122
- * @param {string} [axis="x"] Which axis to check. Either "x" or "y"
123
- * @returns {boolean} Whether or not the element fits inside the boundaries on the given axis
124
- */
125
-
126
- function elementFits(elementDimensions, position, boundaries) {
127
- var axis = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'x';
128
- var index = axis === 'y' ? 1 : 0;
129
- var min = boundaries[index];
130
- var max = boundaries[index + 2];
131
- var start = position[index];
132
- var end = position[index] + elementDimensions[index];
133
- return start >= min && end <= max;
134
- }
135
- /**
136
- * @param {number[]} [elementDimensions] The dimensions of the element: [width, height]
137
- * @param {number[]} [targetBoundaries] The boundaries of the target the element should attach to: [minX, minY, maxX, maxY]
138
- * @param {number[]} [containerBoundaries] The boundaries of the container the element should be contained in: [minX, minY, maxX, maxY]
139
- * @param {number} [preferredDirection=1] Which direction is preferred. Either 1 (right right) or -1 (to left)
140
- * @param {boolean} [isRootLevel] Flag that indicates if the element is on level 1 (the root level)
141
- * @param {object} [element] The list element - used to calculate the offset of submenus
142
- * @returns {object} The determined position and direction of the element: { position: [x, y], direction: 1 | -1 }
143
- */
144
-
145
-
146
- function getPosition(elementDimensions, targetBoundaries, containerBoundaries) {
147
- var preferredDirection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
148
- var isRootLevel = arguments.length > 4 ? arguments[4] : undefined;
149
- var element = arguments.length > 5 ? arguments[5] : undefined;
150
- var position = [0, 0];
151
- var direction = preferredDirection; // x
152
-
153
- position[0] = direction === 1 ? targetBoundaries[0] : targetBoundaries[2] - elementDimensions[0];
154
- var xFits = elementFits(elementDimensions, position, containerBoundaries, 'x');
155
-
156
- if (!xFits) {
157
- direction = direction * -1;
158
- position[0] = direction === 1 ? targetBoundaries[0] : targetBoundaries[2] - elementDimensions[0];
159
- } // y
160
-
161
-
162
- position[1] = targetBoundaries[3];
163
- var yFits = elementFits(elementDimensions, position, containerBoundaries, 'y');
164
-
165
- if (!yFits) {
166
- position[1] = targetBoundaries[1] - elementDimensions[1];
167
-
168
- if (!isRootLevel && element) {
169
- // if sub-menu and not root level, consider offset
170
- var diff = getSubMenuOffset(element);
171
- position[1] += diff;
172
- }
173
- }
174
-
175
- return {
176
- position: position,
177
- direction: direction
178
- };
179
- }
180
-
181
- exports.capWithinRange = capWithinRange;
182
- exports.clickedElementHasSubnodes = clickedElementHasSubnodes;
183
- exports.focusNode = focusNode;
184
- exports.getFirstSubNode = getFirstSubNode;
185
- exports.getNextNode = getNextNode;
186
- exports.getParentMenu = getParentMenu;
187
- exports.getParentNode = getParentNode;
188
- exports.getPosition = getPosition;
189
- exports.getSubMenuOffset = getSubMenuOffset;
190
- exports.getValidNodes = getValidNodes;
191
- exports.resetFocus = resetFocus;
@@ -1,31 +0,0 @@
1
- /**
2
- * Copyright IBM Corp. 2016, 2022
3
- *
4
- * This source code is licensed under the Apache-2.0 license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- 'use strict';
9
-
10
- Object.defineProperty(exports, '__esModule', { value: true });
11
-
12
- var Menu = require('./Menu.js');
13
- var MenuDivider = require('./MenuDivider.js');
14
- var MenuGroup = require('./MenuGroup.js');
15
- var MenuItem = require('./MenuItem.js');
16
- var MenuRadioGroup = require('./MenuRadioGroup.js');
17
- var MenuSelectableItem = require('./MenuSelectableItem.js');
18
-
19
- Menu["default"].MenuDivider = MenuDivider["default"];
20
- Menu["default"].MenuGroup = MenuGroup["default"];
21
- Menu["default"].MenuItem = MenuItem["default"];
22
- Menu["default"].MenuRadioGroup = MenuRadioGroup["default"];
23
- Menu["default"].MenuSelectableItem = MenuSelectableItem["default"];
24
-
25
- exports.Menu = Menu["default"];
26
- exports["default"] = Menu["default"];
27
- exports.MenuDivider = MenuDivider["default"];
28
- exports.MenuGroup = MenuGroup["default"];
29
- exports.MenuItem = MenuItem["default"];
30
- exports.MenuRadioGroup = MenuRadioGroup["default"];
31
- exports.MenuSelectableItem = MenuSelectableItem["default"];