@primer/react 0.0.0-20260715193046 → 0.0.0-20260716164750

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +15 -3
  2. package/dist/ActionBar/ActionBar.js +1 -1
  3. package/dist/ActionList/Group.js +1 -1
  4. package/dist/ActionList/List.js +14 -20
  5. package/dist/AnchoredOverlay/AnchoredOverlay.js +3 -9
  6. package/dist/Autocomplete/AutocompleteInput.js +7 -10
  7. package/dist/ButtonGroup/ButtonGroup.js +8 -15
  8. package/dist/Checkbox/Checkbox.js +9 -16
  9. package/dist/Dialog/Dialog.js +5 -12
  10. package/dist/FeatureFlags/DefaultFeatureFlags.js +1 -2
  11. package/dist/FilteredActionList/FilteredActionList.js +20 -31
  12. package/dist/FilteredActionList/FilteredActionListInput.d.ts +1 -1
  13. package/dist/Overlay/Overlay.js +1 -1
  14. package/dist/PageHeader/PageHeader.js +21 -30
  15. package/dist/PageLayout/DragHandle.d.ts +45 -0
  16. package/dist/PageLayout/DragHandle.js +224 -0
  17. package/dist/PageLayout/PageLayout.js +53 -247
  18. package/dist/PageLayout/index.d.ts +3 -1
  19. package/dist/PageLayout/usePaneWidth.d.ts +63 -1
  20. package/dist/PageLayout/usePaneWidth.js +52 -36
  21. package/dist/SelectPanel/SelectPanel.js +1 -1
  22. package/dist/TextInput/TextInput.js +6 -13
  23. package/dist/TooltipV2/Tooltip.js +11 -18
  24. package/dist/experimental/Tabs/types.d.ts +2 -2
  25. package/dist/experimental/Tabs/useTabList.js +10 -18
  26. package/dist/experimental/index.js +3 -3
  27. package/dist/hooks/useAnchoredPosition.js +14 -1
  28. package/dist/hooks/useMergedRefs.d.ts +4 -4
  29. package/dist/hooks/useMergedRefs.js +5 -8
  30. package/dist/hooks/useProvidedRefOrCreate.d.ts +10 -7
  31. package/dist/hooks/useProvidedRefOrCreate.js +10 -7
  32. package/dist/index.d.ts +3 -1
  33. package/dist/index.js +3 -1
  34. package/package.json +1 -1
@@ -1,7 +1,5 @@
1
- import { useMergedRefs } from "../hooks/useMergedRefs.js";
2
1
  import { useProvidedRefOrCreate } from "../hooks/useProvidedRefOrCreate.js";
3
2
  import { warning } from "../utils/warning.js";
4
- import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
5
3
  import { isResponsiveValue } from "../hooks/useResponsiveValue.js";
6
4
  import { isSlot } from "../utils/is-slot.js";
7
5
  import { getResponsiveAttributes } from "../internal/utils/getResponsiveAttributes.js";
@@ -12,7 +10,7 @@ import PageHeader_module_css_default from "./PageHeader.module.css.js";
12
10
  import { c } from "react-compiler-runtime";
13
11
  import { clsx } from "clsx";
14
12
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
15
- import React, { useEffect, useRef } from "react";
13
+ import React, { useEffect } from "react";
16
14
  import { ArrowLeftIcon } from "@primer/octicons-react";
17
15
  //#region src/PageHeader/PageHeader.tsx
18
16
  const hiddenOnRegularAndWide = {
@@ -29,12 +27,7 @@ const Root = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
29
27
  const $ = c(17);
30
28
  const { children, className, as: t1, "aria-label": ariaLabel, role, hasBorder } = t0;
31
29
  const BaseComponent = t1 === void 0 ? "div" : t1;
32
- const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
33
- const rootRef = useRef(null);
34
- const mergedRef = useMergedRefs(rootRef, forwardedRef);
35
- const providedOrCreatedRef = useProvidedRefOrCreate(forwardedRef);
36
- const readRef = mergedRefEnabled ? rootRef : providedOrCreatedRef;
37
- const appliedRef = mergedRefEnabled ? mergedRef : providedOrCreatedRef;
30
+ const rootRef = useProvidedRefOrCreate(forwardedRef);
38
31
  const hoistChildState = (nodes) => {
39
32
  const result = { hasNavigation: false };
40
33
  for (const child of React.Children.toArray(nodes)) {
@@ -61,12 +54,12 @@ const Root = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
61
54
  const isInteractive = _temp;
62
55
  let t2;
63
56
  let t3;
64
- if ($[0] !== children || $[1] !== readRef) {
57
+ if ($[0] !== children || $[1] !== rootRef) {
65
58
  t2 = function validateInteractiveElementsInTitle() {
66
59
  let hasContextArea = false;
67
60
  let hasLeadingAction = false;
68
- if (!readRef.current || readRef.current.children.length <= 0) return;
69
- const titleArea = Array.from(readRef.current.children).find(_temp2);
61
+ if (!rootRef.current || rootRef.current.children.length <= 0) return;
62
+ const titleArea = Array.from(rootRef.current.children).find(_temp2);
70
63
  if (!titleArea) return;
71
64
  for (const child_1 of React.Children.toArray(children)) {
72
65
  if (/*#__PURE__*/ React.isValidElement(child_1) && (child_1.type === ContextArea || isSlot(child_1, ContextArea))) hasContextArea = true;
@@ -74,9 +67,9 @@ const Root = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
74
67
  }
75
68
  warning(Array.from(titleArea.childNodes).some((child_2) => child_2 instanceof HTMLElement && isInteractive(child_2) || Array.from(child_2.childNodes).some((child_3) => child_3 instanceof HTMLElement && isInteractive(child_3))) && (hasContextArea || hasLeadingAction), "When PageHeader.ContextArea or PageHeader.LeadingAction is present, we recommended not to include any interactive items in the PageHeader.TitleArea to make sure the focus order is logical.");
76
69
  };
77
- t3 = [children, readRef];
70
+ t3 = [children, rootRef];
78
71
  $[0] = children;
79
- $[1] = readRef;
72
+ $[1] = rootRef;
80
73
  $[2] = t2;
81
74
  $[3] = t3;
82
75
  } else {
@@ -96,9 +89,9 @@ const Root = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
96
89
  const t8 = getResponsiveAttributes("title-size-variant", titleVariant);
97
90
  const t9 = getNavHiddenDataAttributes(navigationHidden);
98
91
  let t10;
99
- if ($[6] !== BaseComponent || $[7] !== appliedRef || $[8] !== ariaLabel || $[9] !== children || $[10] !== role || $[11] !== t4 || $[12] !== t6 || $[13] !== t7 || $[14] !== t8 || $[15] !== t9) {
92
+ if ($[6] !== BaseComponent || $[7] !== ariaLabel || $[8] !== children || $[9] !== role || $[10] !== rootRef || $[11] !== t4 || $[12] !== t6 || $[13] !== t7 || $[14] !== t8 || $[15] !== t9) {
100
93
  t10 = /*#__PURE__*/ jsx(BaseComponent, {
101
- ref: appliedRef,
94
+ ref: rootRef,
102
95
  className: t4,
103
96
  "data-component": t5,
104
97
  "data-has-border": t6,
@@ -110,10 +103,10 @@ const Root = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
110
103
  children
111
104
  });
112
105
  $[6] = BaseComponent;
113
- $[7] = appliedRef;
114
- $[8] = ariaLabel;
115
- $[9] = children;
116
- $[10] = role;
106
+ $[7] = ariaLabel;
107
+ $[8] = children;
108
+ $[9] = role;
109
+ $[10] = rootRef;
117
110
  $[11] = t4;
118
111
  $[12] = t6;
119
112
  $[13] = t7;
@@ -302,9 +295,7 @@ const TitleArea = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
302
295
  const { children, className, hidden: t1, variant: t2 } = t0;
303
296
  const hidden = t1 === void 0 ? false : t1;
304
297
  const variant = t2 === void 0 ? "medium" : t2;
305
- const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
306
- const providedOrCreatedRef = useProvidedRefOrCreate(forwardedRef);
307
- const appliedRef = mergedRefEnabled ? forwardedRef : providedOrCreatedRef;
298
+ const titleAreaRef = useProvidedRefOrCreate(forwardedRef);
308
299
  let t3;
309
300
  if ($[0] !== className) {
310
301
  t3 = clsx(PageHeader_module_css_default.TitleArea, className);
@@ -324,20 +315,20 @@ const TitleArea = /*#__PURE__*/ React.forwardRef((t0, forwardedRef) => {
324
315
  $[5] = t5;
325
316
  } else t5 = $[5];
326
317
  let t6;
327
- if ($[6] !== appliedRef || $[7] !== children || $[8] !== t3 || $[9] !== t4 || $[10] !== t5) {
318
+ if ($[6] !== children || $[7] !== t3 || $[8] !== t4 || $[9] !== t5 || $[10] !== titleAreaRef) {
328
319
  t6 = /*#__PURE__*/ jsx("div", {
329
320
  className: t3,
330
- ref: appliedRef,
321
+ ref: titleAreaRef,
331
322
  "data-component": "TitleArea",
332
323
  ...t4,
333
324
  ...t5,
334
325
  children
335
326
  });
336
- $[6] = appliedRef;
337
- $[7] = children;
338
- $[8] = t3;
339
- $[9] = t4;
340
- $[10] = t5;
327
+ $[6] = children;
328
+ $[7] = t3;
329
+ $[8] = t4;
330
+ $[9] = t5;
331
+ $[10] = titleAreaRef;
341
332
  $[11] = t6;
342
333
  } else t6 = $[11];
343
334
  return t6;
@@ -0,0 +1,45 @@
1
+ import React from "react";
2
+
3
+ //#region src/PageLayout/DragHandle.d.ts
4
+ type DragHandleProps = {
5
+ /** Ref for imperative ARIA updates during drag */handleRef: React.RefObject<HTMLDivElement>; /** Called once when drag starts with initial cursor X position */
6
+ onDragStart: (clientX: number) => void; /** Called on each drag tick with cursor position (pointer) or delta (keyboard) */
7
+ onDrag: (value: number, isKeyboard: boolean) => void; /** Called when drag operation completes */
8
+ onDragEnd: () => void; /** Reset width on double-click */
9
+ onDoubleClick?: React.MouseEventHandler<HTMLDivElement>;
10
+ /**
11
+ * Accessible name for the slider. Defaults to `'Draggable pane splitter'`.
12
+ * Provide a context-specific or localized label for standalone usage.
13
+ * Ignored when `aria-labelledby` is provided.
14
+ */
15
+ 'aria-label'?: string; /** Id of an element that labels the slider. Takes precedence over `aria-label`. */
16
+ 'aria-labelledby'?: string; /** ARIA slider min value */
17
+ 'aria-valuemin'?: number; /** ARIA slider max value */
18
+ 'aria-valuemax'?: number; /** ARIA slider current value */
19
+ 'aria-valuenow'?: number;
20
+ /**
21
+ * Ref to the element that receives drag-time styling/containment optimizations
22
+ * (e.g. the resizable pane). When omitted, those side effects are skipped.
23
+ */
24
+ dragTargetRef?: React.RefObject<HTMLElement | null>;
25
+ /**
26
+ * Ref to a content wrapper element that receives drag-time containment.
27
+ * Only needed for layouts (like PageLayout) that optimize sibling content during drag.
28
+ */
29
+ contentWrapperRef?: React.RefObject<HTMLElement | null>;
30
+ /**
31
+ * Formats the `aria-valuetext` announced for the current width.
32
+ * @default valueNow => `Pane width ${valueNow} pixels`
33
+ */
34
+ formatValueText?: (valueNow: number) => string; /** Value for the `data-component` attribute. */
35
+ 'data-component'?: string;
36
+ };
37
+ /**
38
+ * DragHandle - handles all pointer and keyboard interactions for resizing.
39
+ * ARIA values are set in JSX for SSR accessibility, then updated via DOM
40
+ * manipulation during drag for performance. The consumer owns writing the width
41
+ * (via the `onDrag` callback); this component only reports interactions.
42
+ */
43
+ declare const DragHandle: React.NamedExoticComponent<DragHandleProps>;
44
+ //#endregion
45
+ export { DragHandle, DragHandleProps };
@@ -0,0 +1,224 @@
1
+ import PageLayout_module_css_default from "./PageLayout.module.css.js";
2
+ import { defaultFormatValueText } from "./usePaneWidth.js";
3
+ import { removeDraggingStyles, setDraggingStyles } from "./paneUtils.js";
4
+ import { c } from "react-compiler-runtime";
5
+ import { jsx } from "react/jsx-runtime";
6
+ import React, { memo } from "react";
7
+ //#region src/PageLayout/DragHandle.tsx
8
+ const isArrowKey = (key) => key === "ArrowLeft" || key === "ArrowRight" || key === "ArrowUp" || key === "ArrowDown";
9
+ const isShrinkKey = (key) => key === "ArrowLeft" || key === "ArrowDown";
10
+ /**
11
+ * DragHandle - handles all pointer and keyboard interactions for resizing.
12
+ * ARIA values are set in JSX for SSR accessibility, then updated via DOM
13
+ * manipulation during drag for performance. The consumer owns writing the width
14
+ * (via the `onDrag` callback); this component only reports interactions.
15
+ */
16
+ const DragHandle = /*#__PURE__*/ memo(function DragHandle(t0) {
17
+ const $ = c(41);
18
+ const { handleRef, onDragStart, onDrag, onDragEnd, onDoubleClick, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-valuemin": ariaValueMin, "aria-valuemax": ariaValueMax, "aria-valuenow": ariaValueNow, dragTargetRef, contentWrapperRef, formatValueText: t1, "data-component": t2 } = t0;
19
+ const formatValueText = t1 === void 0 ? defaultFormatValueText : t1;
20
+ const dataComponent = t2 === void 0 ? "PageLayout.DragHandle" : t2;
21
+ const stableOnDragStart = React.useRef(onDragStart);
22
+ const stableOnDrag = React.useRef(onDrag);
23
+ const stableOnDragEnd = React.useRef(onDragEnd);
24
+ let t3;
25
+ if ($[0] !== onDrag || $[1] !== onDragEnd || $[2] !== onDragStart) {
26
+ t3 = () => {
27
+ stableOnDragStart.current = onDragStart;
28
+ stableOnDrag.current = onDrag;
29
+ stableOnDragEnd.current = onDragEnd;
30
+ };
31
+ $[0] = onDrag;
32
+ $[1] = onDragEnd;
33
+ $[2] = onDragStart;
34
+ $[3] = t3;
35
+ } else t3 = $[3];
36
+ React.useEffect(t3);
37
+ const isDraggingRef = React.useRef(false);
38
+ let t4;
39
+ if ($[4] !== contentWrapperRef || $[5] !== dragTargetRef || $[6] !== handleRef) {
40
+ t4 = () => {
41
+ var _dragTargetRef$curren, _contentWrapperRef$cu;
42
+ if (isDraggingRef.current) return;
43
+ setDraggingStyles({
44
+ handle: handleRef.current,
45
+ pane: (_dragTargetRef$curren = dragTargetRef === null || dragTargetRef === void 0 ? void 0 : dragTargetRef.current) !== null && _dragTargetRef$curren !== void 0 ? _dragTargetRef$curren : null,
46
+ contentWrapper: (_contentWrapperRef$cu = contentWrapperRef === null || contentWrapperRef === void 0 ? void 0 : contentWrapperRef.current) !== null && _contentWrapperRef$cu !== void 0 ? _contentWrapperRef$cu : null
47
+ });
48
+ isDraggingRef.current = true;
49
+ };
50
+ $[4] = contentWrapperRef;
51
+ $[5] = dragTargetRef;
52
+ $[6] = handleRef;
53
+ $[7] = t4;
54
+ } else t4 = $[7];
55
+ const startDragging = t4;
56
+ let t5;
57
+ if ($[8] !== contentWrapperRef || $[9] !== dragTargetRef || $[10] !== handleRef) {
58
+ t5 = () => {
59
+ var _dragTargetRef$curren2, _contentWrapperRef$cu2;
60
+ if (!isDraggingRef.current) return;
61
+ removeDraggingStyles({
62
+ handle: handleRef.current,
63
+ pane: (_dragTargetRef$curren2 = dragTargetRef === null || dragTargetRef === void 0 ? void 0 : dragTargetRef.current) !== null && _dragTargetRef$curren2 !== void 0 ? _dragTargetRef$curren2 : null,
64
+ contentWrapper: (_contentWrapperRef$cu2 = contentWrapperRef === null || contentWrapperRef === void 0 ? void 0 : contentWrapperRef.current) !== null && _contentWrapperRef$cu2 !== void 0 ? _contentWrapperRef$cu2 : null
65
+ });
66
+ isDraggingRef.current = false;
67
+ };
68
+ $[8] = contentWrapperRef;
69
+ $[9] = dragTargetRef;
70
+ $[10] = handleRef;
71
+ $[11] = t5;
72
+ } else t5 = $[11];
73
+ const endDragging = t5;
74
+ let t6;
75
+ if ($[12] !== startDragging) {
76
+ t6 = (event) => {
77
+ if (event.button !== 0) return;
78
+ event.preventDefault();
79
+ const target = event.currentTarget;
80
+ try {
81
+ target.setPointerCapture(event.pointerId);
82
+ } catch {}
83
+ stableOnDragStart.current(event.clientX);
84
+ startDragging();
85
+ };
86
+ $[12] = startDragging;
87
+ $[13] = t6;
88
+ } else t6 = $[13];
89
+ const handlePointerDown = t6;
90
+ const rafIdRef = React.useRef(null);
91
+ const pendingClientXRef = React.useRef(null);
92
+ let t7;
93
+ if ($[14] === Symbol.for("react.memo_cache_sentinel")) {
94
+ t7 = (event_0) => {
95
+ if (!isDraggingRef.current) return;
96
+ event_0.preventDefault();
97
+ pendingClientXRef.current = event_0.clientX;
98
+ if (rafIdRef.current === null) rafIdRef.current = requestAnimationFrame(() => {
99
+ rafIdRef.current = null;
100
+ if (pendingClientXRef.current !== null) {
101
+ stableOnDrag.current(pendingClientXRef.current, false);
102
+ pendingClientXRef.current = null;
103
+ }
104
+ });
105
+ };
106
+ $[14] = t7;
107
+ } else t7 = $[14];
108
+ const handlePointerMove = t7;
109
+ let t8;
110
+ if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
111
+ t8 = (event_1) => {
112
+ if (!isDraggingRef.current) return;
113
+ event_1.preventDefault();
114
+ };
115
+ $[15] = t8;
116
+ } else t8 = $[15];
117
+ const handlePointerUp = t8;
118
+ let t9;
119
+ if ($[16] !== endDragging) {
120
+ t9 = () => {
121
+ if (!isDraggingRef.current) return;
122
+ if (rafIdRef.current !== null) {
123
+ cancelAnimationFrame(rafIdRef.current);
124
+ rafIdRef.current = null;
125
+ pendingClientXRef.current = null;
126
+ }
127
+ endDragging();
128
+ stableOnDragEnd.current();
129
+ };
130
+ $[16] = endDragging;
131
+ $[17] = t9;
132
+ } else t9 = $[17];
133
+ const handleLostPointerCapture = t9;
134
+ let t10;
135
+ if ($[18] !== startDragging) {
136
+ t10 = (event_2) => {
137
+ if (!isArrowKey(event_2.key)) return;
138
+ event_2.preventDefault();
139
+ const delta = isShrinkKey(event_2.key) ? -3 : 3;
140
+ if (!isDraggingRef.current) startDragging();
141
+ stableOnDrag.current(delta, true);
142
+ };
143
+ $[18] = startDragging;
144
+ $[19] = t10;
145
+ } else t10 = $[19];
146
+ const handleKeyDown = t10;
147
+ let t11;
148
+ if ($[20] !== endDragging) {
149
+ t11 = (event_3) => {
150
+ if (!isArrowKey(event_3.key)) return;
151
+ event_3.preventDefault();
152
+ endDragging();
153
+ stableOnDragEnd.current();
154
+ };
155
+ $[20] = endDragging;
156
+ $[21] = t11;
157
+ } else t11 = $[21];
158
+ const handleKeyUp = t11;
159
+ let t12;
160
+ let t13;
161
+ if ($[22] === Symbol.for("react.memo_cache_sentinel")) {
162
+ t12 = () => () => {
163
+ if (rafIdRef.current !== null) {
164
+ cancelAnimationFrame(rafIdRef.current);
165
+ rafIdRef.current = null;
166
+ }
167
+ };
168
+ t13 = [];
169
+ $[22] = t12;
170
+ $[23] = t13;
171
+ } else {
172
+ t12 = $[22];
173
+ t13 = $[23];
174
+ }
175
+ React.useEffect(t12, t13);
176
+ const t14 = ariaLabelledBy ? void 0 : ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : "Draggable pane splitter";
177
+ let t15;
178
+ if ($[24] !== ariaValueNow || $[25] !== formatValueText) {
179
+ t15 = ariaValueNow !== void 0 ? formatValueText(ariaValueNow) : void 0;
180
+ $[24] = ariaValueNow;
181
+ $[25] = formatValueText;
182
+ $[26] = t15;
183
+ } else t15 = $[26];
184
+ let t16;
185
+ if ($[27] !== ariaLabelledBy || $[28] !== ariaValueMax || $[29] !== ariaValueMin || $[30] !== ariaValueNow || $[31] !== dataComponent || $[32] !== handleKeyDown || $[33] !== handleKeyUp || $[34] !== handleLostPointerCapture || $[35] !== handlePointerDown || $[36] !== handleRef || $[37] !== onDoubleClick || $[38] !== t14 || $[39] !== t15) {
186
+ t16 = /*#__PURE__*/ jsx("div", {
187
+ ref: handleRef,
188
+ className: PageLayout_module_css_default.DraggableHandle,
189
+ "data-component": dataComponent,
190
+ role: "slider",
191
+ "aria-label": t14,
192
+ "aria-labelledby": ariaLabelledBy,
193
+ "aria-valuemin": ariaValueMin,
194
+ "aria-valuemax": ariaValueMax,
195
+ "aria-valuenow": ariaValueNow,
196
+ "aria-valuetext": t15,
197
+ tabIndex: 0,
198
+ onPointerDown: handlePointerDown,
199
+ onPointerMove: handlePointerMove,
200
+ onPointerUp: handlePointerUp,
201
+ onLostPointerCapture: handleLostPointerCapture,
202
+ onKeyDown: handleKeyDown,
203
+ onKeyUp: handleKeyUp,
204
+ onDoubleClick
205
+ });
206
+ $[27] = ariaLabelledBy;
207
+ $[28] = ariaValueMax;
208
+ $[29] = ariaValueMin;
209
+ $[30] = ariaValueNow;
210
+ $[31] = dataComponent;
211
+ $[32] = handleKeyDown;
212
+ $[33] = handleKeyUp;
213
+ $[34] = handleLostPointerCapture;
214
+ $[35] = handlePointerDown;
215
+ $[36] = handleRef;
216
+ $[37] = onDoubleClick;
217
+ $[38] = t14;
218
+ $[39] = t15;
219
+ $[40] = t16;
220
+ } else t16 = $[40];
221
+ return t16;
222
+ });
223
+ //#endregion
224
+ export { DragHandle };