@primer/react 38.29.0-rc.87f864386 → 38.29.0-rc.9dc2e199b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -25,8 +25,12 @@
25
25
 
26
26
  - [#7976](https://github.com/primer/react/pull/7976) [`1fac927`](https://github.com/primer/react/commit/1fac9270c497c1904acbb3eb60805630aab82a97) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - NavList: add a small gap between items for readability, including before expanded sub-navs, behind the `primer_react_action_list_item_gap` feature flag
27
27
 
28
+ - [#7999](https://github.com/primer/react/pull/7999) [`eada357`](https://github.com/primer/react/commit/eada3574ff15bfd7680602f34e19308ea766a972) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - Breadcrumbs: Improve rendering performance and refresh the overflow menu when breadcrumb content changes without changing the number of items.
29
+
28
30
  - [#7929](https://github.com/primer/react/pull/7929) [`48c34ca`](https://github.com/primer/react/commit/48c34ca452a5449b0ba901783edb169b6a1e1882) Thanks [@joshblack](https://github.com/joshblack)! - FilteredActionList: Make body skeleton widths stable for server rendering
29
31
 
32
+ - [#7985](https://github.com/primer/react/pull/7985) [`969c874`](https://github.com/primer/react/commit/969c8749b40a8f5075dd9ca91314cde5c41e3814) Thanks [@joshblack](https://github.com/joshblack)! - AnchoredOverlay: Render the popover target attribute correctly for popover anchors
33
+
30
34
  - [#7984](https://github.com/primer/react/pull/7984) [`06fdad4`](https://github.com/primer/react/commit/06fdad432ad274878b15921d3ee25a157c61e70d) Thanks [@joshblack](https://github.com/joshblack)! - CircleBadge, ActionList: Prevent internal props from rendering on DOM elements
31
35
 
32
36
  - [#7978](https://github.com/primer/react/pull/7978) [`e3f655c`](https://github.com/primer/react/commit/e3f655c6735ffd1bd105b8e7599e273bb1eee4d1) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - PageHeader.ParentLink: Forward unknown props (e.g. `to`) to the underlying element, enabling client-side routing with polymorphic `as`.
@@ -1 +1 @@
1
- {"version":3,"file":"AnchoredOverlay.d.ts","sourceRoot":"","sources":["../../src/AnchoredOverlay/AnchoredOverlay.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAmC,KAAK,GAAG,EAAC,MAAM,OAAO,CAAA;AAChE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,uBAAuB,CAAA;AAEhE,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,uBAAuB,CAAA;AAIhE,OAAO,KAAK,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAAC,KAAK,eAAe,EAAC,MAAM,6BAA6B,CAAA;AAChE,OAAO,EAAa,KAAK,eAAe,EAAC,MAAM,WAAW,CAAA;AAO1D,UAAU,8BAA8B;IACtC;;;OAGG;IACH,YAAY,EAAE,CAAC,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE,YAAY,GAAG,iBAAiB,CAAC,EAChG,KAAK,EAAE,CAAC,KACL,GAAG,CAAC,OAAO,CAAA;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAE/C;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,UAAU,iCAAiC;IACzC;;;OAGG;IACH,YAAY,EAAE,IAAI,CAAA;IAElB;;;OAGG;IACH,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAC9C;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,MAAM,iCAAiC,GACzC,OAAO,CAAC,8BAA8B,CAAC,GACvC,iCAAiC,CAAA;AAEr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EAAE,CAAC,EAAC,QAAQ,EAAC,EAAE;QAAC,QAAQ,EAAE,cAAc,CAAA;KAAC,KAAK,IAAI,CAAA;IACnE;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAA;IAC3C;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC/B;;;;;;;;;;OAUG;IACH,4BAA4B,CAAC,EAAE;QAAC,gBAAgB,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,eAAe,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAC,CAAA;CAC5G;AAED,MAAM,MAAM,oBAAoB,GAAG,wBAAwB,GACzD,CAAC,8BAA8B,GAAG,iCAAiC,CAAC,GACpE,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,MAAM,GAAG,cAAc,GAAG,iBAAiB,GAAG,mBAAmB,CAAC,CAAC,CAAA;AAS9G;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CA4TnF,CAAA"}
@@ -7,6 +7,7 @@ import { XIcon } from '@primer/octicons-react';
7
7
  import classes from './AnchoredOverlay.module.css.js';
8
8
  import { clsx } from 'clsx';
9
9
  import { widthMap } from '../Overlay/constants.js';
10
+ import { reactMajorVersion } from '../utils/environment.js';
10
11
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
11
12
  import { useFeatureFlag } from '../FeatureFlags/useFeatureFlag.js';
12
13
  import { useProvidedRefOrCreate } from '../hooks/useProvidedRefOrCreate.js';
@@ -138,6 +139,11 @@ const AnchoredOverlay = ({
138
139
  ...focusTrapSettings
139
140
  });
140
141
  const popoverId = useId();
142
+ const popoverTargetProps = shouldRenderAsPopover ? reactMajorVersion >= 19 ? {
143
+ popoverTarget: popoverId
144
+ } : {
145
+ popovertarget: popoverId
146
+ } : {};
141
147
  const id = popoverId.replaceAll(':', '_'); // popoverId can contain colons which are invalid in CSS custom property names, so we replace them with underscores
142
148
  const anchorName = `--anchored-overlay-anchor-${id}`;
143
149
 
@@ -234,9 +240,7 @@ const AnchoredOverlay = ({
234
240
  tabIndex: 0,
235
241
  onClick: onAnchorClick,
236
242
  onKeyDown: onAnchorKeyDown,
237
- ...(shouldRenderAsPopover ? {
238
- popoverTarget: popoverId
239
- } : {})
243
+ ...popoverTargetProps
240
244
  }), open ? /*#__PURE__*/jsxs(Overlay, {
241
245
  returnFocusRef: anchorRef,
242
246
  onClickOutside: onClickOutside,
@@ -1 +1 @@
1
- {"version":3,"file":"Breadcrumbs.d.ts","sourceRoot":"","sources":["../../src/Breadcrumbs/Breadcrumbs.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,EAAE,EAAC,MAAM,SAAS,CAAA;AAC/B,OAAO,KAA6E,MAAM,OAAO,CAAA;AAUjG,OAAO,EAAC,KAAK,gBAAgB,EAAkB,MAAM,6BAA6B,CAAA;AAElF,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,iBAAiB,CAAC;IACrD;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,gBAAgB,CAAA;IAC7C;;;;OAIG;IACH,OAAO,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC/B;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;CAC5B,CAAC,CAAA;AA8GF,iBAAS,WAAW,CAAC,EAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAiB,EAAE,OAAkB,EAAC,EAAE,gBAAgB,qBAwMzG;kBAxMQ,WAAW;;;AAoNpB,KAAK,0BAA0B,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,GAAG,GAAG,IAAI,gBAAgB,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,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAiB,EAAE,OAAkB,EAAC,EAAE,gBAAgB,qBA4IzG;kBA5IQ,WAAW;;;AAwJpB,KAAK,0BAA0B,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,GAAG,GAAG,IAAI,gBAAgB,CACpF,EAAE,EACF,GAAG,EACH;IACE,EAAE,CAAC,EAAE,EAAE,CAAA;IACP,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CACF,CAAA;AAuBD,MAAM,MAAM,oBAAoB,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,GAAG,GAAG,IAAI,0BAA0B,CAAC,EAAE,CAAC,CAAA;;YApBlG,EAAE,SAAS,KAAK,CAAC,WAAW;aANtB,EAAE;mBACI,OAAO;;;;;;;AA4BtB,wBAAiF;AAEjF;;GAEG;AACH,eAAO,MAAM,UAAU;WA5BpB,EAAE,SAAS,KAAK,CAAC,WAAW;aANtB,EAAE;mBACI,OAAO;;;;CAiCuD,CAAA;AAE7E;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,gBAAgB,CAAA;AAE9C;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,GAAG,GAAG,IAAI,oBAAoB,CAAC,EAAE,CAAC,CAAA"}
@@ -1,7 +1,8 @@
1
1
  import { c } from 'react-compiler-runtime';
2
2
  import { clsx } from 'clsx';
3
- import React, { useRef, useCallback, useState, useMemo, useEffect } from 'react';
3
+ import React, { useRef, useState } from 'react';
4
4
  import classes from './Breadcrumbs.module.css.js';
5
+ import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
5
6
  import { ActionList } from '../ActionList/index.js';
6
7
  import { IconButton } from '../Button/IconButton.js';
7
8
  import { KebabHorizontalIcon } from '@primer/octicons-react';
@@ -206,177 +207,350 @@ const getValidChildren = children => {
206
207
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
207
208
  return React.Children.toArray(children).filter(child => /*#__PURE__*/React.isValidElement(child));
208
209
  };
209
- function Breadcrumbs({
210
- className,
211
- children,
212
- style,
213
- overflow = 'wrap',
214
- variant = 'normal'
210
+ const MENU_BUTTON_FALLBACK_WIDTH = 32; // Design system small IconButton
211
+ const CONTAINER_FALLBACK_WIDTH = 800; // Used before the container has been measured
212
+
213
+ // Pure derivation of how many leading breadcrumb items collapse into the
214
+ // overflow menu, given the measured widths. Returns counts/flags (primitives)
215
+ // rather than element arrays so the render memo below only invalidates when the
216
+ // split actually changes, not on every sub-threshold resize. Kept outside the
217
+ // component so it has no hidden dependency on previous state and can be called
218
+ // directly during render.
219
+ function calculateOverflow({
220
+ availableWidth,
221
+ itemCount,
222
+ childArrayWidths,
223
+ menuButtonWidth,
224
+ overflow,
225
+ hideRoot
215
226
  }) {
216
- const containerRef = useRef(null);
217
- const measureMenuButton = useCallback(element => {
218
- if (element) {
219
- const iconButtonElement = element.querySelector('button[data-component="IconButton"]');
220
- if (iconButtonElement) {
221
- const measuredWidth = iconButtonElement.offsetWidth;
222
- // eslint-disable-next-line react-hooks/immutability
223
- setMenuButtonWidth(measuredWidth);
227
+ var _childArrayWidths$;
228
+ let eHideRoot = hideRoot;
229
+ const rootItemWidth = (_childArrayWidths$ = childArrayWidths[0]) !== null && _childArrayWidths$ !== void 0 ? _childArrayWidths$ : 0;
230
+ const NARROW_BREAKPOINT = 544;
231
+ const isNarrow = availableWidth < NARROW_BREAKPOINT;
232
+ let MIN_VISIBLE_ITEMS = 4;
233
+ if (!eHideRoot) {
234
+ MIN_VISIBLE_ITEMS = 3;
235
+ } else if (isNarrow && itemCount > 2) {
236
+ MIN_VISIBLE_ITEMS = 1;
237
+ }
238
+ const calculateVisibleItemsWidth = w => {
239
+ const widths = w.reduce((sum, width) => sum + width + 16, 0);
240
+ return !eHideRoot ? rootItemWidth + widths : widths;
241
+ };
242
+ let currentVisibleItemWidths = [...childArrayWidths];
243
+ let menuItemCount = 0;
244
+ if (availableWidth > 0 && currentVisibleItemWidths.length > 0) {
245
+ let visibleItemsWidthTotal = calculateVisibleItemsWidth(currentVisibleItemWidths);
246
+ while ((overflow === 'menu' || overflow === 'menu-with-root') && (visibleItemsWidthTotal > availableWidth || currentVisibleItemWidths.length > MIN_VISIBLE_ITEMS)) {
247
+ menuItemCount += 1;
248
+ currentVisibleItemWidths = currentVisibleItemWidths.slice(1);
249
+
250
+ // A menu button is now shown, so its width is always part of the total.
251
+ visibleItemsWidthTotal = calculateVisibleItemsWidth(currentVisibleItemWidths) + menuButtonWidth;
252
+ if (currentVisibleItemWidths.length === 1 && visibleItemsWidthTotal > availableWidth) {
253
+ eHideRoot = true;
254
+ break;
255
+ } else {
256
+ eHideRoot = hideRoot;
224
257
  }
225
258
  }
226
- }, []);
227
- const hideRoot = !(overflow === 'menu-with-root');
228
- const [effectiveHideRoot, setEffectiveHideRoot] = useState(hideRoot);
229
- const childArray = useMemo(() => getValidChildren(children), [children]);
259
+ }
260
+ return {
261
+ menuItemCount,
262
+ effectiveHideRoot: eHideRoot
263
+ };
264
+ }
265
+ function Breadcrumbs(t0) {
266
+ const $ = c(48);
267
+ const {
268
+ className,
269
+ children,
270
+ style,
271
+ overflow: t1,
272
+ variant: t2
273
+ } = t0;
274
+ const overflow = t1 === undefined ? "wrap" : t1;
275
+ const variant = t2 === undefined ? "normal" : t2;
276
+ const containerRef = useRef(null);
277
+ const hideRoot = !(overflow === "menu-with-root");
278
+ let t3;
279
+ if ($[0] !== children) {
280
+ t3 = getValidChildren(children);
281
+ $[0] = children;
282
+ $[1] = t3;
283
+ } else {
284
+ t3 = $[1];
285
+ }
286
+ const childArray = t3;
230
287
  const rootItem = childArray[0];
231
-
232
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
233
- const [visibleItems, setVisibleItems] = useState(() => childArray);
234
- const [childArrayWidths, setChildArrayWidths] = useState(() => []);
235
-
236
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
237
- const [menuItems, setMenuItems] = useState([]);
238
- const [rootItemWidth, setRootItemWidth] = useState(0);
239
- const MENU_BUTTON_FALLBACK_WIDTH = 32; // Design system small IconButton
288
+ const [childArrayWidths, setChildArrayWidths] = useState(_temp2);
289
+ const [containerWidth, setContainerWidth] = useState(null);
240
290
  const [menuButtonWidth, setMenuButtonWidth] = useState(MENU_BUTTON_FALLBACK_WIDTH);
241
- useEffect(() => {
242
- var _containerRef$current;
243
- const listElement = (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.querySelector('ol');
244
- if (listElement && listElement.children.length > 0 && listElement.children.length === childArray.length) {
245
- const listElementArray = Array.from(listElement.children);
246
- const widths = listElementArray.map(child => child.offsetWidth);
247
- setChildArrayWidths(widths);
248
- setRootItemWidth(listElementArray[0].offsetWidth);
249
- }
250
- }, [childArray]);
251
- const calculateOverflow = useCallback(availableWidth => {
252
- let eHideRoot = effectiveHideRoot;
253
- const MENU_BUTTON_WIDTH = menuButtonWidth;
254
- const NARROW_BREAKPOINT = 544;
255
- const isNarrow = availableWidth < NARROW_BREAKPOINT;
256
- let MIN_VISIBLE_ITEMS = 4;
257
- if (!eHideRoot) {
258
- MIN_VISIBLE_ITEMS = 3;
259
- } else if (isNarrow && childArray.length > 2) {
260
- MIN_VISIBLE_ITEMS = 1;
261
- }
262
- const calculateVisibleItemsWidth = w => {
263
- const widths_0 = w.reduce((sum, width) => sum + width + 16, 0);
264
- return !eHideRoot ? rootItemWidth + widths_0 : widths_0;
291
+ let t4;
292
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
293
+ t4 = element => {
294
+ if (element) {
295
+ const iconButtonElement = element.querySelector("button[data-component=\"IconButton\"]");
296
+ if (iconButtonElement) {
297
+ const measuredWidth = iconButtonElement.offsetWidth;
298
+ setMenuButtonWidth(prev => prev === measuredWidth ? prev : measuredWidth);
299
+ }
300
+ }
265
301
  };
266
- let currentVisibleItems = [...childArray];
267
- let currentVisibleItemWidths = [...childArrayWidths];
268
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
269
- let currentMenuItems = [];
270
- let currentMenuItemsWidths = [];
271
- if (availableWidth > 0 && currentVisibleItemWidths.length > 0) {
272
- let visibleItemsWidthTotal = calculateVisibleItemsWidth(currentVisibleItemWidths);
273
- if (currentMenuItems.length > 0) {
274
- visibleItemsWidthTotal += MENU_BUTTON_WIDTH;
302
+ $[2] = t4;
303
+ } else {
304
+ t4 = $[2];
305
+ }
306
+ const measureMenuButton = t4;
307
+ let t5;
308
+ if ($[3] !== childArray.length || $[4] !== overflow) {
309
+ t5 = () => {
310
+ if (overflow === "wrap") {
311
+ return;
275
312
  }
276
- while ((overflow === 'menu' || overflow === 'menu-with-root') && (visibleItemsWidthTotal > availableWidth || currentVisibleItems.length > MIN_VISIBLE_ITEMS)) {
277
- const itemToHide = currentVisibleItems[0];
278
- const itemToHideWidth = currentVisibleItemWidths[0];
279
- currentMenuItems = [...currentMenuItems, itemToHide];
280
- currentMenuItemsWidths = [...currentMenuItemsWidths, itemToHideWidth];
281
- currentVisibleItems = currentVisibleItems.slice(1);
282
- currentVisibleItemWidths = currentVisibleItemWidths.slice(1);
283
- visibleItemsWidthTotal = calculateVisibleItemsWidth(currentVisibleItemWidths);
284
- if (currentMenuItems.length > 0) {
285
- visibleItemsWidthTotal += MENU_BUTTON_WIDTH;
286
- }
287
- if (currentVisibleItems.length === 1 && visibleItemsWidthTotal > availableWidth) {
288
- eHideRoot = true;
289
- break;
290
- } else {
291
- eHideRoot = hideRoot;
292
- }
313
+ const containerElement = containerRef.current;
314
+ if (!containerElement) {
315
+ return;
316
+ }
317
+ const measuredContainerWidth = containerElement.offsetWidth;
318
+ setContainerWidth(prev_0 => prev_0 === measuredContainerWidth ? prev_0 : measuredContainerWidth);
319
+ const listElement = containerElement.querySelector("ol");
320
+ if (listElement && listElement.children.length > 0 && listElement.children.length === childArray.length) {
321
+ const widths = Array.from(listElement.children).map(_temp3);
322
+ setChildArrayWidths(widths);
293
323
  }
294
- }
295
- return {
296
- visibleItems: currentVisibleItems,
297
- menuItems: currentMenuItems,
298
- effectiveHideRoot: eHideRoot
299
324
  };
300
- }, [childArray, childArrayWidths, effectiveHideRoot, hideRoot, overflow, rootItemWidth, menuButtonWidth]);
301
- const handleResize = useCallback(entries => {
302
- if (entries[0]) {
303
- const containerWidth = entries[0].contentRect.width;
304
- const result = calculateOverflow(containerWidth);
305
- if (visibleItems.length !== result.visibleItems.length && menuItems.length !== result.menuItems.length || result.effectiveHideRoot !== effectiveHideRoot) {
306
- setVisibleItems(result.visibleItems);
307
- setMenuItems(result.menuItems);
308
- setEffectiveHideRoot(result.effectiveHideRoot);
325
+ $[3] = childArray.length;
326
+ $[4] = overflow;
327
+ $[5] = t5;
328
+ } else {
329
+ t5 = $[5];
330
+ }
331
+ let t6;
332
+ if ($[6] !== childArray || $[7] !== overflow) {
333
+ t6 = [childArray, overflow];
334
+ $[6] = childArray;
335
+ $[7] = overflow;
336
+ $[8] = t6;
337
+ } else {
338
+ t6 = $[8];
339
+ }
340
+ useIsomorphicLayoutEffect(t5, t6);
341
+ let t7;
342
+ if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
343
+ t7 = entries => {
344
+ if (entries[0]) {
345
+ const width = Math.round(entries[0].contentRect.width);
346
+ setContainerWidth(prev_1 => prev_1 === width ? prev_1 : width);
309
347
  }
348
+ };
349
+ $[9] = t7;
350
+ } else {
351
+ t7 = $[9];
352
+ }
353
+ let t8;
354
+ if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
355
+ t8 = [];
356
+ $[10] = t8;
357
+ } else {
358
+ t8 = $[10];
359
+ }
360
+ useResizeObserver(t7, containerRef, t8, overflow !== "wrap");
361
+ let t9;
362
+ bb0: {
363
+ if (overflow === "wrap" || childArrayWidths.length !== childArray.length) {
364
+ let t10;
365
+ if ($[11] !== hideRoot) {
366
+ t10 = {
367
+ menuItemCount: 0,
368
+ effectiveHideRoot: hideRoot
369
+ };
370
+ $[11] = hideRoot;
371
+ $[12] = t10;
372
+ } else {
373
+ t10 = $[12];
374
+ }
375
+ t9 = t10;
376
+ break bb0;
310
377
  }
311
- }, [calculateOverflow, effectiveHideRoot, menuItems.length, visibleItems.length]);
312
- useResizeObserver(handleResize, containerRef);
313
- useEffect(() => {
314
- // eslint-disable-next-line react-you-might-not-need-an-effect/no-event-handler
315
- if ((overflow === 'menu' || overflow === 'menu-with-root') && childArray.length > 5 && menuItems.length === 0) {
316
- var _containerRef$current2;
317
- const containerWidth_0 = ((_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.offsetWidth) || 800;
318
- const result_0 = calculateOverflow(containerWidth_0);
319
-
320
- // eslint-disable-next-line react-you-might-not-need-an-effect/no-adjust-state-on-prop-change, react-you-might-not-need-an-effect/no-chain-state-updates
321
- setVisibleItems(result_0.visibleItems);
322
-
323
- // eslint-disable-next-line react-you-might-not-need-an-effect/no-adjust-state-on-prop-change, react-you-might-not-need-an-effect/no-chain-state-updates
324
- setMenuItems(result_0.menuItems);
325
-
326
- // eslint-disable-next-line react-you-might-not-need-an-effect/no-chain-state-updates, react-you-might-not-need-an-effect/no-derived-state
327
- setEffectiveHideRoot(result_0.effectiveHideRoot);
328
- }
329
- }, [overflow, childArray, calculateOverflow, menuItems.length]);
330
- const finalChildren = React.useMemo(() => {
331
- if (overflow === 'wrap' || menuItems.length === 0) {
332
- return React.Children.map(children, child_0 => /*#__PURE__*/jsx("li", {
333
- className: classes.ItemWrapper,
334
- children: child_0
335
- }));
336
- }
337
- let effectiveMenuItems = [...menuItems];
338
- // In 'menu-with-root' mode, include the root item inside the menu even if it's visible in the breadcrumbs
339
- if (!effectiveHideRoot) {
340
- effectiveMenuItems = [...menuItems.slice(1)];
341
- }
342
- const menuElement = /*#__PURE__*/jsxs("li", {
343
- className: classes.BreadcrumbsItem,
344
- children: [/*#__PURE__*/jsx(BreadcrumbsMenuItem, {
345
- ref: measureMenuButton,
346
- items: effectiveMenuItems,
347
- "aria-label": `${effectiveMenuItems.length} more breadcrumb items`
348
- }), /*#__PURE__*/jsx(ItemSeparator, {})]
349
- }, "breadcrumbs-menu");
350
- const visibleElements = visibleItems.map((child_1, index) => /*#__PURE__*/jsxs("li", {
351
- className: classes.BreadcrumbsItem,
352
- children: [child_1, /*#__PURE__*/jsx(ItemSeparator, {})]
353
- }, `visible + ${index}`));
354
- const rootElement = /*#__PURE__*/jsxs("li", {
355
- className: classes.BreadcrumbsItem,
356
- children: [rootItem, /*#__PURE__*/jsx(ItemSeparator, {})]
357
- }, `rootElement`);
358
- if (effectiveHideRoot) {
359
- // Show: [overflow menu, leaf breadcrumb]
360
- return [menuElement, ...visibleElements];
378
+ const t10 = containerWidth !== null && containerWidth !== void 0 ? containerWidth : CONTAINER_FALLBACK_WIDTH;
379
+ let t11;
380
+ if ($[13] !== childArray.length || $[14] !== childArrayWidths || $[15] !== hideRoot || $[16] !== menuButtonWidth || $[17] !== overflow || $[18] !== t10) {
381
+ t11 = calculateOverflow({
382
+ availableWidth: t10,
383
+ itemCount: childArray.length,
384
+ childArrayWidths,
385
+ menuButtonWidth,
386
+ overflow,
387
+ hideRoot
388
+ });
389
+ $[13] = childArray.length;
390
+ $[14] = childArrayWidths;
391
+ $[15] = hideRoot;
392
+ $[16] = menuButtonWidth;
393
+ $[17] = overflow;
394
+ $[18] = t10;
395
+ $[19] = t11;
361
396
  } else {
362
- // Show: [root breadcrumb, overflow menu, leaf breadcrumb]
363
- return [rootElement, menuElement, ...visibleElements];
397
+ t11 = $[19];
364
398
  }
365
- }, [overflow, menuItems, effectiveHideRoot, measureMenuButton, visibleItems, rootItem, children]);
366
- return /*#__PURE__*/jsx("nav", {
367
- className: clsx(className, classes.BreadcrumbsBase),
368
- "aria-label": "Breadcrumbs",
369
- style: style,
370
- ref: containerRef,
371
- "data-overflow": overflow,
372
- "data-variant": variant,
373
- "data-component": "Breadcrumbs",
374
- children: /*#__PURE__*/jsx(BreadcrumbsList, {
399
+ t9 = t11;
400
+ }
401
+ const {
402
+ menuItemCount,
403
+ effectiveHideRoot
404
+ } = t9;
405
+ let t10;
406
+ if ($[20] !== childArray || $[21] !== children || $[22] !== effectiveHideRoot || $[23] !== menuItemCount || $[24] !== overflow || $[25] !== rootItem) {
407
+ bb1: {
408
+ if (overflow === "wrap" || menuItemCount === 0) {
409
+ let t11;
410
+ if ($[27] !== children) {
411
+ t11 = React.Children.map(children, _temp4);
412
+ $[27] = children;
413
+ $[28] = t11;
414
+ } else {
415
+ t11 = $[28];
416
+ }
417
+ t10 = t11;
418
+ break bb1;
419
+ }
420
+ const menuItems = childArray.slice(0, menuItemCount);
421
+ const visibleItems = childArray.slice(menuItemCount);
422
+ const effectiveMenuItems = effectiveHideRoot ? menuItems : menuItems.slice(1);
423
+ const t11 = `${effectiveMenuItems.length} more breadcrumb items`;
424
+ let t12;
425
+ if ($[29] !== effectiveMenuItems || $[30] !== t11) {
426
+ t12 = /*#__PURE__*/jsx(BreadcrumbsMenuItem, {
427
+ ref: measureMenuButton,
428
+ items: effectiveMenuItems,
429
+ "aria-label": t11
430
+ });
431
+ $[29] = effectiveMenuItems;
432
+ $[30] = t11;
433
+ $[31] = t12;
434
+ } else {
435
+ t12 = $[31];
436
+ }
437
+ let t13;
438
+ if ($[32] === Symbol.for("react.memo_cache_sentinel")) {
439
+ t13 = /*#__PURE__*/jsx(ItemSeparator, {});
440
+ $[32] = t13;
441
+ } else {
442
+ t13 = $[32];
443
+ }
444
+ let t14;
445
+ if ($[33] !== t12) {
446
+ t14 = /*#__PURE__*/jsxs("li", {
447
+ className: classes.BreadcrumbsItem,
448
+ children: [t12, t13]
449
+ }, "breadcrumbs-menu");
450
+ $[33] = t12;
451
+ $[34] = t14;
452
+ } else {
453
+ t14 = $[34];
454
+ }
455
+ const menuElement = t14;
456
+ const visibleElements = visibleItems.map(_temp5);
457
+ let t15;
458
+ if ($[35] === Symbol.for("react.memo_cache_sentinel")) {
459
+ t15 = /*#__PURE__*/jsx(ItemSeparator, {});
460
+ $[35] = t15;
461
+ } else {
462
+ t15 = $[35];
463
+ }
464
+ let t16;
465
+ if ($[36] !== rootItem) {
466
+ t16 = /*#__PURE__*/jsxs("li", {
467
+ className: classes.BreadcrumbsItem,
468
+ children: [rootItem, t15]
469
+ }, "rootElement");
470
+ $[36] = rootItem;
471
+ $[37] = t16;
472
+ } else {
473
+ t16 = $[37];
474
+ }
475
+ const rootElement = t16;
476
+ if (effectiveHideRoot) {
477
+ t10 = [menuElement, ...visibleElements];
478
+ } else {
479
+ t10 = [rootElement, menuElement, ...visibleElements];
480
+ }
481
+ }
482
+ $[20] = childArray;
483
+ $[21] = children;
484
+ $[22] = effectiveHideRoot;
485
+ $[23] = menuItemCount;
486
+ $[24] = overflow;
487
+ $[25] = rootItem;
488
+ $[26] = t10;
489
+ } else {
490
+ t10 = $[26];
491
+ }
492
+ const finalChildren = t10;
493
+ let t11;
494
+ if ($[38] !== className) {
495
+ t11 = clsx(className, classes.BreadcrumbsBase);
496
+ $[38] = className;
497
+ $[39] = t11;
498
+ } else {
499
+ t11 = $[39];
500
+ }
501
+ let t12;
502
+ if ($[40] !== finalChildren) {
503
+ t12 = /*#__PURE__*/jsx(BreadcrumbsList, {
375
504
  children: finalChildren
376
- })
505
+ });
506
+ $[40] = finalChildren;
507
+ $[41] = t12;
508
+ } else {
509
+ t12 = $[41];
510
+ }
511
+ let t13;
512
+ if ($[42] !== overflow || $[43] !== style || $[44] !== t11 || $[45] !== t12 || $[46] !== variant) {
513
+ t13 = /*#__PURE__*/jsx("nav", {
514
+ className: t11,
515
+ "aria-label": "Breadcrumbs",
516
+ style: style,
517
+ ref: containerRef,
518
+ "data-overflow": overflow,
519
+ "data-variant": variant,
520
+ "data-component": "Breadcrumbs",
521
+ children: t12
522
+ });
523
+ $[42] = overflow;
524
+ $[43] = style;
525
+ $[44] = t11;
526
+ $[45] = t12;
527
+ $[46] = variant;
528
+ $[47] = t13;
529
+ } else {
530
+ t13 = $[47];
531
+ }
532
+ return t13;
533
+ }
534
+ function _temp5(child_1, index) {
535
+ return /*#__PURE__*/jsxs("li", {
536
+ className: classes.BreadcrumbsItem,
537
+ children: [child_1, /*#__PURE__*/jsx(ItemSeparator, {})]
538
+ }, `visible + ${index}`);
539
+ }
540
+ _temp5.displayName = "_temp5";
541
+ function _temp4(child_0) {
542
+ return /*#__PURE__*/jsx("li", {
543
+ className: classes.ItemWrapper,
544
+ children: child_0
377
545
  });
378
546
  }
379
- Breadcrumbs.displayName = "Breadcrumbs";
547
+ _temp4.displayName = "_temp4";
548
+ function _temp3(child) {
549
+ return child.offsetWidth;
550
+ }
551
+ function _temp2() {
552
+ return [];
553
+ }
380
554
  const ItemSeparator = () => {
381
555
  const $ = c(1);
382
556
  let t0;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "38.29.0-rc.87f864386",
4
+ "version": "38.29.0-rc.9dc2e199b",
5
5
  "description": "An implementation of GitHub's Primer Design System using React",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",