@primer/react 0.0.0-20260814135639 → 0.0.0-20260818135516

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,9 +1,7 @@
1
1
  import useIsomorphicLayoutEffect from "../../utils/useIsomorphicLayoutEffect.js";
2
2
  import { useResizeObserver } from "../../hooks/useResizeObserver.js";
3
3
  import { useId as useId$1 } from "../../hooks/useId.js";
4
- import { warning } from "../../utils/warning.js";
5
4
  import { isSlot } from "../../utils/is-slot.js";
6
- import { useFeatureFlag } from "../../FeatureFlags/useFeatureFlag.js";
7
5
  import { invariant } from "../../utils/invariant.js";
8
6
  import { UnderlineItem, UnderlineItemList, UnderlineWrapper } from "../../internal/components/UnderlineTabbedInterface.js";
9
7
  import UnderlinePanels_module_css_default from "./UnderlinePanels.module.css.js";
@@ -19,78 +17,43 @@ const UnderlinePanelsContext = /*#__PURE__*/ createContext({
19
17
  iconsVisible: true,
20
18
  loadingCounters: void 0
21
19
  });
22
- const UnderlinePanels = ({ "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, children, loadingCounters, className, value: valueProp, defaultValue: defaultValueProp, onChange: onChangeProp, activationMode = "automatic", ...props }) => {
23
- var _tabValues$;
24
- const controlledApiEnabled = useFeatureFlag("primer_react_underline_panels_controlled");
25
- const controlledValue = controlledApiEnabled ? valueProp : void 0;
26
- const defaultValue = controlledApiEnabled ? defaultValueProp : void 0;
27
- const onChange = controlledApiEnabled ? onChangeProp : void 0;
20
+ const UnderlinePanels = ({ "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, children, loadingCounters, className, ...props }) => {
28
21
  const [iconsVisible, setIconsVisible] = useState(true);
29
22
  const wrapperRef = useRef(null);
30
23
  const listRef = useRef(null);
31
24
  const parentId = useId$1(props.id);
32
- const [tabs, tabPanels, tabsHaveIcons, selectedFromProps, tabValues, panelValues] = useMemo(() => {
25
+ const [tabs, tabPanels, tabsHaveIcons, selectedFromProps] = useMemo(() => {
33
26
  let tabIndex = 0;
34
27
  let panelIndex = 0;
35
28
  const childrenWithProps = Children.map(children, (child) => {
36
- if (/*#__PURE__*/ isValidElement(child) && (child.type === Tab || isSlot(child, Tab))) {
37
- var _ref;
38
- const value = (_ref = controlledApiEnabled ? child.props.value : void 0) !== null && _ref !== void 0 ? _ref : `${tabIndex}`;
39
- tabIndex++;
40
- return /*#__PURE__*/ cloneElement(child, { value });
41
- }
42
- if (/*#__PURE__*/ isValidElement(child) && (child.type === Panel || isSlot(child, Panel))) {
43
- var _ref2;
44
- const value = (_ref2 = controlledApiEnabled ? child.props.value : void 0) !== null && _ref2 !== void 0 ? _ref2 : `${panelIndex}`;
45
- panelIndex++;
46
- return /*#__PURE__*/ cloneElement(child, { value });
47
- }
29
+ if (/*#__PURE__*/ isValidElement(child) && (child.type === Tab || isSlot(child, Tab))) return /*#__PURE__*/ cloneElement(child, { value: `${tabIndex++}` });
30
+ if (/*#__PURE__*/ isValidElement(child) && (child.type === Panel || isSlot(child, Panel))) return /*#__PURE__*/ cloneElement(child, { value: `${panelIndex++}` });
48
31
  return child;
49
32
  });
50
33
  const tabs = [];
51
34
  const tabPanels = [];
52
- const tabValues = [];
53
- const panelValues = [];
54
35
  let selectedFromProps;
55
36
  for (const child of Children.toArray(childrenWithProps)) {
56
37
  if (!/*#__PURE__*/ isValidElement(child)) continue;
57
38
  if (child.type === Tab || isSlot(child, Tab)) {
58
- const value = child.props.value;
59
- if (value !== void 0) tabValues.push(value);
60
39
  const ariaSelected = child.props["aria-selected"];
61
- if (ariaSelected === true || ariaSelected === "true") selectedFromProps = value;
40
+ if (ariaSelected === true || ariaSelected === "true") selectedFromProps = `${tabs.length}`;
62
41
  tabs.push(child);
63
- } else if (child.type === Panel || isSlot(child, Panel)) {
64
- const value = child.props.value;
65
- if (value !== void 0) panelValues.push(value);
66
- tabPanels.push(child);
67
- }
42
+ } else if (child.type === Panel || isSlot(child, Panel)) tabPanels.push(child);
68
43
  }
69
44
  return [
70
45
  tabs,
71
46
  tabPanels,
72
47
  tabs.some((tab) => /*#__PURE__*/ React.isValidElement(tab) && tab.props.icon),
73
- selectedFromProps,
74
- tabValues,
75
- panelValues
48
+ selectedFromProps
76
49
  ];
77
- }, [children, controlledApiEnabled]);
78
- const isControlled = controlledValue !== void 0;
79
- const [uncontrolledValue, setUncontrolledValue] = useState(() => {
80
- var _ref3;
81
- return (_ref3 = defaultValue !== null && defaultValue !== void 0 ? defaultValue : selectedFromProps) !== null && _ref3 !== void 0 ? _ref3 : "0";
82
- });
50
+ }, [children]);
51
+ const [selectedValue, setSelectedValue] = useState(() => selectedFromProps !== null && selectedFromProps !== void 0 ? selectedFromProps : "0");
83
52
  const [prevSelectedFromProps, setPrevSelectedFromProps] = useState(selectedFromProps);
84
- if (!isControlled && selectedFromProps !== prevSelectedFromProps) {
53
+ if (selectedFromProps !== prevSelectedFromProps) {
85
54
  setPrevSelectedFromProps(selectedFromProps);
86
- if (selectedFromProps !== void 0 && selectedFromProps !== uncontrolledValue) setUncontrolledValue(selectedFromProps);
55
+ if (selectedFromProps !== void 0 && selectedFromProps !== selectedValue) setSelectedValue(selectedFromProps);
87
56
  }
88
- const selectedValue = isControlled ? controlledValue : uncontrolledValue;
89
- const effectiveValue = tabValues.includes(selectedValue) ? selectedValue : (_tabValues$ = tabValues[0]) !== null && _tabValues$ !== void 0 ? _tabValues$ : selectedValue;
90
- const handleValueChange = (value) => {
91
- if (!isControlled) setUncontrolledValue(value);
92
- onChange === null || onChange === void 0 || onChange({ value });
93
- };
94
57
  const { tabListProps } = useTabList({
95
58
  "aria-label": ariaLabel,
96
59
  "aria-labelledby": ariaLabelledBy,
@@ -115,31 +78,17 @@ const UnderlinePanels = ({ "aria-label": ariaLabel, "aria-labelledby": ariaLabel
115
78
  const wrapperWidth = resizeObserverEntries[0].contentRect.width;
116
79
  setIconsVisible(wrapperWidth > listWidthRef.current);
117
80
  }, wrapperRef, []);
118
- {
119
- const selectedTabs = tabs.filter((tab) => {
120
- const ariaSelected = /*#__PURE__*/ React.isValidElement(tab) && tab.props["aria-selected"];
121
- return ariaSelected === true || ariaSelected === "true";
122
- });
123
- !(selectedTabs.length <= 1) && invariant(false, "Only one tab can be selected at a time.");
124
- !(tabs.length === tabPanels.length) && invariant(false, `The number of tabs and panels must be equal. Counted ${tabs.length} tabs and ${tabPanels.length} panels.`);
125
- const duplicateTabValue = tabValues.find((value, index) => tabValues.indexOf(value) !== index);
126
- !(duplicateTabValue === void 0) && invariant(false, `Every tab must have a unique \`value\`. Found duplicate "${duplicateTabValue}".`);
127
- const duplicatePanelValue = panelValues.find((value, index) => panelValues.indexOf(value) !== index);
128
- !(duplicatePanelValue === void 0) && invariant(false, `Every panel must have a unique \`value\`. Found duplicate "${duplicatePanelValue}".`);
129
- const unmatchedTabValue = tabValues.find((value) => !panelValues.includes(value));
130
- !(unmatchedTabValue === void 0) && invariant(false, `Tab with \`value\` "${unmatchedTabValue}" has no matching panel. Give a \`UnderlinePanels.Panel\` the same \`value\`.`);
131
- warning(isControlled && selectedTabs.length > 0, "UnderlinePanels: do not combine the controlled `value` prop with `aria-selected` on a tab. `value` takes precedence; use `value`/`onChange` (or `defaultValue`) to drive selection.");
132
- warning(controlledValue !== void 0 && defaultValue !== void 0, "UnderlinePanels: do not combine the controlled `value` prop with `defaultValue`. `value` takes precedence; use one or the other.");
133
- const providedValue = controlledValue !== null && controlledValue !== void 0 ? controlledValue : defaultValue;
134
- warning(providedValue !== void 0 && tabValues.length > 0 && !tabValues.includes(providedValue), `UnderlinePanels: the selected value "${providedValue}" does not match any tab, so the first tab is selected instead. Provide a \`value\`/\`defaultValue\` that matches a \`UnderlinePanels.Tab\` \`value\`.`);
135
- }
81
+ !(tabs.filter((tab) => {
82
+ const ariaSelected = /*#__PURE__*/ React.isValidElement(tab) && tab.props["aria-selected"];
83
+ return ariaSelected === true || ariaSelected === "true";
84
+ }).length <= 1) && invariant(false, "Only one tab can be selected at a time.");
85
+ !(tabs.length === tabPanels.length) && invariant(false, `The number of tabs and panels must be equal. Counted ${tabs.length} tabs and ${tabPanels.length} panels.`);
136
86
  return /*#__PURE__*/ jsx(UnderlinePanelsContext.Provider, {
137
87
  value: contextValue,
138
88
  children: /*#__PURE__*/ jsxs(Tabs, {
139
89
  id: parentId,
140
- value: effectiveValue,
141
- activationMode,
142
- onValueChange: ({ value }) => handleValueChange(value),
90
+ value: selectedValue,
91
+ onValueChange: ({ value }) => setSelectedValue(value),
143
92
  children: [/*#__PURE__*/ jsx(UnderlineWrapper, {
144
93
  ref: wrapperRef,
145
94
  "data-icons-visible": iconsVisible,
@@ -2,6 +2,10 @@ import { c } from "react-compiler-runtime";
2
2
  import { useEffect } from "react";
3
3
  import { iterateFocusableElements } from "@primer/behaviors/utils";
4
4
  //#region src/hooks/useOpenAndCloseFocus.ts
5
+ function focusCurrentTarget(ref) {
6
+ var _ref$current;
7
+ (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.focus();
8
+ }
5
9
  function useOpenAndCloseFocus(t0) {
6
10
  const $ = c(6);
7
11
  const { initialFocusRef, returnFocusRef, containerRef, preventFocusOnOpen } = t0;
@@ -16,9 +20,8 @@ function useOpenAndCloseFocus(t0) {
16
20
  firstItem === null || firstItem === void 0 || firstItem.focus();
17
21
  }
18
22
  }
19
- const returnFocusRefCurrent = returnFocusRef.current;
20
23
  return function() {
21
- returnFocusRefCurrent === null || returnFocusRefCurrent === void 0 || returnFocusRefCurrent.focus();
24
+ focusCurrentTarget(returnFocusRef);
22
25
  };
23
26
  };
24
27
  t2 = [
@@ -91,6 +91,12 @@
91
91
  "type": "boolean",
92
92
  "defaultValue": "",
93
93
  "description": "Provides a disabled state for the button. The button will remain focusable, and have `aria-disabled` applied."
94
+ },
95
+ {
96
+ "name": "activeAnchorRef",
97
+ "type": "React.Ref<HTMLButtonElement>",
98
+ "required": false,
99
+ "description": "Receives the visible trigger representing this action. Points to this button while inline and the ActionBar overflow button while this action is overflowing."
94
100
  }
95
101
  ],
96
102
  "passthrough": {
@@ -119,6 +125,12 @@
119
125
  "type": "boolean",
120
126
  "defaultValue": "",
121
127
  "description": "Provides a disabled state for the button. The button will remain focusable, and have `aria-disabled` applied."
128
+ },
129
+ {
130
+ "name": "activeAnchorRef",
131
+ "type": "React.Ref<HTMLButtonElement>",
132
+ "required": false,
133
+ "description": "Receives the visible trigger representing this action. Points to this button while inline and the ActionBar overflow button while this action is overflowing."
122
134
  }
123
135
  ],
124
136
  "passthrough": {
@@ -906,9 +918,9 @@
906
918
  },
907
919
  {
908
920
  "name": "renderAnchor",
909
- "type": "<T extends React.HTMLAttributes<HTMLElement>>(props: T) => JSX.Element",
921
+ "type": "<T extends React.HTMLAttributes<HTMLElement>>(props: T, anchorRef: React.RefCallback<HTMLElement>) => JSX.Element",
910
922
  "defaultValue": "",
911
- "description": "A custom function component used to render the anchor element. When renderAnchor is null, an anchorRef is required."
923
+ "description": "A custom function component used to render the anchor element. The second argument is a reactive ref for the current anchor element. When renderAnchor is null, an anchorRef is required."
912
924
  },
913
925
  {
914
926
  "name": "anchorRef",
@@ -9599,22 +9611,6 @@
9599
9611
  {
9600
9612
  "id": "experimental-components-underlinepanels-features--with-icons-hidden-on-narrow-screen",
9601
9613
  "code": "() => (\n <UnderlinePanels aria-label=\"Tabs with icons\">\n <UnderlinePanels.Tab icon={CodeIcon}>Tab 1</UnderlinePanels.Tab>\n <UnderlinePanels.Tab icon={EyeIcon}>Tab 2</UnderlinePanels.Tab>\n <UnderlinePanels.Tab icon={GitPullRequestIcon}>Tab 3</UnderlinePanels.Tab>\n <UnderlinePanels.Tab icon={CommentDiscussionIcon}>\n Tab 4\n </UnderlinePanels.Tab>\n <UnderlinePanels.Tab icon={PlayIcon}>Tab 5</UnderlinePanels.Tab>\n <UnderlinePanels.Tab icon={ProjectIcon}>Tab 6</UnderlinePanels.Tab>\n <UnderlinePanels.Tab icon={GraphIcon}>Tab 7</UnderlinePanels.Tab>\n <UnderlinePanels.Tab icon={GearIcon}>Tab 8</UnderlinePanels.Tab>\n <UnderlinePanels.Tab icon={ShieldLockIcon}>Tab 9</UnderlinePanels.Tab>\n <UnderlinePanels.Panel>Panel 1</UnderlinePanels.Panel>\n <UnderlinePanels.Panel>Panel 2</UnderlinePanels.Panel>\n <UnderlinePanels.Panel>Panel 3</UnderlinePanels.Panel>\n <UnderlinePanels.Panel>Panel 4</UnderlinePanels.Panel>\n <UnderlinePanels.Panel>Panel 5</UnderlinePanels.Panel>\n <UnderlinePanels.Panel>Panel 6</UnderlinePanels.Panel>\n <UnderlinePanels.Panel>Panel 7</UnderlinePanels.Panel>\n <UnderlinePanels.Panel>Panel 8</UnderlinePanels.Panel>\n <UnderlinePanels.Panel>Panel 9</UnderlinePanels.Panel>\n </UnderlinePanels>\n)"
9602
- },
9603
- {
9604
- "id": "experimental-components-underlinepanels-features--controlled",
9605
- "code": "() => {\n const [refType, setRefType] = useState('branch')\n return (\n <>\n <FlagState />\n <UnderlinePanels\n aria-label=\"Ref type\"\n value={refType}\n onChange={({ value }) => {\n action('onChange')({\n value,\n })\n setRefType(value)\n }}\n >\n <UnderlinePanels.Tab value=\"branch\" icon={GitBranchIcon}>\n Branches\n </UnderlinePanels.Tab>\n <UnderlinePanels.Tab value=\"tag\" icon={TagIcon}>\n Tags\n </UnderlinePanels.Tab>\n <UnderlinePanels.Panel value=\"branch\">\n Find or create a branch…\n </UnderlinePanels.Panel>\n <UnderlinePanels.Panel value=\"tag\">\n Search or create a new tag…\n </UnderlinePanels.Panel>\n </UnderlinePanels>\n <p>\n Selected ref type: <strong>{refType}</strong>\n </p>\n </>\n )\n}"
9606
- },
9607
- {
9608
- "id": "experimental-components-underlinepanels-features--uncontrolled",
9609
- "code": "() => (\n <>\n <FlagState />\n <UnderlinePanels\n aria-label=\"Ref type\"\n defaultValue=\"tag\"\n onChange={({ value }) => {\n action('onChange')({\n value,\n })\n }}\n >\n <UnderlinePanels.Tab value=\"branch\">Branches</UnderlinePanels.Tab>\n <UnderlinePanels.Tab value=\"tag\">Tags</UnderlinePanels.Tab>\n <UnderlinePanels.Panel value=\"branch\">\n Find or create a branch…\n </UnderlinePanels.Panel>\n <UnderlinePanels.Panel value=\"tag\">\n Search or create a new tag…\n </UnderlinePanels.Panel>\n </UnderlinePanels>\n </>\n)"
9610
- },
9611
- {
9612
- "id": "experimental-components-underlinepanels-features--manual-activation",
9613
- "code": "() => {\n const [refType, setRefType] = useState('branch')\n return (\n <>\n <FlagState />\n <p>\n With <code>activationMode=&quot;manual&quot;</code>, arrow keys only\n move focus; press Enter or Space (or click) to commit selection. Prefer\n this when switching tabs triggers async work like a fetch.\n </p>\n <UnderlinePanels\n aria-label=\"Ref type\"\n value={refType}\n activationMode=\"manual\"\n onChange={({ value }) => {\n action('onChange')({\n value,\n })\n setRefType(value)\n }}\n >\n <UnderlinePanels.Tab value=\"branch\">Branches</UnderlinePanels.Tab>\n <UnderlinePanels.Tab value=\"tag\">Tags</UnderlinePanels.Tab>\n <UnderlinePanels.Panel value=\"branch\">\n Find or create a branch…\n </UnderlinePanels.Panel>\n <UnderlinePanels.Panel value=\"tag\">\n Search or create a new tag…\n </UnderlinePanels.Panel>\n </UnderlinePanels>\n </>\n )\n}"
9614
- },
9615
- {
9616
- "id": "experimental-components-underlinepanels-features--in-overlay",
9617
- "code": "() => {\n const [open, setOpen] = useState(false)\n const [refType, setRefType] = useState('branch')\n return (\n <>\n <FlagState />\n <AnchoredOverlay\n open={open}\n onOpen={() => setOpen(true)}\n onClose={() => setOpen(false)}\n renderAnchor={(props) => <Button {...props}>Select ref type</Button>}\n overlayProps={{\n role: 'dialog',\n 'aria-modal': true,\n 'aria-label': 'Select a ref type',\n style: {\n width: '320px',\n },\n }}\n focusZoneSettings={{\n disabled: true,\n }}\n >\n <UnderlinePanels\n aria-label=\"Ref type\"\n value={refType}\n onChange={({ value }) => {\n action('onChange')({\n value,\n })\n setRefType(value)\n }}\n >\n <UnderlinePanels.Tab value=\"branch\">Branches</UnderlinePanels.Tab>\n <UnderlinePanels.Tab value=\"tag\">Tags</UnderlinePanels.Tab>\n <UnderlinePanels.Panel value=\"branch\">\n Find or create a branch…\n </UnderlinePanels.Panel>\n <UnderlinePanels.Panel value=\"tag\">\n Search or create a new tag…\n </UnderlinePanels.Panel>\n </UnderlinePanels>\n </AnchoredOverlay>\n </>\n )\n}"
9618
9614
  }
9619
9615
  ],
9620
9616
  "importPath": "@primer/react/experimental",
@@ -9631,30 +9627,6 @@
9631
9627
  "defaultValue": "",
9632
9628
  "description": "ID of the element containing the name for the tab list"
9633
9629
  },
9634
- {
9635
- "name": "value",
9636
- "type": "string",
9637
- "defaultValue": "",
9638
- "description": "The value of the selected tab, keyed to each `UnderlinePanels.Tab`/`UnderlinePanels.Panel` `value`. Provide this (with `onChange`) for a controlled component where the selected tab is the single source of truth. Requires the `primer_react_underline_panels_controlled` feature flag."
9639
- },
9640
- {
9641
- "name": "defaultValue",
9642
- "type": "string",
9643
- "defaultValue": "",
9644
- "description": "The value of the tab selected by default, for an uncontrolled component. Cannot be combined with `value`."
9645
- },
9646
- {
9647
- "name": "onChange",
9648
- "type": "({value}: {value: string}) => void",
9649
- "defaultValue": "",
9650
- "description": "Callback fired whenever the selected tab changes, for every selection method — pointer, Enter/Space, and Arrow/Home/End keys. Unlike `UnderlinePanels.Tab`'s `onSelect` (which only fires on click and Enter/Space), this makes the selected value usable as a single source of truth for data-driven tabs."
9651
- },
9652
- {
9653
- "name": "activationMode",
9654
- "type": "'automatic' | 'manual'",
9655
- "defaultValue": "'automatic'",
9656
- "description": "Controls how tabs are activated with the keyboard. `'automatic'` selects on focus (Arrow/Home/End select immediately); `'manual'` moves focus only and commits selection on Enter, Space, or click. Prefer `'manual'` when displaying a panel is not instant (e.g. it triggers a network request). Requires the `primer_react_underline_panels_controlled` feature flag."
9657
- },
9658
9630
  {
9659
9631
  "name": "children",
9660
9632
  "type": "Array<UnderlinePanels.Tab | UnderlinePanels.Panel>",
@@ -9685,12 +9657,6 @@
9685
9657
  {
9686
9658
  "name": "UnderlinePanels.Tab",
9687
9659
  "props": [
9688
- {
9689
- "name": "value",
9690
- "type": "string",
9691
- "defaultValue": "",
9692
- "description": "A value that uniquely identifies this tab, paired with the `UnderlinePanels.Panel` of the same `value`. Provide this to use domain values (e.g. `'branch'`) with the container's controlled `value`/`onChange` API. When omitted, tabs and panels are paired by DOM order."
9693
- },
9694
9660
  {
9695
9661
  "name": "aria-selected",
9696
9662
  "type": "| boolean | 'true' | 'false'",
@@ -9701,7 +9667,7 @@
9701
9667
  "name": "onSelect",
9702
9668
  "type": "(event) => void",
9703
9669
  "defaultValue": "",
9704
- "description": "The handler that gets called when the tab is selected. Note: this fires only on click and Enter/Space — not on arrow-key navigation. For a callback that fires for every selection method, use the container's `onChange` prop instead."
9670
+ "description": "The handler that gets called when the tab is selected"
9705
9671
  },
9706
9672
  {
9707
9673
  "name": "counter",
@@ -9719,14 +9685,7 @@
9719
9685
  },
9720
9686
  {
9721
9687
  "name": "UnderlinePanels.Panel",
9722
- "props": [
9723
- {
9724
- "name": "value",
9725
- "type": "string",
9726
- "defaultValue": "",
9727
- "description": "A value that uniquely identifies this panel, paired with the `UnderlinePanels.Tab` of the same `value`. When omitted, tabs and panels are paired by DOM order."
9728
- }
9729
- ],
9688
+ "props": [],
9730
9689
  "passthrough": {
9731
9690
  "element": "div",
9732
9691
  "url": "https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div#Attributes"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260814135639",
4
+ "version": "0.0.0-20260818135516",
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",