@primer/react 0.0.0-20260223174351 → 0.0.0-20260223174400

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,5 +1,5 @@
1
- import './PageLayout-3444a142.css';
1
+ import './PageLayout-06f4c069.css';
2
2
 
3
- var classes = {"paneMaxWidthDiffBreakpoint":"1280","paneMaxWidthDiffDefault":"511","sidebarMaxWidthDiffDefault":"256","paneMaxWidthDiffWide":"959","PageLayoutRoot":"prc-PageLayout-PageLayoutRoot--KH-d","PageLayoutWrapper":"prc-PageLayout-PageLayoutWrapper-2BhU2","PageLayoutContent":"prc-PageLayout-PageLayoutContent-BneH9","HorizontalDivider":"prc-PageLayout-HorizontalDivider-JLVqp","VerticalDivider":"prc-PageLayout-VerticalDivider-9QRmK","Header":"prc-PageLayout-Header-0of-R","HeaderContent":"prc-PageLayout-HeaderContent-gdFfN","HeaderHorizontalDivider":"prc-PageLayout-HeaderHorizontalDivider-odAHl","ContentWrapper":"prc-PageLayout-ContentWrapper-gR9eG","Content":"prc-PageLayout-Content-xWL-A","PaneWrapper":"prc-PageLayout-PaneWrapper-pHPop","PaneVerticalDivider":"prc-PageLayout-PaneVerticalDivider-le57g","Pane":"prc-PageLayout-Pane-AyzHK","PaneHorizontalDivider":"prc-PageLayout-PaneHorizontalDivider-9tbnE","FooterWrapper":"prc-PageLayout-FooterWrapper-9cB8y","FooterHorizontalDivider":"prc-PageLayout-FooterHorizontalDivider-W-RaS","FooterContent":"prc-PageLayout-FooterContent-HUS0V","DraggableHandle":"prc-PageLayout-DraggableHandle-9s6B4","SidebarWrapper":"prc-PageLayout-SidebarWrapper-kLG4B","Sidebar":"prc-PageLayout-Sidebar-iciWg","SidebarVerticalDivider":"prc-PageLayout-SidebarVerticalDivider-0Rl0V"};
3
+ var classes = {"paneMaxWidthDiffBreakpoint":"1280","paneMaxWidthDiffDefault":"511","sidebarMaxWidthDiffDefault":"256","PageLayoutRoot":"prc-PageLayout-PageLayoutRoot--KH-d","PageLayoutWrapper":"prc-PageLayout-PageLayoutWrapper-2BhU2","PageLayoutContent":"prc-PageLayout-PageLayoutContent-BneH9","HorizontalDivider":"prc-PageLayout-HorizontalDivider-JLVqp","VerticalDivider":"prc-PageLayout-VerticalDivider-9QRmK","Header":"prc-PageLayout-Header-0of-R","HeaderContent":"prc-PageLayout-HeaderContent-gdFfN","HeaderHorizontalDivider":"prc-PageLayout-HeaderHorizontalDivider-odAHl","ContentWrapper":"prc-PageLayout-ContentWrapper-gR9eG","Content":"prc-PageLayout-Content-xWL-A","PaneWrapper":"prc-PageLayout-PaneWrapper-pHPop","PaneVerticalDivider":"prc-PageLayout-PaneVerticalDivider-le57g","Pane":"prc-PageLayout-Pane-AyzHK","PaneHorizontalDivider":"prc-PageLayout-PaneHorizontalDivider-9tbnE","FooterWrapper":"prc-PageLayout-FooterWrapper-9cB8y","FooterHorizontalDivider":"prc-PageLayout-FooterHorizontalDivider-W-RaS","FooterContent":"prc-PageLayout-FooterContent-HUS0V","DraggableHandle":"prc-PageLayout-DraggableHandle-9s6B4","SidebarWrapper":"prc-PageLayout-SidebarWrapper-kLG4B","Sidebar":"prc-PageLayout-Sidebar-iciWg","SidebarVerticalDivider":"prc-PageLayout-SidebarVerticalDivider-0Rl0V"};
4
4
 
5
5
  export { classes as default };
@@ -74,11 +74,12 @@ export declare const isCustomWidthOptions: (width: PaneWidthValue) => width is C
74
74
  export declare const isPaneWidth: (width: PaneWidthValue) => width is PaneWidth;
75
75
  export declare const getDefaultPaneWidth: (w: PaneWidthValue) => number;
76
76
  /**
77
- * Derives the --pane-max-width-diff value from viewport width alone.
78
- * Avoids the expensive getComputedStyle call that forces a synchronous layout recalc.
79
- * The CSS only defines two breakpoint-dependent values, so a simple width check is equivalent.
77
+ * Gets the max-width-diff CSS variable value from a pane element.
78
+ * For sidebars, reads --sidebar-max-width-diff (constant across viewports).
79
+ * For panes, reads --pane-max-width-diff (changes at 1280px breakpoint).
80
+ * Note: This calls getComputedStyle which forces layout - cache the result when possible.
80
81
  */
81
- export declare function getMaxWidthDiffFromViewport(): number;
82
+ export declare function getPaneMaxWidthDiff(paneElement: HTMLElement | null, isSidebar?: boolean): number;
82
83
  export declare const updateAriaValues: (handle: HTMLElement | null, values: {
83
84
  current?: number;
84
85
  min?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"usePaneWidth.d.ts","sourceRoot":"","sources":["../../src/PageLayout/usePaneWidth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAiC,MAAM,OAAO,CAAA;AAQrD,KAAK,WAAW,GAAG,GAAG,MAAM,IAAI,CAAA;AAEhC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,GAAG,EAAE,WAAW,CAAA;IAChB,OAAO,EAAE,WAAW,CAAA;IACpB,GAAG,EAAE,WAAW,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;AAEpD;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,kBAAkB,CAAA;AAE3D,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,cAAc,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,OAAO,CAAA;IAClB,uFAAuF;IACvF,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAA;IAC/C,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAA;IACjD,iBAAiB,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAA;IACzD;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,oFAAoF;IACpF,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACrC,8HAA8H;IAC9H,YAAY,CAAC,EAAE,MA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,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAC,SASvD,CAAA;AA8BD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,QAAQ,EACR,SAAS,EACT,eAAe,EACf,OAAO,EACP,SAAS,EACT,iBAAiB,EACjB,mBAA2B,EAC3B,WAAW,EACX,YAAY,EAAE,eAAe,GAC9B,EAAE,mBAAmB,GAAG,kBAAkB,CAuQ1C"}
@@ -1,6 +1,5 @@
1
1
  import { c } from 'react-compiler-runtime';
2
2
  import React, { startTransition } from 'react';
3
- import { canUseDOM } from '../utils/environment.js';
4
3
  import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
5
4
  import classes from './PageLayout.module.css.js';
6
5
 
@@ -28,9 +27,6 @@ const DEFAULT_MAX_WIDTH_DIFF = Number(classes.paneMaxWidthDiffDefault);
28
27
  */
29
28
  const DEFAULT_SIDEBAR_MAX_WIDTH_DIFF = Number(classes.sidebarMaxWidthDiffDefault);
30
29
 
31
- // Value for --pane-max-width-diff at/above the wide breakpoint.
32
- const WIDE_MAX_WIDTH_DIFF = Number(classes.paneMaxWidthDiffWide);
33
-
34
30
  // --pane-max-width-diff changes at this breakpoint in PageLayout.module.css.
35
31
  const DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT = Number(classes.paneMaxWidthDiffBreakpoint);
36
32
  /**
@@ -71,13 +67,17 @@ const getDefaultPaneWidth = w => {
71
67
  };
72
68
 
73
69
  /**
74
- * Derives the --pane-max-width-diff value from viewport width alone.
75
- * Avoids the expensive getComputedStyle call that forces a synchronous layout recalc.
76
- * The CSS only defines two breakpoint-dependent values, so a simple width check is equivalent.
70
+ * Gets the max-width-diff CSS variable value from a pane element.
71
+ * For sidebars, reads --sidebar-max-width-diff (constant across viewports).
72
+ * For panes, reads --pane-max-width-diff (changes at 1280px breakpoint).
73
+ * Note: This calls getComputedStyle which forces layout - cache the result when possible.
77
74
  */
78
- function getMaxWidthDiffFromViewport() {
79
- if (!canUseDOM) return DEFAULT_MAX_WIDTH_DIFF;
80
- return window.innerWidth >= DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT ? WIDE_MAX_WIDTH_DIFF : DEFAULT_MAX_WIDTH_DIFF;
75
+ function getPaneMaxWidthDiff(paneElement, isSidebar = false) {
76
+ const defaultValue = isSidebar ? DEFAULT_SIDEBAR_MAX_WIDTH_DIFF : DEFAULT_MAX_WIDTH_DIFF;
77
+ const cssVar = isSidebar ? '--sidebar-max-width-diff' : '--pane-max-width-diff';
78
+ if (!paneElement) return defaultValue;
79
+ const value = parseInt(getComputedStyle(paneElement).getPropertyValue(cssVar), 10);
80
+ return value > 0 ? value : defaultValue;
81
81
  }
82
82
 
83
83
  // Helper to update ARIA slider attributes via direct DOM manipulation
@@ -321,7 +321,7 @@ function usePaneWidth(t0) {
321
321
  const crossedBreakpoint = lastViewportWidth < DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT && currentViewportWidth >= DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT || lastViewportWidth >= DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT && currentViewportWidth < DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT;
322
322
  lastViewportWidth = currentViewportWidth;
323
323
  if (crossedBreakpoint) {
324
- maxWidthDiffRef.current = getMaxWidthDiffFromViewport();
324
+ maxWidthDiffRef.current = getPaneMaxWidthDiff(paneRef.current, constrainToViewport);
325
325
  }
326
326
  const actualMax = getMaxPaneWidthRef.current();
327
327
  (_paneRef$current = paneRef.current) === null || _paneRef$current === void 0 ? void 0 : _paneRef$current.style.setProperty("--pane-max-width", `${actualMax}px`);
@@ -342,7 +342,7 @@ function usePaneWidth(t0) {
342
342
  }
343
343
  });
344
344
  };
345
- maxWidthDiffRef.current = getMaxWidthDiffFromViewport();
345
+ maxWidthDiffRef.current = getPaneMaxWidthDiff(paneRef.current, constrainToViewport);
346
346
  const initialMax = getMaxPaneWidthRef.current();
347
347
  setMaxPaneWidth(initialMax);
348
348
  (_paneRef$current3 = paneRef.current) === null || _paneRef$current3 === void 0 ? void 0 : _paneRef$current3.style.setProperty("--pane-max-width", `${initialMax}px`);
@@ -453,4 +453,4 @@ function usePaneWidth(t0) {
453
453
  return t14;
454
454
  }
455
455
 
456
- export { ARROW_KEY_STEP, DEFAULT_MAX_WIDTH_DIFF, DEFAULT_SIDEBAR_MAX_WIDTH_DIFF, SSR_DEFAULT_MAX_WIDTH, defaultPaneWidth, getDefaultPaneWidth, getMaxWidthDiffFromViewport, isCustomWidthOptions, isPaneWidth, updateAriaValues, usePaneWidth };
456
+ export { ARROW_KEY_STEP, DEFAULT_MAX_WIDTH_DIFF, DEFAULT_SIDEBAR_MAX_WIDTH_DIFF, SSR_DEFAULT_MAX_WIDTH, defaultPaneWidth, getDefaultPaneWidth, getPaneMaxWidthDiff, isCustomWidthOptions, isPaneWidth, updateAriaValues, usePaneWidth };
@@ -5,6 +5,20 @@ export declare function useRovingTabIndex({ containerRef, mouseDownRef, }: {
5
5
  }): void;
6
6
  export declare function getNextFocusableElement(activeElement: HTMLElement, event: KeyboardEvent): HTMLElement | undefined;
7
7
  export declare function getElementState(element: HTMLElement): 'open' | 'closed' | 'end';
8
+ /**
9
+ * Find the next or previous visible treeitem using direct DOM traversal.
10
+ *
11
+ * PERFORMANCE: This is O(tree depth) instead of O(n) because it walks
12
+ * siblings and parent/child edges directly, rather than creating a TreeWalker
13
+ * that scans from the root to find the current element on every keystroke.
14
+ *
15
+ * NOTE: This relies on TreeView.SubTree unmounting its children when collapsed
16
+ * (returning null when !isExpanded). Because collapsed subtree children are
17
+ * never in the DOM, we can safely skip them by only entering children of nodes
18
+ * with aria-expanded="true". If SubTree ever changes to keep collapsed children
19
+ * mounted (e.g. via CSS display:none), this logic would need to add filtering
20
+ * for items inside collapsed parents.
21
+ */
8
22
  export declare function getVisibleElement(element: HTMLElement, direction: 'next' | 'previous'): HTMLElement | undefined;
9
23
  export declare function getFirstChildElement(element: HTMLElement): HTMLElement | undefined;
10
24
  export declare function getParentElement(element: HTMLElement): HTMLElement | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"useRovingTabIndex.d.ts","sourceRoot":"","sources":["../../src/TreeView/useRovingTabIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,wBAAgB,iBAAiB,CAAC,EAChC,YAAY,EACZ,YAAY,GACb,EAAE;IACD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;IAC1C,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;CACvC,QAwDA;AAID,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,GAAG,WAAW,GAAG,SAAS,CAyDjH;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAa/E;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAwB/G;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAGlF;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAI9E;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAI7E;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAuB5E"}
1
+ {"version":3,"file":"useRovingTabIndex.d.ts","sourceRoot":"","sources":["../../src/TreeView/useRovingTabIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,wBAAgB,iBAAiB,CAAC,EAChC,YAAY,EACZ,YAAY,GACb,EAAE;IACD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;IAC1C,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;CACvC,QAwDA;AAID,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,GAAG,WAAW,GAAG,SAAS,CAyDjH;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAa/E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAK/G;AAsFD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAGlF;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAI9E;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAI7E;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAuB5E"}
@@ -123,25 +123,103 @@ function getElementState(element) {
123
123
  return 'end';
124
124
  }
125
125
  }
126
+
127
+ /**
128
+ * Find the next or previous visible treeitem using direct DOM traversal.
129
+ *
130
+ * PERFORMANCE: This is O(tree depth) instead of O(n) because it walks
131
+ * siblings and parent/child edges directly, rather than creating a TreeWalker
132
+ * that scans from the root to find the current element on every keystroke.
133
+ *
134
+ * NOTE: This relies on TreeView.SubTree unmounting its children when collapsed
135
+ * (returning null when !isExpanded). Because collapsed subtree children are
136
+ * never in the DOM, we can safely skip them by only entering children of nodes
137
+ * with aria-expanded="true". If SubTree ever changes to keep collapsed children
138
+ * mounted (e.g. via CSS display:none), this logic would need to add filtering
139
+ * for items inside collapsed parents.
140
+ */
126
141
  function getVisibleElement(element, direction) {
127
- const root = element.closest('[role=tree]');
128
- if (!root) return;
129
- const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, node => {
130
- if (!(node instanceof HTMLElement)) return NodeFilter.FILTER_SKIP;
131
- return node.getAttribute('role') === 'treeitem' ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
132
- });
133
- let current = walker.firstChild();
134
- while (current !== element) {
135
- current = walker.nextNode();
136
- }
137
- let next = direction === 'next' ? walker.nextNode() : walker.previousNode();
142
+ if (direction === 'next') {
143
+ return getNextVisibleElement(element);
144
+ }
145
+ return getPreviousVisibleElement(element);
146
+ }
147
+ function getNextVisibleElement(element) {
148
+ // If the current item is expanded, the next visible item is its first child
149
+ if (element.getAttribute('aria-expanded') === 'true') {
150
+ const firstChild = getFirstChildElement(element);
151
+ if (firstChild) return firstChild;
152
+ }
153
+
154
+ // Otherwise, walk up the tree looking for a next sibling
155
+ let current = element;
156
+ while (current) {
157
+ const next = getNextSiblingTreeItem(current);
158
+ if (next) return next;
159
+
160
+ // No next sibling at this level, try the parent's next sibling
161
+ current = getParentElement(current);
162
+ }
163
+ return undefined;
164
+ }
165
+ function getPreviousVisibleElement(element) {
166
+ const prev = getPreviousSiblingTreeItem(element);
167
+ if (prev) {
168
+ // Navigate to the deepest last visible descendant of the previous sibling
169
+ return getDeepestLastDescendant(prev);
170
+ }
171
+
172
+ // No previous sibling, the parent is the previous visible element
173
+ return getParentElement(element);
174
+ }
138
175
 
139
- // If next element is nested inside a collapsed subtree, continue iterating
140
- while (next instanceof HTMLElement && (_next$parentElement = next.parentElement) !== null && _next$parentElement !== void 0 && _next$parentElement.closest('[role=treeitem][aria-expanded=false]')) {
141
- var _next$parentElement;
142
- next = direction === 'next' ? walker.nextNode() : walker.previousNode();
176
+ /**
177
+ * Walk into expanded subtrees to find the deepest last visible descendant.
178
+ * For example, if the last sibling is an expanded directory whose last child
179
+ * is also an expanded directory, we drill all the way down.
180
+ */
181
+ function getDeepestLastDescendant(element) {
182
+ if (element.getAttribute('aria-expanded') === 'true') {
183
+ const lastChild = getLastChildTreeItem(element);
184
+ if (lastChild) {
185
+ return getDeepestLastDescendant(lastChild);
186
+ }
187
+ }
188
+ return element;
189
+ }
190
+ function getNextSiblingTreeItem(element) {
191
+ let sibling = element.nextElementSibling;
192
+ while (sibling) {
193
+ if (sibling instanceof HTMLElement && sibling.getAttribute('role') === 'treeitem') {
194
+ return sibling;
195
+ }
196
+ sibling = sibling.nextElementSibling;
197
+ }
198
+ return undefined;
199
+ }
200
+ function getPreviousSiblingTreeItem(element) {
201
+ let sibling = element.previousElementSibling;
202
+ while (sibling) {
203
+ if (sibling instanceof HTMLElement && sibling.getAttribute('role') === 'treeitem') {
204
+ return sibling;
205
+ }
206
+ sibling = sibling.previousElementSibling;
207
+ }
208
+ return undefined;
209
+ }
210
+ function getLastChildTreeItem(element) {
211
+ // Find the [role=group] child (the subtree container), then get its last treeitem
212
+ for (let i = element.children.length - 1; i >= 0; i--) {
213
+ const child = element.children[i];
214
+ if (child instanceof HTMLElement && child.getAttribute('role') === 'group') {
215
+ let lastChild = child.lastElementChild;
216
+ while (lastChild && !(lastChild instanceof HTMLElement && lastChild.getAttribute('role') === 'treeitem')) {
217
+ lastChild = lastChild.previousElementSibling;
218
+ }
219
+ return lastChild instanceof HTMLElement ? lastChild : undefined;
220
+ }
143
221
  }
144
- return next instanceof HTMLElement ? next : undefined;
222
+ return undefined;
145
223
  }
146
224
  function getFirstChildElement(element) {
147
225
  const firstChild = element.querySelector('[role=treeitem]');
@@ -1,21 +1,58 @@
1
- import React, { forwardRef, useRef, useContext } from 'react';
1
+ import { c } from 'react-compiler-runtime';
2
+ import { forwardRef, useRef, useContext } from 'react';
2
3
  import { UnderlineNavContext } from './UnderlineNavContext.js';
3
4
  import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
4
5
  import { UnderlineItem } from '../internal/components/UnderlineTabbedInterface.js';
5
6
  import classes from './UnderlineNavItem.module.css.js';
6
7
  import { jsx } from 'react/jsx-runtime';
7
8
 
8
- const UnderlineNavItem = /*#__PURE__*/forwardRef(({
9
- as: Component = 'a',
10
- href = '#',
11
- children,
12
- counter,
13
- onSelect,
14
- 'aria-current': ariaCurrent,
15
- icon: Icon,
16
- leadingVisual,
17
- ...props
18
- }, forwardedRef) => {
9
+ const UnderlineNavItem = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
10
+ var _leadingVisual;
11
+ const $ = c(32);
12
+ let Icon;
13
+ let ariaCurrent;
14
+ let children;
15
+ let counter;
16
+ let leadingVisual;
17
+ let onSelect;
18
+ let props;
19
+ let t1;
20
+ let t2;
21
+ if ($[0] !== t0) {
22
+ ({
23
+ as: t1,
24
+ href: t2,
25
+ children,
26
+ counter,
27
+ onSelect,
28
+ "aria-current": ariaCurrent,
29
+ icon: Icon,
30
+ leadingVisual,
31
+ ...props
32
+ } = t0);
33
+ $[0] = t0;
34
+ $[1] = Icon;
35
+ $[2] = ariaCurrent;
36
+ $[3] = children;
37
+ $[4] = counter;
38
+ $[5] = leadingVisual;
39
+ $[6] = onSelect;
40
+ $[7] = props;
41
+ $[8] = t1;
42
+ $[9] = t2;
43
+ } else {
44
+ Icon = $[1];
45
+ ariaCurrent = $[2];
46
+ children = $[3];
47
+ counter = $[4];
48
+ leadingVisual = $[5];
49
+ onSelect = $[6];
50
+ props = $[7];
51
+ t1 = $[8];
52
+ t2 = $[9];
53
+ }
54
+ const Component = t1 === undefined ? "a" : t1;
55
+ const href = t2 === undefined ? "#" : t2;
19
56
  const backupRef = useRef(null);
20
57
  const ref = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
21
58
  const {
@@ -24,51 +61,107 @@ const UnderlineNavItem = /*#__PURE__*/forwardRef(({
24
61
  loadingCounters,
25
62
  iconsVisible
26
63
  } = useContext(UnderlineNavContext);
27
- useIsomorphicLayoutEffect(() => {
28
- if (ref.current) {
29
- const domRect = ref.current.getBoundingClientRect();
30
- const icon = Array.from(ref.current.children).find(child => child.getAttribute('data-component') === 'icon');
31
- const content = Array.from(ref.current.children).find(child => child.getAttribute('data-component') === 'text');
32
- const text = content.textContent;
33
- const iconWidthWithMargin = icon ? icon.getBoundingClientRect().width + Number(getComputedStyle(icon).marginRight.slice(0, -2)) + Number(getComputedStyle(icon).marginLeft.slice(0, -2)) : 0;
34
- setChildrenWidth({
35
- text,
36
- width: domRect.width
37
- });
38
- setNoIconChildrenWidth({
39
- text,
40
- width: domRect.width - iconWidthWithMargin
41
- });
42
- }
43
- }, [ref, setChildrenWidth, setNoIconChildrenWidth]);
44
- const keyDownHandler = React.useCallback(event => {
45
- if ((event.key === ' ' || event.key === 'Enter') && !event.defaultPrevented && typeof onSelect === 'function') {
46
- onSelect(event);
47
- }
48
- }, [onSelect]);
49
- const clickHandler = React.useCallback(event => {
50
- if (!event.defaultPrevented && typeof onSelect === 'function') {
51
- onSelect(event);
52
- }
53
- }, [onSelect]);
54
- return /*#__PURE__*/jsx("li", {
55
- className: classes.UnderlineNavItem,
56
- children: /*#__PURE__*/jsx(UnderlineItem, {
57
- ref: ref,
58
- as: Component,
59
- href: href,
60
- "aria-current": ariaCurrent,
61
- onKeyDown: keyDownHandler,
62
- onClick: clickHandler,
63
- counter: counter,
64
- icon: leadingVisual !== null && leadingVisual !== void 0 ? leadingVisual : Icon,
65
- loadingCounters: loadingCounters,
66
- iconsVisible: iconsVisible,
67
- ...props,
68
- children: children
69
- })
70
- });
64
+ let t3;
65
+ let t4;
66
+ if ($[10] !== ref || $[11] !== setChildrenWidth || $[12] !== setNoIconChildrenWidth) {
67
+ t3 = () => {
68
+ if (ref.current) {
69
+ const domRect = ref.current.getBoundingClientRect();
70
+ const icon = Array.from(ref.current.children).find(_temp);
71
+ const content = Array.from(ref.current.children).find(_temp2);
72
+ const text = content.textContent;
73
+ const iconWidthWithMargin = icon ? icon.getBoundingClientRect().width + Number(getComputedStyle(icon).marginRight.slice(0, -2)) + Number(getComputedStyle(icon).marginLeft.slice(0, -2)) : 0;
74
+ setChildrenWidth({
75
+ text,
76
+ width: domRect.width
77
+ });
78
+ setNoIconChildrenWidth({
79
+ text,
80
+ width: domRect.width - iconWidthWithMargin
81
+ });
82
+ }
83
+ };
84
+ t4 = [ref, setChildrenWidth, setNoIconChildrenWidth];
85
+ $[10] = ref;
86
+ $[11] = setChildrenWidth;
87
+ $[12] = setNoIconChildrenWidth;
88
+ $[13] = t3;
89
+ $[14] = t4;
90
+ } else {
91
+ t3 = $[13];
92
+ t4 = $[14];
93
+ }
94
+ useIsomorphicLayoutEffect(t3, t4);
95
+ let t5;
96
+ if ($[15] !== onSelect) {
97
+ t5 = event => {
98
+ if ((event.key === " " || event.key === "Enter") && !event.defaultPrevented && typeof onSelect === "function") {
99
+ onSelect(event);
100
+ }
101
+ };
102
+ $[15] = onSelect;
103
+ $[16] = t5;
104
+ } else {
105
+ t5 = $[16];
106
+ }
107
+ const keyDownHandler = t5;
108
+ let t6;
109
+ if ($[17] !== onSelect) {
110
+ t6 = event_0 => {
111
+ if (!event_0.defaultPrevented && typeof onSelect === "function") {
112
+ onSelect(event_0);
113
+ }
114
+ };
115
+ $[17] = onSelect;
116
+ $[18] = t6;
117
+ } else {
118
+ t6 = $[18];
119
+ }
120
+ const clickHandler = t6;
121
+ const t7 = (_leadingVisual = leadingVisual) !== null && _leadingVisual !== void 0 ? _leadingVisual : Icon;
122
+ let t8;
123
+ if ($[19] !== Component || $[20] !== ariaCurrent || $[21] !== children || $[22] !== clickHandler || $[23] !== counter || $[24] !== href || $[25] !== iconsVisible || $[26] !== keyDownHandler || $[27] !== loadingCounters || $[28] !== props || $[29] !== ref || $[30] !== t7) {
124
+ t8 = /*#__PURE__*/jsx("li", {
125
+ className: classes.UnderlineNavItem,
126
+ children: /*#__PURE__*/jsx(UnderlineItem, {
127
+ ref: ref,
128
+ as: Component,
129
+ href: href,
130
+ "aria-current": ariaCurrent,
131
+ onKeyDown: keyDownHandler,
132
+ onClick: clickHandler,
133
+ counter: counter,
134
+ icon: t7,
135
+ loadingCounters: loadingCounters,
136
+ iconsVisible: iconsVisible,
137
+ ...props,
138
+ children: children
139
+ })
140
+ });
141
+ $[19] = Component;
142
+ $[20] = ariaCurrent;
143
+ $[21] = children;
144
+ $[22] = clickHandler;
145
+ $[23] = counter;
146
+ $[24] = href;
147
+ $[25] = iconsVisible;
148
+ $[26] = keyDownHandler;
149
+ $[27] = loadingCounters;
150
+ $[28] = props;
151
+ $[29] = ref;
152
+ $[30] = t7;
153
+ $[31] = t8;
154
+ } else {
155
+ t8 = $[31];
156
+ }
157
+ return t8;
71
158
  });
72
159
  UnderlineNavItem.displayName = 'UnderlineNavItem';
160
+ function _temp(child) {
161
+ return child.getAttribute("data-component") === "icon";
162
+ }
163
+ function _temp2(child_0) {
164
+ return child_0.getAttribute("data-component") === "text";
165
+ }
73
166
 
74
167
  export { UnderlineNavItem };