@primer/react 0.0.0-20260617130545 → 0.0.0-20260617134638

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
@@ -1,17 +1,17 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260617130545
3
+ ## 0.0.0-20260617134638
4
4
 
5
5
  ### Minor Changes
6
6
 
7
+ - [#7994](https://github.com/primer/react/pull/7994) [`1026d40`](https://github.com/primer/react/commit/1026d4012f4e8960f5c3730f826b1eed77e00b2d) Thanks [@TylerJDev](https://github.com/TylerJDev)! - ActionList: Adds `tooltipDirection` prop to `ActionList.TrailingAction`
8
+
7
9
  - [#7867](https://github.com/primer/react/pull/7867) [`4ec4248`](https://github.com/primer/react/commit/4ec4248b9c1ae662b761385110f1fd7ad7480a2f) Thanks [@llastflowers](https://github.com/llastflowers)! - Add data-component attributes and associated tests for ActionMenu, AnchoredOverlay, Autocomplete, and NavList
8
10
 
9
11
  ### Patch Changes
10
12
 
11
13
  - [#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
12
14
 
13
- - [#7999](https://github.com/primer/react/pull/7999) [`19fe8bc`](https://github.com/primer/react/commit/19fe8bc3ec7949a4697cf8e3487e4c460e50e71c) 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.
14
-
15
15
  - [#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
16
16
 
17
17
  - Fake entry to force publishing
@@ -4,18 +4,20 @@ import { IconButton } from '../Button/IconButton.js';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5
 
6
6
  const GroupHeadingTrailingActionImpl = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
7
- const $ = c(13);
7
+ const $ = c(15);
8
8
  let icon;
9
9
  let label;
10
10
  let props;
11
11
  let t1;
12
12
  let t2;
13
+ let t3;
13
14
  if ($[0] !== t0) {
14
15
  ({
15
16
  as: t1,
16
17
  icon,
17
18
  label,
18
19
  href: t2,
20
+ tooltipDirection: t3,
19
21
  ...props
20
22
  } = t0);
21
23
  $[0] = t0;
@@ -24,40 +26,44 @@ const GroupHeadingTrailingActionImpl = /*#__PURE__*/forwardRef((t0, forwardedRef
24
26
  $[3] = props;
25
27
  $[4] = t1;
26
28
  $[5] = t2;
29
+ $[6] = t3;
27
30
  } else {
28
31
  icon = $[1];
29
32
  label = $[2];
30
33
  props = $[3];
31
34
  t1 = $[4];
32
35
  t2 = $[5];
36
+ t3 = $[6];
33
37
  }
34
38
  const as = t1 === undefined ? "button" : t1;
35
39
  const href = t2 === undefined ? null : t2;
36
- let t3;
37
- if ($[6] !== as || $[7] !== forwardedRef || $[8] !== href || $[9] !== icon || $[10] !== label || $[11] !== props) {
38
- t3 = /*#__PURE__*/jsx(IconButton, {
40
+ const tooltipDirection = t3 === undefined ? "w" : t3;
41
+ let t4;
42
+ if ($[7] !== as || $[8] !== forwardedRef || $[9] !== href || $[10] !== icon || $[11] !== label || $[12] !== props || $[13] !== tooltipDirection) {
43
+ t4 = /*#__PURE__*/jsx(IconButton, {
39
44
  as: as,
40
45
  "aria-label": label,
41
46
  icon: icon,
42
47
  variant: "invisible",
43
48
  size: "small",
44
- tooltipDirection: "w",
49
+ tooltipDirection: tooltipDirection,
45
50
  href: href,
46
51
  ref: forwardedRef,
47
52
  "data-component": "ActionList.GroupHeading.TrailingAction",
48
53
  ...props
49
54
  });
50
- $[6] = as;
51
- $[7] = forwardedRef;
52
- $[8] = href;
53
- $[9] = icon;
54
- $[10] = label;
55
- $[11] = props;
56
- $[12] = t3;
55
+ $[7] = as;
56
+ $[8] = forwardedRef;
57
+ $[9] = href;
58
+ $[10] = icon;
59
+ $[11] = label;
60
+ $[12] = props;
61
+ $[13] = tooltipDirection;
62
+ $[14] = t4;
57
63
  } else {
58
- t3 = $[12];
64
+ t4 = $[14];
59
65
  }
60
- return t3;
66
+ return t4;
61
67
  });
62
68
  GroupHeadingTrailingActionImpl.displayName = 'ActionList.GroupHeading.TrailingAction';
63
69
  GroupHeadingTrailingActionImpl.__SLOT__ = Symbol('ActionList.GroupHeading.TrailingAction');
@@ -1,4 +1,5 @@
1
1
  import type React from 'react';
2
+ import type { IconButtonProps } from '../Button/types';
2
3
  import type { ForwardRefComponent as PolymorphicForwardRefComponent } from '../utils/polymorphic';
3
4
  type ElementProps = {
4
5
  as?: 'button';
@@ -18,7 +19,7 @@ export type ActionListTrailingActionProps = ElementProps & {
18
19
  label: string;
19
20
  className?: string;
20
21
  style?: React.CSSProperties;
21
- };
22
+ } & Pick<IconButtonProps, 'tooltipDirection'>;
22
23
  export declare const TrailingAction: PolymorphicForwardRefComponent<"button" | "a", ActionListTrailingActionProps>;
23
24
  export {};
24
25
  //# sourceMappingURL=TrailingAction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TrailingAction.d.ts","sourceRoot":"","sources":["../../src/ActionList/TrailingAction.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAI/F,KAAK,YAAY,GACb;IACE,EAAE,CAAC,EAAE,QAAQ,CAAA;IACb,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,GACD;IACE,EAAE,EAAE,GAAG,CAAA;IACP,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,KA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 import classes from './ActionList.module.css.js';
7
7
  import { jsx } from 'react/jsx-runtime';
8
8
 
9
9
  const TrailingAction = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
10
- const $ = c(23);
10
+ const $ = c(25);
11
11
  let className;
12
12
  let icon;
13
13
  let label;
@@ -16,6 +16,7 @@ const TrailingAction = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
16
16
  let style;
17
17
  let t1;
18
18
  let t2;
19
+ let t3;
19
20
  if ($[0] !== t0) {
20
21
  ({
21
22
  as: t1,
@@ -25,6 +26,7 @@ const TrailingAction = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
25
26
  className,
26
27
  style,
27
28
  loading,
29
+ tooltipDirection: t3,
28
30
  ...props
29
31
  } = t0);
30
32
  $[0] = t0;
@@ -36,6 +38,7 @@ const TrailingAction = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
36
38
  $[6] = style;
37
39
  $[7] = t1;
38
40
  $[8] = t2;
41
+ $[9] = t3;
39
42
  } else {
40
43
  className = $[1];
41
44
  icon = $[2];
@@ -45,25 +48,27 @@ const TrailingAction = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
45
48
  style = $[6];
46
49
  t1 = $[7];
47
50
  t2 = $[8];
51
+ t3 = $[9];
48
52
  }
49
53
  const as = t1 === undefined ? "button" : t1;
50
54
  const href = t2 === undefined ? null : t2;
51
- let t3;
52
- if ($[9] !== className) {
53
- t3 = clsx(className, classes.TrailingAction);
54
- $[9] = className;
55
- $[10] = t3;
55
+ const tooltipDirection = t3 === undefined ? "w" : t3;
56
+ let t4;
57
+ if ($[10] !== className) {
58
+ t4 = clsx(className, classes.TrailingAction);
59
+ $[10] = className;
60
+ $[11] = t4;
56
61
  } else {
57
- t3 = $[10];
62
+ t4 = $[11];
58
63
  }
59
- let t4;
60
- if ($[11] !== as || $[12] !== forwardedRef || $[13] !== href || $[14] !== icon || $[15] !== label || $[16] !== loading || $[17] !== props) {
61
- t4 = icon ? /*#__PURE__*/jsx(IconButton, {
64
+ let t5;
65
+ if ($[12] !== as || $[13] !== forwardedRef || $[14] !== href || $[15] !== icon || $[16] !== label || $[17] !== loading || $[18] !== props || $[19] !== tooltipDirection) {
66
+ t5 = icon ? /*#__PURE__*/jsx(IconButton, {
62
67
  as: as,
63
68
  "aria-label": label,
64
69
  icon: icon,
65
70
  variant: "invisible",
66
- tooltipDirection: "w",
71
+ tooltipDirection: tooltipDirection,
67
72
  href: href,
68
73
  loading: loading,
69
74
  "data-loading": Boolean(loading),
@@ -82,33 +87,34 @@ const TrailingAction = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
82
87
  ...props,
83
88
  children: label
84
89
  });
85
- $[11] = as;
86
- $[12] = forwardedRef;
87
- $[13] = href;
88
- $[14] = icon;
89
- $[15] = label;
90
- $[16] = loading;
91
- $[17] = props;
92
- $[18] = t4;
90
+ $[12] = as;
91
+ $[13] = forwardedRef;
92
+ $[14] = href;
93
+ $[15] = icon;
94
+ $[16] = label;
95
+ $[17] = loading;
96
+ $[18] = props;
97
+ $[19] = tooltipDirection;
98
+ $[20] = t5;
93
99
  } else {
94
- t4 = $[18];
100
+ t5 = $[20];
95
101
  }
96
- let t5;
97
- if ($[19] !== style || $[20] !== t3 || $[21] !== t4) {
98
- t5 = /*#__PURE__*/jsx("span", {
99
- className: t3,
102
+ let t6;
103
+ if ($[21] !== style || $[22] !== t4 || $[23] !== t5) {
104
+ t6 = /*#__PURE__*/jsx("span", {
105
+ className: t4,
100
106
  "data-component": "ActionList.TrailingAction",
101
107
  style: style,
102
- children: t4
108
+ children: t5
103
109
  });
104
- $[19] = style;
105
- $[20] = t3;
106
- $[21] = t4;
107
- $[22] = t5;
110
+ $[21] = style;
111
+ $[22] = t4;
112
+ $[23] = t5;
113
+ $[24] = t6;
108
114
  } else {
109
- t5 = $[22];
115
+ t6 = $[24];
110
116
  }
111
- return t5;
117
+ return t6;
112
118
  });
113
119
  TrailingAction.__SLOT__ = Symbol('ActionList.TrailingAction');
114
120
 
@@ -1 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AG,GAAG,IAAI,0BAA0B,CAAC,EAAE,CAAC,CAAA;;YApBlG,EAAE,SAAS,KAAK,CAAC,WAAW;aANtB,EAAE;mBACI,OAAO;;aADb,EAAE;mBACI,OAAO;;;;;;;AA4BtB,wBAAiF;AAEjF;;GAEG;AACH,eAAO,MAAM,UAAU;WA5BpB,EAAE,SAAS,KAAK,CAAC,WAAW;aANtB,EAAE;mBACI,OAAO;;aADb,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,8 +1,7 @@
1
1
  import { c } from 'react-compiler-runtime';
2
2
  import { clsx } from 'clsx';
3
- import React, { useRef, useState } from 'react';
3
+ import React, { useRef, useCallback, useState, useMemo, useEffect } from 'react';
4
4
  import classes from './Breadcrumbs.module.css.js';
5
- import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
6
5
  import { ActionList } from '../ActionList/index.js';
7
6
  import { IconButton } from '../Button/IconButton.js';
8
7
  import { KebabHorizontalIcon } from '@primer/octicons-react';
@@ -207,350 +206,177 @@ const getValidChildren = children => {
207
206
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
208
207
  return React.Children.toArray(children).filter(child => /*#__PURE__*/React.isValidElement(child));
209
208
  };
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
209
+ function Breadcrumbs({
210
+ className,
211
+ children,
212
+ style,
213
+ overflow = 'wrap',
214
+ variant = 'normal'
226
215
  }) {
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;
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);
257
224
  }
258
225
  }
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;
226
+ }, []);
227
+ const hideRoot = !(overflow === 'menu-with-root');
228
+ const [effectiveHideRoot, setEffectiveHideRoot] = useState(hideRoot);
229
+ const childArray = useMemo(() => getValidChildren(children), [children]);
287
230
  const rootItem = childArray[0];
288
- const [childArrayWidths, setChildArrayWidths] = useState(_temp2);
289
- const [containerWidth, setContainerWidth] = useState(null);
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
290
240
  const [menuButtonWidth, setMenuButtonWidth] = useState(MENU_BUTTON_FALLBACK_WIDTH);
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
- }
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;
301
265
  };
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;
312
- }
313
- const containerElement = containerRef.current;
314
- if (!containerElement) {
315
- return;
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;
316
275
  }
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);
323
- }
324
- };
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);
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
+ }
347
293
  }
294
+ }
295
+ return {
296
+ visibleItems: currentVisibleItems,
297
+ menuItems: currentMenuItems,
298
+ effectiveHideRoot: eHideRoot
348
299
  };
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];
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);
374
309
  }
375
- t9 = t10;
376
- break bb0;
377
310
  }
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;
396
- } else {
397
- t11 = $[19];
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);
398
328
  }
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
- }
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
+ }));
481
336
  }
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, {
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];
361
+ } else {
362
+ // Show: [root breadcrumb, overflow menu, leaf breadcrumb]
363
+ return [rootElement, menuElement, ...visibleElements];
364
+ }
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, {
504
375
  children: finalChildren
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
376
+ })
545
377
  });
546
378
  }
547
- _temp4.displayName = "_temp4";
548
- function _temp3(child) {
549
- return child.offsetWidth;
550
- }
551
- function _temp2() {
552
- return [];
553
- }
379
+ Breadcrumbs.displayName = "Breadcrumbs";
554
380
  const ItemSeparator = () => {
555
381
  const $ = c(1);
556
382
  let t0;
@@ -534,6 +534,12 @@
534
534
  "type": "boolean",
535
535
  "defaultValue": "false",
536
536
  "description": "Whether the TrailingAction is in a loading state. When true, the TrailingAction will render a spinner instead of an icon. Only available when `as` is 'button'."
537
+ },
538
+ {
539
+ "name": "tooltipDirection",
540
+ "type": "'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw'",
541
+ "defaultValue": "'w'",
542
+ "description": "Direction of the tooltip shown when hovering over the TrailingAction. Only applies when `icon` is set."
537
543
  }
538
544
  ]
539
545
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260617130545",
4
+ "version": "0.0.0-20260617134638",
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",