@primer/react 0.0.0-20260402165401 → 0.0.0-20260402201150

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.
@@ -1,19 +1,29 @@
1
1
  import { c } from 'react-compiler-runtime';
2
- import React, { useRef, forwardRef, useState, useMemo, useCallback, useContext, useSyncExternalStore } from 'react';
2
+ import React, { useRef, useState, forwardRef, useMemo, useCallback } from 'react';
3
3
  import { KebabHorizontalIcon } from '@primer/octicons-react';
4
4
  import { ActionList } from '../ActionList/index.js';
5
+ import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
6
+ import { useResizeObserver } from '../hooks/useResizeObserver.js';
5
7
  import { IconButton } from '../Button/IconButton.js';
6
8
  import { useFocusZone } from '../hooks/useFocusZone.js';
7
9
  import styles from './ActionBar.module.css.js';
8
10
  import { clsx } from 'clsx';
9
11
  import { createDescendantRegistry } from '../utils/descendant-registry.js';
10
- import { jsx, jsxs } from 'react/jsx-runtime';
12
+ import { jsxs, jsx } from 'react/jsx-runtime';
11
13
  import { useMergedRefs } from '../hooks/useMergedRefs.js';
12
14
  import { FocusKeys } from '@primer/behaviors';
13
15
  import { ActionMenu } from '../ActionMenu/ActionMenu.js';
14
16
 
17
+ const ACTIONBAR_ITEM_GAP = 8;
18
+
19
+ /**
20
+ * Registry of descendants to render in the list or menu. To preserve insertion order across updates, children are
21
+ * set to `null` when unregistered rather than fully dropped from the map.
22
+ */
23
+
15
24
  const ActionBarContext = /*#__PURE__*/React.createContext({
16
25
  size: 'medium',
26
+ isVisibleChild: () => true,
17
27
  groupId: undefined
18
28
  });
19
29
 
@@ -21,7 +31,23 @@ const ActionBarContext = /*#__PURE__*/React.createContext({
21
31
  small (28px), medium (32px), large (40px)
22
32
  */
23
33
 
34
+ const MORE_BTN_WIDTH = 32;
24
35
  const ActionBarItemsRegistry = createDescendantRegistry();
36
+ const calculatePossibleItems = (registryEntries, navWidth, gap, moreMenuWidth = 0) => {
37
+ const widthToFit = navWidth - moreMenuWidth;
38
+ let breakpoint = registryEntries.length; // assume all items will fit
39
+ let sumsOfChildWidth = 0;
40
+ for (const [index, [, child]] of registryEntries.entries()) {
41
+ sumsOfChildWidth += index > 0 ? child.width + gap : child.width;
42
+ if (sumsOfChildWidth > widthToFit) {
43
+ breakpoint = index;
44
+ break;
45
+ } else {
46
+ continue;
47
+ }
48
+ }
49
+ return breakpoint;
50
+ };
25
51
  const renderMenuItem = (item, index) => {
26
52
  if (item.type === 'divider') {
27
53
  return /*#__PURE__*/jsx(ActionList.Divider, {}, index);
@@ -70,8 +96,44 @@ const renderMenuItem = (item, index) => {
70
96
  }, label);
71
97
  };
72
98
  renderMenuItem.displayName = "renderMenuItem";
99
+ const getMenuItems = (navWidth, moreMenuWidth, childRegistry, hasActiveMenu, gap) => {
100
+ var _childRegistry$entrie;
101
+ const registryEntries = Array.from((_childRegistry$entrie = childRegistry === null || childRegistry === void 0 ? void 0 : childRegistry.entries()) !== null && _childRegistry$entrie !== void 0 ? _childRegistry$entrie : []).filter(entry => entry[1] !== null && (entry[1].type !== 'action' || entry[1].groupId === undefined));
102
+ if (registryEntries.length === 0) return new Set();
103
+ const numberOfItemsPossible = calculatePossibleItems(registryEntries, navWidth, gap);
104
+ const numberOfItemsPossibleWithMoreMenu = calculatePossibleItems(registryEntries, navWidth, gap, moreMenuWidth || MORE_BTN_WIDTH);
105
+ const menuItems = new Set();
106
+
107
+ // First, we check if we can fit all the items with their icons
108
+ if (registryEntries.length >= numberOfItemsPossible) {
109
+ /* Below is an accessibility requirement. Never show only one item in the overflow menu.
110
+ * If there is only one item left to display in the overflow menu according to the calculation,
111
+ * we need to pull another item from the list into the overflow menu.
112
+ */
113
+ const numberOfItemsInMenu = registryEntries.length - numberOfItemsPossibleWithMoreMenu;
114
+ const numberOfListItems = numberOfItemsInMenu === 1 ? numberOfItemsPossibleWithMoreMenu - 1 : numberOfItemsPossibleWithMoreMenu;
115
+ for (const [index, [id, child]] of registryEntries.entries()) {
116
+ if (index < numberOfListItems) {
117
+ continue;
118
+ //if the last item is a divider
119
+ } else if (child.type === 'divider') {
120
+ if (index === numberOfListItems - 1 || index === numberOfListItems) {
121
+ continue;
122
+ } else {
123
+ menuItems.add(id);
124
+ }
125
+ } else {
126
+ menuItems.add(id);
127
+ }
128
+ }
129
+ return menuItems;
130
+ } else if (numberOfItemsPossible > registryEntries.length && hasActiveMenu) {
131
+ /* If the items fit in the list and there are items in the overflow menu, we need to move them back to the list */
132
+ return new Set();
133
+ }
134
+ };
73
135
  const ActionBar = props => {
74
- const $ = c(36);
136
+ const $ = c(38);
75
137
  const {
76
138
  size: t0,
77
139
  children,
@@ -85,254 +147,276 @@ const ActionBar = props => {
85
147
  const flush = t1 === undefined ? false : t1;
86
148
  const gap = t2 === undefined ? "condensed" : t2;
87
149
  const listRef = useRef(null);
150
+ const [computedGap, setComputedGap] = useState(ACTIONBAR_ITEM_GAP);
88
151
  const [childRegistry, setChildRegistry] = ActionBarItemsRegistry.useRegistryState();
152
+ const [menuItemIds, setMenuItemIds] = useState(_temp);
89
153
  const navRef = useRef(null);
90
154
  let t3;
91
155
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
92
- t3 = {
93
- containerRef: listRef,
94
- bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
95
- focusOutBehavior: "wrap",
96
- getNextFocusable: (direction, from) => {
97
- var _listRef$current$quer, _listRef$current;
98
- const items = Array.from((_listRef$current$quer = (_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.querySelectorAll(":is(button, a, input, [tabindex]):not(:disabled):not([data-overflowing]):not([data-more-button-inactive])")) !== null && _listRef$current$quer !== void 0 ? _listRef$current$quer : []);
99
- const fromIndex = from ? items.indexOf(from) : -1;
100
- switch (direction) {
101
- case "start":
102
- {
103
- return items[0];
104
- }
105
- case "end":
106
- {
107
- return items.at(-1);
108
- }
109
- case "next":
110
- {
111
- var _items;
112
- return (_items = items[fromIndex + 1]) !== null && _items !== void 0 ? _items : items[0];
113
- }
114
- case "previous":
115
- {
116
- var _items2;
117
- return (_items2 = items[fromIndex - 1]) !== null && _items2 !== void 0 ? _items2 : items.at(-1);
118
- }
119
- }
156
+ t3 = () => {
157
+ if (!listRef.current) {
158
+ return;
159
+ }
160
+ const g = window.getComputedStyle(listRef.current).gap;
161
+ const parsed = parseFloat(g);
162
+ if (!Number.isNaN(parsed)) {
163
+ setComputedGap(parsed);
120
164
  }
121
165
  };
122
166
  $[0] = t3;
123
167
  } else {
124
168
  t3 = $[0];
125
169
  }
126
- useFocusZone(t3);
127
170
  let t4;
128
- if ($[1] !== childRegistry) {
129
- t4 = childRegistry && Array.from(childRegistry.entries()).filter(_temp);
130
- $[1] = childRegistry;
171
+ if ($[1] !== gap) {
172
+ t4 = [gap];
173
+ $[1] = gap;
131
174
  $[2] = t4;
132
175
  } else {
133
176
  t4 = $[2];
134
177
  }
135
- const overflowItems = t4;
178
+ useIsomorphicLayoutEffect(t3, t4);
179
+ const moreMenuRef = useRef(null);
136
180
  let t5;
137
- if ($[3] !== size) {
138
- t5 = {
139
- size
181
+ if ($[3] !== childRegistry || $[4] !== computedGap || $[5] !== menuItemIds.size) {
182
+ t5 = resizeObserverEntries => {
183
+ var _moreMenuRef$current$, _moreMenuRef$current;
184
+ const navWidth = resizeObserverEntries[0].contentRect.width;
185
+ const moreMenuWidth = (_moreMenuRef$current$ = (_moreMenuRef$current = moreMenuRef.current) === null || _moreMenuRef$current === void 0 ? void 0 : _moreMenuRef$current.getBoundingClientRect().width) !== null && _moreMenuRef$current$ !== void 0 ? _moreMenuRef$current$ : 0;
186
+ const hasActiveMenu = menuItemIds.size > 0;
187
+ if (navWidth > 0) {
188
+ const newMenuItemIds = getMenuItems(navWidth, moreMenuWidth, childRegistry, hasActiveMenu, computedGap);
189
+ if (newMenuItemIds) {
190
+ setMenuItemIds(newMenuItemIds);
191
+ }
192
+ }
140
193
  };
141
- $[3] = size;
142
- $[4] = t5;
194
+ $[3] = childRegistry;
195
+ $[4] = computedGap;
196
+ $[5] = menuItemIds.size;
197
+ $[6] = t5;
143
198
  } else {
144
- t5 = $[4];
199
+ t5 = $[6];
145
200
  }
201
+ useResizeObserver(t5, navRef);
146
202
  let t6;
147
- if ($[5] !== className) {
148
- t6 = clsx(className, styles.Nav);
149
- $[5] = className;
150
- $[6] = t6;
203
+ if ($[7] !== menuItemIds) {
204
+ t6 = id => !menuItemIds.has(id);
205
+ $[7] = menuItemIds;
206
+ $[8] = t6;
151
207
  } else {
152
- t6 = $[6];
208
+ t6 = $[8];
153
209
  }
154
- const t7 = overflowItems ? overflowItems.length > 0 : undefined;
155
- let t8;
156
- if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
157
- t8 = /*#__PURE__*/jsx("div", {});
158
- $[7] = t8;
210
+ const isVisibleChild = t6;
211
+ let t7;
212
+ if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
213
+ t7 = {
214
+ containerRef: listRef,
215
+ bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
216
+ focusOutBehavior: "wrap"
217
+ };
218
+ $[9] = t7;
159
219
  } else {
160
- t8 = $[7];
161
- }
162
- let t9;
163
- if ($[8] !== children || $[9] !== setChildRegistry) {
164
- t9 = /*#__PURE__*/jsxs("div", {
165
- className: styles.OverflowContainer,
166
- children: [t8, /*#__PURE__*/jsx(ActionBarItemsRegistry.Provider, {
167
- setRegistry: setChildRegistry,
168
- children: children
169
- })]
170
- });
171
- $[8] = children;
172
- $[9] = setChildRegistry;
173
- $[10] = t9;
220
+ t7 = $[9];
221
+ }
222
+ useFocusZone(t7);
223
+ let groupedItemsMap;
224
+ if ($[10] !== childRegistry) {
225
+ groupedItemsMap = new Map();
226
+ for (const [key, childProps] of childRegistry !== null && childRegistry !== void 0 ? childRegistry : []) {
227
+ if (childProps.type === "action" && childProps.groupId) {
228
+ const existingGroup = groupedItemsMap.get(childProps.groupId) || [];
229
+ existingGroup.push([key, childProps]);
230
+ groupedItemsMap.set(childProps.groupId, existingGroup);
231
+ }
232
+ }
233
+ $[10] = childRegistry;
234
+ $[11] = groupedItemsMap;
174
235
  } else {
175
- t9 = $[10];
236
+ groupedItemsMap = $[11];
176
237
  }
177
- const t10 = `More ${ariaLabel} items ${overflowItems === null || overflowItems === void 0 ? void 0 : overflowItems.length}`;
178
- const t11 = overflowItems !== null && overflowItems !== void 0 && overflowItems.length ? undefined : true;
179
- let t12;
180
- if ($[11] !== t10 || $[12] !== t11) {
181
- t12 = /*#__PURE__*/jsx(ActionMenu.Anchor, {
182
- children: /*#__PURE__*/jsx(IconButton, {
183
- variant: "invisible",
184
- "aria-label": t10,
185
- icon: KebabHorizontalIcon,
186
- className: styles.MoreButton,
187
- "data-more-button-inactive": t11
188
- })
189
- });
190
- $[11] = t10;
191
- $[12] = t11;
192
- $[13] = t12;
238
+ const groupedItems = groupedItemsMap;
239
+ let t8;
240
+ if ($[12] !== isVisibleChild || $[13] !== size) {
241
+ t8 = {
242
+ size,
243
+ isVisibleChild
244
+ };
245
+ $[12] = isVisibleChild;
246
+ $[13] = size;
247
+ $[14] = t8;
193
248
  } else {
194
- t12 = $[13];
249
+ t8 = $[14];
195
250
  }
196
- let t13;
197
- if ($[14] !== overflowItems) {
198
- t13 = overflowItems === null || overflowItems === void 0 ? void 0 : overflowItems.map(_temp3);
199
- $[14] = overflowItems;
200
- $[15] = t13;
251
+ let t9;
252
+ if ($[15] !== className) {
253
+ t9 = clsx(className, styles.Nav);
254
+ $[15] = className;
255
+ $[16] = t9;
201
256
  } else {
202
- t13 = $[15];
257
+ t9 = $[16];
203
258
  }
204
- let t14;
205
- if ($[16] !== t13) {
206
- t14 = /*#__PURE__*/jsx(ActionMenu.Overlay, {
207
- children: /*#__PURE__*/jsx(ActionList, {
208
- children: t13
209
- })
259
+ let t10;
260
+ if ($[17] !== children || $[18] !== setChildRegistry) {
261
+ t10 = /*#__PURE__*/jsx(ActionBarItemsRegistry.Provider, {
262
+ setRegistry: setChildRegistry,
263
+ children: children
210
264
  });
211
- $[16] = t13;
212
- $[17] = t14;
265
+ $[17] = children;
266
+ $[18] = setChildRegistry;
267
+ $[19] = t10;
213
268
  } else {
214
- t14 = $[17];
269
+ t10 = $[19];
215
270
  }
216
- let t15;
217
- if ($[18] !== t12 || $[19] !== t14) {
218
- t15 = /*#__PURE__*/jsxs(ActionMenu, {
219
- children: [t12, t14]
271
+ let t11;
272
+ if ($[20] !== ariaLabel || $[21] !== childRegistry || $[22] !== groupedItems || $[23] !== menuItemIds) {
273
+ t11 = menuItemIds.size > 0 && /*#__PURE__*/jsxs(ActionMenu, {
274
+ children: [/*#__PURE__*/jsx(ActionMenu.Anchor, {
275
+ children: /*#__PURE__*/jsx(IconButton, {
276
+ variant: "invisible",
277
+ "aria-label": `More ${ariaLabel} items`,
278
+ icon: KebabHorizontalIcon
279
+ })
280
+ }), /*#__PURE__*/jsx(ActionMenu.Overlay, {
281
+ children: /*#__PURE__*/jsx(ActionList, {
282
+ children: Array.from(menuItemIds).map(id_0 => {
283
+ const menuItem = childRegistry === null || childRegistry === void 0 ? void 0 : childRegistry.get(id_0);
284
+ if (!menuItem) {
285
+ return null;
286
+ }
287
+ if (menuItem.type === "divider") {
288
+ return /*#__PURE__*/jsx(ActionList.Divider, {}, id_0);
289
+ } else {
290
+ if (menuItem.type === "action") {
291
+ const {
292
+ onClick,
293
+ icon: Icon,
294
+ label,
295
+ disabled
296
+ } = menuItem;
297
+ return /*#__PURE__*/jsxs(ActionList.Item, {
298
+ onSelect: event => {
299
+ typeof onClick === "function" && onClick(event);
300
+ },
301
+ disabled: disabled,
302
+ children: [/*#__PURE__*/jsx(ActionList.LeadingVisual, {
303
+ children: /*#__PURE__*/jsx(Icon, {})
304
+ }), label]
305
+ }, label);
306
+ }
307
+ }
308
+ if (menuItem.type === "menu") {
309
+ const menuItems = menuItem.items;
310
+ const {
311
+ icon: Icon_0,
312
+ label: label_0,
313
+ returnFocusRef
314
+ } = menuItem;
315
+ return /*#__PURE__*/jsxs(ActionMenu, {
316
+ children: [/*#__PURE__*/jsx(ActionMenu.Anchor, {
317
+ children: /*#__PURE__*/jsxs(ActionList.Item, {
318
+ children: [Icon_0 !== "none" ? /*#__PURE__*/jsx(ActionList.LeadingVisual, {
319
+ children: /*#__PURE__*/jsx(Icon_0, {})
320
+ }) : null, label_0]
321
+ })
322
+ }), /*#__PURE__*/jsx(ActionMenu.Overlay, {
323
+ ...(returnFocusRef && {
324
+ returnFocusRef
325
+ }),
326
+ children: /*#__PURE__*/jsx(ActionList, {
327
+ children: menuItems.map(_temp2)
328
+ })
329
+ })]
330
+ }, id_0);
331
+ }
332
+ const groupedMenuItems = groupedItems.get(id_0) || [];
333
+ if (menuItem.type === "group") {
334
+ return /*#__PURE__*/jsx(React.Fragment, {
335
+ children: groupedMenuItems.map(_temp3)
336
+ }, id_0);
337
+ }
338
+ })
339
+ })
340
+ })]
220
341
  });
221
- $[18] = t12;
222
- $[19] = t14;
223
- $[20] = t15;
342
+ $[20] = ariaLabel;
343
+ $[21] = childRegistry;
344
+ $[22] = groupedItems;
345
+ $[23] = menuItemIds;
346
+ $[24] = t11;
224
347
  } else {
225
- t15 = $[20];
348
+ t11 = $[24];
226
349
  }
227
- let t16;
228
- if ($[21] !== ariaLabel || $[22] !== ariaLabelledBy || $[23] !== gap || $[24] !== size || $[25] !== t15 || $[26] !== t7 || $[27] !== t9) {
229
- t16 = /*#__PURE__*/jsxs("div", {
350
+ let t12;
351
+ if ($[25] !== ariaLabel || $[26] !== ariaLabelledBy || $[27] !== gap || $[28] !== t10 || $[29] !== t11) {
352
+ t12 = /*#__PURE__*/jsxs("div", {
230
353
  ref: listRef,
231
354
  role: "toolbar",
232
355
  className: styles.List,
233
356
  "aria-label": ariaLabel,
234
357
  "aria-labelledby": ariaLabelledBy,
235
358
  "data-gap": gap,
236
- "data-size": size,
237
- "data-has-overflow": t7,
238
- children: [t9, t15]
359
+ children: [t10, t11]
239
360
  });
240
- $[21] = ariaLabel;
241
- $[22] = ariaLabelledBy;
242
- $[23] = gap;
243
- $[24] = size;
244
- $[25] = t15;
245
- $[26] = t7;
246
- $[27] = t9;
247
- $[28] = t16;
361
+ $[25] = ariaLabel;
362
+ $[26] = ariaLabelledBy;
363
+ $[27] = gap;
364
+ $[28] = t10;
365
+ $[29] = t11;
366
+ $[30] = t12;
248
367
  } else {
249
- t16 = $[28];
368
+ t12 = $[30];
250
369
  }
251
- let t17;
252
- if ($[29] !== flush || $[30] !== t16 || $[31] !== t6) {
253
- t17 = /*#__PURE__*/jsx("div", {
370
+ let t13;
371
+ if ($[31] !== flush || $[32] !== t12 || $[33] !== t9) {
372
+ t13 = /*#__PURE__*/jsx("div", {
254
373
  ref: navRef,
255
- className: t6,
374
+ className: t9,
256
375
  "data-flush": flush,
257
- children: t16
376
+ children: t12
258
377
  });
259
- $[29] = flush;
260
- $[30] = t16;
261
- $[31] = t6;
262
- $[32] = t17;
378
+ $[31] = flush;
379
+ $[32] = t12;
380
+ $[33] = t9;
381
+ $[34] = t13;
263
382
  } else {
264
- t17 = $[32];
383
+ t13 = $[34];
265
384
  }
266
- let t18;
267
- if ($[33] !== t17 || $[34] !== t5) {
268
- t18 = /*#__PURE__*/jsx(ActionBarContext.Provider, {
269
- value: t5,
270
- children: t17
385
+ let t14;
386
+ if ($[35] !== t13 || $[36] !== t8) {
387
+ t14 = /*#__PURE__*/jsx(ActionBarContext.Provider, {
388
+ value: t8,
389
+ children: t13
271
390
  });
272
- $[33] = t17;
273
- $[34] = t5;
274
- $[35] = t18;
391
+ $[35] = t13;
392
+ $[36] = t8;
393
+ $[37] = t14;
275
394
  } else {
276
- t18 = $[35];
395
+ t14 = $[37];
277
396
  }
278
- return t18;
397
+ return t14;
279
398
  };
280
- function useActionBarItem(ref, registryProps) {
281
- var _useContext;
282
- const $ = c(8);
283
- const isGroupOverflowing = (_useContext = useContext(ActionBarGroupContext)) === null || _useContext === void 0 ? void 0 : _useContext.isOverflowing;
284
- const isInGroup = isGroupOverflowing !== undefined;
399
+ function useWidth(ref) {
400
+ const $ = c(3);
401
+ const [width, setWidth] = useState(-1);
285
402
  let t0;
286
- if ($[0] !== isInGroup || $[1] !== ref) {
287
- t0 = onChange => {
288
- if (isInGroup) {
289
- return _temp4;
290
- }
291
- const observer = new IntersectionObserver(() => onChange(), {
292
- threshold: 1
293
- });
294
- if (ref.current) {
295
- observer.observe(ref.current);
296
- }
297
- return () => observer.disconnect();
298
- };
299
- $[0] = isInGroup;
300
- $[1] = ref;
301
- $[2] = t0;
302
- } else {
303
- t0 = $[2];
304
- }
305
- const subscribeIntersectionObserver = t0;
306
403
  let t1;
307
- if ($[3] !== ref) {
308
- t1 = () => ref.current ? ref.current.offsetTop > 0 : false;
309
- $[3] = ref;
310
- $[4] = t1;
311
- } else {
312
- t1 = $[4];
313
- }
314
- const isItemOverflowing = useSyncExternalStore(subscribeIntersectionObserver, t1, _temp5);
315
- const isOverflowing = isGroupOverflowing || isItemOverflowing;
316
- ActionBarItemsRegistry.useRegisterDescendant(isOverflowing ? registryProps : null);
317
- const t2 = isOverflowing ? "" : undefined;
318
- let t3;
319
- if ($[5] !== isOverflowing || $[6] !== t2) {
320
- t3 = {
321
- isOverflowing,
322
- dataOverflowingAttr: t2
404
+ if ($[0] !== ref) {
405
+ t0 = () => {
406
+ var _ref$current$getBound, _ref$current;
407
+ return setWidth((_ref$current$getBound = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.getBoundingClientRect().width) !== null && _ref$current$getBound !== void 0 ? _ref$current$getBound : -1);
323
408
  };
324
- $[5] = isOverflowing;
325
- $[6] = t2;
326
- $[7] = t3;
409
+ t1 = [ref];
410
+ $[0] = ref;
411
+ $[1] = t0;
412
+ $[2] = t1;
327
413
  } else {
328
- t3 = $[7];
414
+ t0 = $[1];
415
+ t1 = $[2];
329
416
  }
330
- return t3;
331
- }
332
- function _temp5() {
333
- return false;
417
+ useIsomorphicLayoutEffect(t0, t1);
418
+ return width;
334
419
  }
335
- function _temp4() {}
336
420
  const ActionBarIconButton = /*#__PURE__*/forwardRef(({
337
421
  disabled,
338
422
  onClick,
@@ -341,36 +425,44 @@ const ActionBarIconButton = /*#__PURE__*/forwardRef(({
341
425
  const ref = useRef(null);
342
426
  const mergedRef = useMergedRefs(ref, forwardedRef);
343
427
  const {
344
- size
428
+ size,
429
+ isVisibleChild
345
430
  } = React.useContext(ActionBarContext);
431
+ const {
432
+ groupId
433
+ } = React.useContext(ActionBarGroupContext);
434
+ const width = useWidth(ref);
346
435
  const {
347
436
  ['aria-label']: ariaLabel,
348
437
  icon
349
438
  } = props;
350
- const {
351
- dataOverflowingAttr
352
- } = useActionBarItem(ref, useMemo(() => ({
439
+ const registryProps = useMemo(() => ({
353
440
  type: 'action',
354
441
  label: ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : '',
355
442
  icon,
356
443
  disabled: !!disabled,
357
- onClick: onClick
358
- }), [ariaLabel, icon, disabled, onClick]));
444
+ onClick: onClick,
445
+ width,
446
+ groupId: groupId !== null && groupId !== void 0 ? groupId : undefined
447
+ }), [ariaLabel, icon, disabled, onClick, groupId, width]);
448
+ const id = ActionBarItemsRegistry.useRegisterDescendant(registryProps);
359
449
  const clickHandler = useCallback(event => {
360
450
  if (disabled) return;
361
451
  onClick === null || onClick === void 0 ? void 0 : onClick(event);
362
452
  }, [disabled, onClick]);
453
+ if (!isVisibleChild(id) || groupId && !isVisibleChild(groupId)) return null;
363
454
  return /*#__PURE__*/jsx(IconButton, {
364
455
  "aria-disabled": disabled,
365
456
  ref: mergedRef,
366
457
  size: size,
367
458
  onClick: clickHandler,
368
459
  ...props,
369
- variant: "invisible",
370
- "data-overflowing": dataOverflowingAttr
460
+ variant: "invisible"
371
461
  });
372
462
  });
373
- const ActionBarGroupContext = /*#__PURE__*/React.createContext(null);
463
+ const ActionBarGroupContext = /*#__PURE__*/React.createContext({
464
+ groupId: null
465
+ });
374
466
  const ActionBarGroup = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
375
467
  const $ = c(10);
376
468
  const {
@@ -378,39 +470,38 @@ const ActionBarGroup = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
378
470
  } = t0;
379
471
  const backupRef = useRef(null);
380
472
  const ref = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
473
+ const width = useWidth(ref);
381
474
  let t1;
382
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
475
+ if ($[0] !== width) {
383
476
  t1 = {
384
- type: "group"
477
+ type: "group",
478
+ width
385
479
  };
386
- $[0] = t1;
480
+ $[0] = width;
481
+ $[1] = t1;
387
482
  } else {
388
- t1 = $[0];
483
+ t1 = $[1];
389
484
  }
390
- const {
391
- dataOverflowingAttr,
392
- isOverflowing
393
- } = useActionBarItem(ref, t1);
485
+ const registryProps = t1;
486
+ const id = ActionBarItemsRegistry.useRegisterDescendant(registryProps);
394
487
  let t2;
395
- if ($[1] !== isOverflowing) {
488
+ if ($[2] !== id) {
396
489
  t2 = {
397
- isOverflowing
490
+ groupId: id
398
491
  };
399
- $[1] = isOverflowing;
400
- $[2] = t2;
492
+ $[2] = id;
493
+ $[3] = t2;
401
494
  } else {
402
- t2 = $[2];
495
+ t2 = $[3];
403
496
  }
404
497
  let t3;
405
- if ($[3] !== children || $[4] !== dataOverflowingAttr || $[5] !== ref) {
498
+ if ($[4] !== children || $[5] !== ref) {
406
499
  t3 = /*#__PURE__*/jsx("div", {
407
500
  className: styles.Group,
408
501
  ref: ref,
409
- "data-overflowing": dataOverflowingAttr,
410
502
  children: children
411
503
  });
412
- $[3] = children;
413
- $[4] = dataOverflowingAttr;
504
+ $[4] = children;
414
505
  $[5] = ref;
415
506
  $[6] = t3;
416
507
  } else {
@@ -464,12 +555,17 @@ const ActionBarMenu = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
464
555
  }
465
556
  const backupRef = useRef(null);
466
557
  const ref = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
558
+ const {
559
+ isVisibleChild
560
+ } = React.useContext(ActionBarContext);
467
561
  const [menuOpen, setMenuOpen] = useState(false);
562
+ const width = useWidth(ref);
468
563
  const t1 = overflowIcon ? overflowIcon : icon;
469
564
  let t2;
470
- if ($[7] !== ariaLabel || $[8] !== items || $[9] !== returnFocusRef || $[10] !== t1) {
565
+ if ($[7] !== ariaLabel || $[8] !== items || $[9] !== returnFocusRef || $[10] !== t1 || $[11] !== width) {
471
566
  t2 = {
472
567
  type: "menu",
568
+ width,
473
569
  label: ariaLabel,
474
570
  icon: t1,
475
571
  returnFocusRef,
@@ -479,26 +575,27 @@ const ActionBarMenu = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
479
575
  $[8] = items;
480
576
  $[9] = returnFocusRef;
481
577
  $[10] = t1;
482
- $[11] = t2;
578
+ $[11] = width;
579
+ $[12] = t2;
483
580
  } else {
484
- t2 = $[11];
581
+ t2 = $[12];
582
+ }
583
+ const registryProps = t2;
584
+ const id = ActionBarItemsRegistry.useRegisterDescendant(registryProps);
585
+ if (!isVisibleChild(id)) {
586
+ return null;
485
587
  }
486
- const {
487
- dataOverflowingAttr
488
- } = useActionBarItem(ref, t2);
489
588
  let t3;
490
- if ($[12] !== ariaLabel || $[13] !== dataOverflowingAttr || $[14] !== icon || $[15] !== props) {
589
+ if ($[13] !== ariaLabel || $[14] !== icon || $[15] !== props) {
491
590
  t3 = /*#__PURE__*/jsx(ActionMenu.Anchor, {
492
591
  children: /*#__PURE__*/jsx(IconButton, {
493
592
  variant: "invisible",
494
593
  "aria-label": ariaLabel,
495
594
  icon: icon,
496
- ...props,
497
- "data-overflowing": dataOverflowingAttr
595
+ ...props
498
596
  })
499
597
  });
500
- $[12] = ariaLabel;
501
- $[13] = dataOverflowingAttr;
598
+ $[13] = ariaLabel;
502
599
  $[14] = icon;
503
600
  $[15] = props;
504
601
  $[16] = t3;
@@ -517,7 +614,7 @@ const ActionBarMenu = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
517
614
  }
518
615
  let t5;
519
616
  if ($[19] !== items) {
520
- t5 = items.map(_temp6);
617
+ t5 = items.map(_temp4);
521
618
  $[19] = items;
522
619
  $[20] = t5;
523
620
  } else {
@@ -566,88 +663,68 @@ const ActionBarMenu = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
566
663
  const VerticalDivider = () => {
567
664
  const $ = c(3);
568
665
  const ref = useRef(null);
666
+ const {
667
+ isVisibleChild
668
+ } = React.useContext(ActionBarContext);
669
+ const width = useWidth(ref);
569
670
  let t0;
570
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
671
+ if ($[0] !== width) {
571
672
  t0 = {
572
- type: "divider"
673
+ type: "divider",
674
+ width
573
675
  };
574
- $[0] = t0;
676
+ $[0] = width;
677
+ $[1] = t0;
575
678
  } else {
576
- t0 = $[0];
679
+ t0 = $[1];
680
+ }
681
+ const registryProps = t0;
682
+ const id = ActionBarItemsRegistry.useRegisterDescendant(registryProps);
683
+ if (!isVisibleChild(id)) {
684
+ return null;
577
685
  }
578
- const {
579
- dataOverflowingAttr
580
- } = useActionBarItem(ref, t0);
581
686
  let t1;
582
- if ($[1] !== dataOverflowingAttr) {
687
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
583
688
  t1 = /*#__PURE__*/jsx("div", {
584
689
  ref: ref,
585
690
  "data-component": "ActionBar.VerticalDivider",
586
691
  "aria-hidden": "true",
587
- className: styles.Divider,
588
- "data-overflowing": dataOverflowingAttr
692
+ className: styles.Divider
589
693
  });
590
- $[1] = dataOverflowingAttr;
591
694
  $[2] = t1;
592
695
  } else {
593
696
  t1 = $[2];
594
697
  }
595
698
  return t1;
596
699
  };
597
- function _temp(entry) {
598
- return entry[1] !== null;
700
+ function _temp() {
701
+ return new Set();
599
702
  }
600
703
  function _temp2(item, index) {
601
704
  return renderMenuItem(item, index);
602
705
  }
603
706
  function _temp3(t0) {
604
- const [id, menuItem] = t0;
605
- if (menuItem.type === "divider") {
606
- return /*#__PURE__*/jsx(ActionList.Divider, {}, id);
607
- }
608
- if (menuItem.type === "action") {
707
+ const [key_0, childProps_0] = t0;
708
+ if (childProps_0.type === "action") {
609
709
  const {
610
- onClick,
611
- icon: Icon,
612
- label,
613
- disabled
614
- } = menuItem;
710
+ onClick: onClick_0,
711
+ icon: Icon_1,
712
+ label: label_1,
713
+ disabled: disabled_0
714
+ } = childProps_0;
615
715
  return /*#__PURE__*/jsxs(ActionList.Item, {
616
- onSelect: event => {
617
- typeof onClick === "function" && onClick(event);
716
+ onSelect: event_0 => {
717
+ typeof onClick_0 === "function" && onClick_0(event_0);
618
718
  },
619
- disabled: disabled,
719
+ disabled: disabled_0,
620
720
  children: [/*#__PURE__*/jsx(ActionList.LeadingVisual, {
621
- children: /*#__PURE__*/jsx(Icon, {})
622
- }), label]
623
- }, label);
624
- }
625
- if (menuItem.type === "menu") {
626
- const menuItems = menuItem.items;
627
- const {
628
- icon: Icon_0,
629
- label: label_0,
630
- returnFocusRef
631
- } = menuItem;
632
- return /*#__PURE__*/jsxs(ActionMenu, {
633
- children: [/*#__PURE__*/jsx(ActionMenu.Anchor, {
634
- children: /*#__PURE__*/jsxs(ActionList.Item, {
635
- children: [Icon_0 !== "none" ? /*#__PURE__*/jsx(ActionList.LeadingVisual, {
636
- children: /*#__PURE__*/jsx(Icon_0, {})
637
- }) : null, label_0]
638
- })
639
- }), /*#__PURE__*/jsx(ActionMenu.Overlay, {
640
- ...(returnFocusRef && {
641
- returnFocusRef
642
- }),
643
- children: /*#__PURE__*/jsx(ActionList, {
644
- children: menuItems.map(_temp2)
645
- })
646
- })]
647
- }, id);
721
+ children: /*#__PURE__*/jsx(Icon_1, {})
722
+ }), label_1]
723
+ }, key_0);
648
724
  }
725
+ return null;
649
726
  }
650
- function _temp6(item, index) {
727
+ function _temp4(item, index) {
651
728
  return renderMenuItem(item, index);
652
729
  }
653
730