@primer/react 0.0.0-20260814130501 → 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.
- package/CHANGELOG.md +25 -2
- package/dist/ActionBar/ActionBar.d.ts +9 -5
- package/dist/ActionBar/ActionBar.js +549 -160
- package/dist/ActionBar/index.d.ts +1 -0
- package/dist/ActionList/Group-d89306a8.css +2 -0
- package/dist/ActionList/Group-d89306a8.css.map +1 -0
- package/dist/ActionList/Group.module.css.js +2 -2
- package/dist/ActionList/Heading.js +2 -1
- package/dist/ActionList/Item.js +282 -277
- package/dist/ActionList/LinkItem.js +11 -3
- package/dist/ActionList/index.d.ts +3 -0
- package/dist/ActionList/shared.d.ts +4 -0
- package/dist/AnchoredOverlay/AnchoredOverlay.d.ts +1 -1
- package/dist/AnchoredOverlay/AnchoredOverlay.js +84 -61
- package/dist/AvatarStack/{AvatarStack-9bb5649f.css → AvatarStack-e6a99916.css} +2 -2
- package/dist/AvatarStack/AvatarStack-e6a99916.css.map +1 -0
- package/dist/AvatarStack/AvatarStack.module.css.js +1 -1
- package/dist/CounterLabel/CounterLabel.js +5 -2
- package/dist/Details/Details.js +2 -1
- package/dist/Dialog/Dialog.js +3 -2
- package/dist/FeatureFlags/DefaultFeatureFlags.js +1 -2
- package/dist/NavList/NavList.d.ts +4 -2
- package/dist/NavList/NavList.js +87 -45
- package/dist/PageHeader/PageHeader.js +2 -1
- package/dist/Popover/Popover.d.ts +1 -0
- package/dist/Popover/Popover.js +84 -47
- package/dist/Portal/Portal.js +91 -29
- package/dist/Radio/Radio.js +1 -1
- package/dist/SelectPanel/SelectPanel.js +28 -27
- package/dist/ThemeContext.d.ts +20 -0
- package/dist/ThemeProvider.d.ts +3 -0
- package/dist/ThemeProvider.js +39 -129
- package/dist/TooltipV2/Tooltip.js +3 -2
- package/dist/TreeView/TreeView.js +0 -1
- package/dist/UnderlineNav/UnderlineNav.d.ts +3 -2
- package/dist/UnderlineNav/UnderlineNav.js +1 -1
- package/dist/deprecated/ActionList/List.js +2 -1
- package/dist/deprecated/ActionMenu.js +2 -2
- package/dist/experimental/SelectPanel2/SelectPanel.js +7 -4
- package/dist/experimental/Tabs/Tabs.js +19 -33
- package/dist/experimental/Tabs/types.d.ts +0 -6
- package/dist/experimental/Tabs/useTab.js +1 -6
- package/dist/experimental/Tabs/useTabList.js +22 -29
- package/dist/experimental/UnderlinePanels/UnderlinePanels.d.ts +1 -38
- package/dist/experimental/UnderlinePanels/UnderlinePanels.js +18 -69
- package/dist/hooks/useFocusZone.js +2 -1
- package/dist/hooks/useMenuInitialFocus.js +72 -57
- package/dist/hooks/useOpenAndCloseFocus.js +5 -2
- package/dist/internal/components/ThemeProviderBase.js +50 -0
- package/dist/internal/hooks/useThemeProvider.js +71 -0
- package/dist/legacy-theme/ts/color-schemes.js +3942 -3942
- package/dist/next/ThemeProvider.d.ts +7 -0
- package/dist/next/ThemeProvider.js +35 -0
- package/dist/next/index.d.ts +4 -1
- package/dist/next/index.js +3 -1
- package/dist/theme.d.ts +16 -54
- package/dist/useTheme.d.ts +2 -14
- package/generated/components.json +28 -58
- package/generated/hooks.json +2 -7
- package/package.json +8 -10
- package/dist/ActionList/Group-efcb39da.css +0 -2
- package/dist/ActionList/Group-efcb39da.css.map +0 -1
- package/dist/AvatarStack/AvatarStack-9bb5649f.css.map +0 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ColorMode, ColorModeWithAuto, Theme } from "./ThemeProvider.js";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/ThemeContext.d.ts
|
|
5
|
+
interface ThemeContextValue {
|
|
6
|
+
/** @deprecated Use `ThemeProvider` and `useTheme` from `@primer/react/next` to migrate away from JavaScript theme values. */
|
|
7
|
+
theme?: Theme;
|
|
8
|
+
colorScheme?: string;
|
|
9
|
+
colorMode?: ColorModeWithAuto;
|
|
10
|
+
resolvedColorMode?: ColorMode;
|
|
11
|
+
/** @deprecated Use `ThemeProvider` and `useTheme` from `@primer/react/next` to migrate away from JavaScript theme values. */
|
|
12
|
+
resolvedColorScheme?: string;
|
|
13
|
+
dayScheme?: string;
|
|
14
|
+
nightScheme?: string;
|
|
15
|
+
setColorMode: React.Dispatch<React.SetStateAction<ColorModeWithAuto>>;
|
|
16
|
+
setDayScheme: React.Dispatch<React.SetStateAction<string>>;
|
|
17
|
+
setNightScheme: React.Dispatch<React.SetStateAction<string>>;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { ThemeContextValue };
|
package/dist/ThemeProvider.d.ts
CHANGED
|
@@ -21,6 +21,9 @@ type ThemeProviderProps = {
|
|
|
21
21
|
*/
|
|
22
22
|
contextOnly?: boolean;
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Use `ThemeProvider` from `@primer/react/next` to migrate away from JavaScript theme values.
|
|
26
|
+
*/
|
|
24
27
|
declare const ThemeProvider: React.FC<React.PropsWithChildren<ThemeProviderProps>>;
|
|
25
28
|
//#endregion
|
|
26
29
|
export { ColorMode, ColorModeWithAuto, Theme, ThemeProvider, ThemeProvider as default, ThemeProviderProps };
|
package/dist/ThemeProvider.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import theme from "./theme.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useTheme } from "./useTheme.js";
|
|
2
|
+
import { ThemeProviderBase } from "./internal/components/ThemeProviderBase.js";
|
|
3
|
+
import { useThemeProvider } from "./internal/hooks/useThemeProvider.js";
|
|
5
4
|
import { c } from "react-compiler-runtime";
|
|
6
5
|
import { jsx } from "react/jsx-runtime";
|
|
7
|
-
import
|
|
6
|
+
import "react";
|
|
8
7
|
import deepmerge from "deepmerge";
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
//#region src/ThemeProvider.tsx
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use `ThemeProvider` from `@primer/react/next` to migrate away from JavaScript theme values.
|
|
11
|
+
*/
|
|
11
12
|
const ThemeProvider = (t0) => {
|
|
12
|
-
var
|
|
13
|
-
const $ = c(
|
|
13
|
+
var _parentValue$theme;
|
|
14
|
+
const $ = c(14);
|
|
14
15
|
let children;
|
|
15
16
|
let props;
|
|
16
17
|
if ($[0] !== t0) {
|
|
@@ -22,134 +23,43 @@ const ThemeProvider = (t0) => {
|
|
|
22
23
|
children = $[1];
|
|
23
24
|
props = $[2];
|
|
24
25
|
}
|
|
25
|
-
const {
|
|
26
|
-
const theme$1 =
|
|
27
|
-
const [colorMode, setColorMode] = useSyncedState((_ref = (_props$colorMode = props.colorMode) !== null && _props$colorMode !== void 0 ? _props$colorMode : fallbackColorMode) !== null && _ref !== void 0 ? _ref : "day");
|
|
28
|
-
const [dayScheme, setDayScheme] = useSyncedState((_ref2 = (_props$dayScheme = props.dayScheme) !== null && _props$dayScheme !== void 0 ? _props$dayScheme : fallbackDayScheme) !== null && _ref2 !== void 0 ? _ref2 : defaultDayScheme);
|
|
29
|
-
const [nightScheme, setNightScheme] = useSyncedState((_ref3 = (_props$nightScheme = props.nightScheme) !== null && _props$nightScheme !== void 0 ? _props$nightScheme : fallbackNightScheme) !== null && _ref3 !== void 0 ? _ref3 : defaultNightScheme);
|
|
30
|
-
const systemColorMode = useSystemColorMode();
|
|
31
|
-
let resolvedColorMode;
|
|
26
|
+
const { parentValue, value } = useThemeProvider(props);
|
|
27
|
+
const theme$1 = (_parentValue$theme = parentValue.theme) !== null && _parentValue$theme !== void 0 ? _parentValue$theme : theme;
|
|
32
28
|
let t1;
|
|
33
|
-
if ($[3] !==
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
$[
|
|
37
|
-
$[
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
$[7] = resolvedColorMode;
|
|
41
|
-
$[8] = t1;
|
|
42
|
-
} else {
|
|
43
|
-
resolvedColorMode = $[7];
|
|
44
|
-
t1 = $[8];
|
|
45
|
-
}
|
|
46
|
-
const colorScheme = t1;
|
|
29
|
+
if ($[3] !== theme$1 || $[4] !== value.colorScheme) {
|
|
30
|
+
t1 = applyColorScheme(theme$1, value.colorScheme);
|
|
31
|
+
$[3] = theme$1;
|
|
32
|
+
$[4] = value.colorScheme;
|
|
33
|
+
$[5] = t1;
|
|
34
|
+
} else t1 = $[5];
|
|
35
|
+
const { resolvedTheme, resolvedColorScheme } = t1;
|
|
47
36
|
let t2;
|
|
48
|
-
if ($[
|
|
49
|
-
t2 =
|
|
50
|
-
|
|
51
|
-
$[10] = theme$1;
|
|
52
|
-
$[11] = t2;
|
|
53
|
-
} else t2 = $[11];
|
|
54
|
-
const { resolvedTheme, resolvedColorScheme } = t2;
|
|
55
|
-
let t3;
|
|
56
|
-
if ($[12] !== colorMode || $[13] !== colorScheme || $[14] !== dayScheme || $[15] !== nightScheme || $[16] !== resolvedColorMode || $[17] !== resolvedColorScheme || $[18] !== resolvedTheme || $[19] !== setColorMode || $[20] !== setDayScheme || $[21] !== setNightScheme) {
|
|
57
|
-
t3 = {
|
|
37
|
+
if ($[6] !== resolvedColorScheme || $[7] !== resolvedTheme || $[8] !== value) {
|
|
38
|
+
t2 = {
|
|
39
|
+
...value,
|
|
58
40
|
theme: resolvedTheme,
|
|
59
|
-
|
|
60
|
-
colorMode,
|
|
61
|
-
resolvedColorMode,
|
|
62
|
-
resolvedColorScheme,
|
|
63
|
-
dayScheme,
|
|
64
|
-
nightScheme,
|
|
65
|
-
setColorMode,
|
|
66
|
-
setDayScheme,
|
|
67
|
-
setNightScheme
|
|
41
|
+
resolvedColorScheme
|
|
68
42
|
};
|
|
69
|
-
$[
|
|
70
|
-
$[
|
|
71
|
-
$[
|
|
72
|
-
$[
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
$[22] = t3;
|
|
80
|
-
} else t3 = $[22];
|
|
81
|
-
const contextValue = t3;
|
|
82
|
-
if (props.contextOnly) {
|
|
83
|
-
let t4;
|
|
84
|
-
if ($[23] !== children || $[24] !== contextValue) {
|
|
85
|
-
t4 = /*#__PURE__*/ jsx(ThemeContext.Provider, {
|
|
86
|
-
value: contextValue,
|
|
87
|
-
children
|
|
88
|
-
});
|
|
89
|
-
$[23] = children;
|
|
90
|
-
$[24] = contextValue;
|
|
91
|
-
$[25] = t4;
|
|
92
|
-
} else t4 = $[25];
|
|
93
|
-
return t4;
|
|
94
|
-
}
|
|
95
|
-
const t4 = colorMode === "auto" ? "auto" : colorScheme.includes("dark") ? "dark" : "light";
|
|
96
|
-
let t5;
|
|
97
|
-
if ($[26] !== children || $[27] !== dayScheme || $[28] !== nightScheme || $[29] !== t4) {
|
|
98
|
-
t5 = /*#__PURE__*/ jsx("div", {
|
|
99
|
-
"data-component": "ThemeProvider",
|
|
100
|
-
"data-color-mode": t4,
|
|
101
|
-
"data-light-theme": dayScheme,
|
|
102
|
-
"data-dark-theme": nightScheme,
|
|
103
|
-
children
|
|
104
|
-
});
|
|
105
|
-
$[26] = children;
|
|
106
|
-
$[27] = dayScheme;
|
|
107
|
-
$[28] = nightScheme;
|
|
108
|
-
$[29] = t4;
|
|
109
|
-
$[30] = t5;
|
|
110
|
-
} else t5 = $[30];
|
|
111
|
-
let t6;
|
|
112
|
-
if ($[31] !== contextValue || $[32] !== t5) {
|
|
113
|
-
t6 = /*#__PURE__*/ jsx(ThemeContext.Provider, {
|
|
43
|
+
$[6] = resolvedColorScheme;
|
|
44
|
+
$[7] = resolvedTheme;
|
|
45
|
+
$[8] = value;
|
|
46
|
+
$[9] = t2;
|
|
47
|
+
} else t2 = $[9];
|
|
48
|
+
const contextValue = t2;
|
|
49
|
+
let t3;
|
|
50
|
+
if ($[10] !== children || $[11] !== contextValue || $[12] !== props.contextOnly) {
|
|
51
|
+
t3 = /*#__PURE__*/ jsx(ThemeProviderBase, {
|
|
52
|
+
contextOnly: props.contextOnly,
|
|
114
53
|
value: contextValue,
|
|
115
|
-
children
|
|
54
|
+
children
|
|
116
55
|
});
|
|
117
|
-
$[
|
|
118
|
-
$[
|
|
119
|
-
$[
|
|
120
|
-
|
|
121
|
-
|
|
56
|
+
$[10] = children;
|
|
57
|
+
$[11] = contextValue;
|
|
58
|
+
$[12] = props.contextOnly;
|
|
59
|
+
$[13] = t3;
|
|
60
|
+
} else t3 = $[13];
|
|
61
|
+
return t3;
|
|
122
62
|
};
|
|
123
|
-
function subscribeToSystemColorMode(callback) {
|
|
124
|
-
var _window, _window$matchMedia;
|
|
125
|
-
const media = (_window = window) === null || _window === void 0 ? void 0 : (_window$matchMedia = _window.matchMedia) === null || _window$matchMedia === void 0 ? void 0 : _window$matchMedia.call(_window, "(prefers-color-scheme: dark)");
|
|
126
|
-
media === null || media === void 0 || media.addEventListener("change", callback);
|
|
127
|
-
return () => media === null || media === void 0 ? void 0 : media.removeEventListener("change", callback);
|
|
128
|
-
}
|
|
129
|
-
function useSystemColorMode() {
|
|
130
|
-
return React.useSyncExternalStore(subscribeToSystemColorMode, getSystemColorMode, _temp);
|
|
131
|
-
}
|
|
132
|
-
function _temp() {
|
|
133
|
-
return "day";
|
|
134
|
-
}
|
|
135
|
-
function getSystemColorMode() {
|
|
136
|
-
var _window2, _window2$matchMedia, _window2$matchMedia$c;
|
|
137
|
-
return (_window2 = window) !== null && _window2 !== void 0 && (_window2$matchMedia = _window2.matchMedia) !== null && _window2$matchMedia !== void 0 && (_window2$matchMedia$c = _window2$matchMedia.call(_window2, "(prefers-color-scheme: dark)")) !== null && _window2$matchMedia$c !== void 0 && _window2$matchMedia$c.matches ? "night" : "day";
|
|
138
|
-
}
|
|
139
|
-
function resolveColorMode(colorMode, systemColorMode) {
|
|
140
|
-
switch (colorMode) {
|
|
141
|
-
case "auto": return systemColorMode;
|
|
142
|
-
default: return colorMode;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
function chooseColorScheme(colorMode, dayScheme, nightScheme) {
|
|
146
|
-
switch (colorMode) {
|
|
147
|
-
case "day":
|
|
148
|
-
case "light": return dayScheme;
|
|
149
|
-
case "dark":
|
|
150
|
-
case "night": return nightScheme;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
63
|
function applyColorScheme(theme, colorScheme) {
|
|
154
64
|
if (!theme.colorSchemes) return {
|
|
155
65
|
resolvedTheme: theme,
|
|
@@ -100,10 +100,11 @@ const Tooltip = /*#__PURE__*/ React.forwardRef(({ direction = "s", text, type =
|
|
|
100
100
|
const trigger = readTriggerRef.current;
|
|
101
101
|
tooltip.showPopover();
|
|
102
102
|
setIsPopoverOpen(true);
|
|
103
|
-
const
|
|
103
|
+
const settings = {
|
|
104
104
|
side: directionToPosition[direction].side,
|
|
105
105
|
align: directionToPosition[direction].align
|
|
106
|
-
}
|
|
106
|
+
};
|
|
107
|
+
const { top, left, anchorAlign, anchorSide } = getAnchoredPosition(tooltip, trigger, settings);
|
|
107
108
|
const calculatedDirection = positionToDirection[`${anchorSide}-${anchorAlign}`];
|
|
108
109
|
setCalculatedDirection(calculatedDirection);
|
|
109
110
|
tooltip.style.top = `${top}px`;
|
|
@@ -17,8 +17,9 @@ type UnderlineNavProps = {
|
|
|
17
17
|
*/
|
|
18
18
|
variant?: 'inset' | 'flush';
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* Controls the container width below which icons are hidden to save space. Defaults to `medium`.
|
|
21
|
+
* To keep icons visible in a narrow container, use a smaller breakpoint such as `xsmall`, or set to `null` to
|
|
22
|
+
* always show icons.
|
|
22
23
|
*/
|
|
23
24
|
hideIconsBreakpoint?: 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge' | null;
|
|
24
25
|
};
|
|
@@ -22,7 +22,7 @@ const UnderlineNav = /*#__PURE__*/ forwardRef((t0, forwardedRef) => {
|
|
|
22
22
|
const as = t1 === void 0 ? "nav" : t1;
|
|
23
23
|
const loadingCounters = t2 === void 0 ? false : t2;
|
|
24
24
|
const variant = t3 === void 0 ? "inset" : t3;
|
|
25
|
-
const hideIconsBreakpoint = t4 === void 0 ? "
|
|
25
|
+
const hideIconsBreakpoint = t4 === void 0 ? "medium" : t4;
|
|
26
26
|
const backupRef = useRef(null);
|
|
27
27
|
const navRef = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
|
|
28
28
|
const listRef = useRef(null);
|
|
@@ -59,7 +59,8 @@ const List = /*#__PURE__*/ React.forwardRef((props, forwardedRef) => {
|
|
|
59
59
|
const { firstGroupStyle, lastGroupStyle, headerStyle, itemStyle } = useListVariant(restProps.variant);
|
|
60
60
|
const renderGroup = (groupProps) => {
|
|
61
61
|
var _ref;
|
|
62
|
-
|
|
62
|
+
const GroupComponent = ((_ref = "renderGroup" in groupProps && groupProps.renderGroup) !== null && _ref !== void 0 ? _ref : restProps.renderGroup) || Group;
|
|
63
|
+
return /*#__PURE__*/ createElement(GroupComponent, {
|
|
63
64
|
...groupProps,
|
|
64
65
|
key: groupProps.groupId
|
|
65
66
|
});
|
|
@@ -84,11 +84,11 @@ const ActionMenuBase = (t0) => {
|
|
|
84
84
|
}
|
|
85
85
|
let t5;
|
|
86
86
|
if ($[14] !== anchorContent || $[15] !== renderAnchor) {
|
|
87
|
-
t5 = (props) => renderAnchor({
|
|
87
|
+
t5 = (props, anchorRef_0) => renderAnchor({
|
|
88
88
|
"aria-label": "menu",
|
|
89
89
|
children: anchorContent,
|
|
90
90
|
...props
|
|
91
|
-
});
|
|
91
|
+
}, anchorRef_0);
|
|
92
92
|
$[14] = anchorContent;
|
|
93
93
|
$[15] = renderAnchor;
|
|
94
94
|
$[16] = t5;
|
|
@@ -43,10 +43,11 @@ const responsiveButtonSizes = {
|
|
|
43
43
|
const Panel = ({ title, description, variant: propsVariant, selectionVariant = "multiple", id, defaultOpen = false, open: propsOpen, anchorRef: providedAnchorRef, anchoredPositionSettings, onCancel: propsOnCancel, onClearSelection: propsOnClearSelection, onSubmit: propsOnSubmit, width = "medium", maxHeight = "large", className, ...props }) => {
|
|
44
44
|
var _position$top, _position$left, _slots$header;
|
|
45
45
|
const [internalOpen, setInternalOpen] = React.useState(defaultOpen);
|
|
46
|
-
const
|
|
46
|
+
const responsiveVariants = Object.assign({
|
|
47
47
|
regular: "anchored",
|
|
48
48
|
narrow: "full-screen"
|
|
49
|
-
}, typeof propsVariant === "string" ? { regular: propsVariant } : propsVariant)
|
|
49
|
+
}, typeof propsVariant === "string" ? { regular: propsVariant } : propsVariant);
|
|
50
|
+
const currentVariant = useResponsiveValue(responsiveVariants, "anchored");
|
|
50
51
|
if (propsOpen !== void 0 && internalOpen !== propsOpen) setInternalOpen(propsOpen);
|
|
51
52
|
let Anchor;
|
|
52
53
|
const anchorRef = useProvidedRefOrCreate(providedAnchorRef);
|
|
@@ -348,18 +349,20 @@ const SelectPanelFooter = ({ ...props }) => {
|
|
|
348
349
|
SelectPanelFooter.displayName = "SelectPanelFooter";
|
|
349
350
|
SelectPanelFooter.__SLOT__ = Symbol("SelectPanel.Footer");
|
|
350
351
|
const SecondaryButton = (props) => {
|
|
352
|
+
const size = useResponsiveValue(responsiveButtonSizes, "small");
|
|
351
353
|
return /*#__PURE__*/ jsx(ButtonComponent, {
|
|
352
354
|
type: "button",
|
|
353
|
-
size
|
|
355
|
+
size,
|
|
354
356
|
block: true,
|
|
355
357
|
...props
|
|
356
358
|
});
|
|
357
359
|
};
|
|
358
360
|
SecondaryButton.displayName = "SecondaryButton";
|
|
359
361
|
const SecondaryLink = ({ className, ...props }) => {
|
|
362
|
+
const size = useResponsiveValue(responsiveButtonSizes, "small");
|
|
360
363
|
return /*#__PURE__*/ jsx(ButtonComponent, {
|
|
361
364
|
as: Link,
|
|
362
|
-
size
|
|
365
|
+
size,
|
|
363
366
|
variant: "invisible",
|
|
364
367
|
block: true,
|
|
365
368
|
...props,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import useIsomorphicLayoutEffect from "../../utils/useIsomorphicLayoutEffect.js";
|
|
2
|
-
import { useFeatureFlag } from "../../FeatureFlags/useFeatureFlag.js";
|
|
3
2
|
import { useControllableState } from "../../hooks/useControllableState.js";
|
|
4
3
|
import { TabsContext } from "./TabsContext.js";
|
|
5
4
|
import { c } from "react-compiler-runtime";
|
|
@@ -14,13 +13,11 @@ import React, { useId } from "react";
|
|
|
14
13
|
* The `Tab`, `TabList`, and `TabPanel` components are provided for convenience to showcase the API & implementation.
|
|
15
14
|
*/
|
|
16
15
|
function Tabs(props) {
|
|
17
|
-
var _props$id, _props$
|
|
18
|
-
const $ = c(
|
|
16
|
+
var _props$id, _props$defaultValue;
|
|
17
|
+
const $ = c(13);
|
|
19
18
|
const { children, onValueChange } = props;
|
|
20
19
|
const generatedId = useId();
|
|
21
20
|
const groupId = (_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : generatedId;
|
|
22
|
-
const controlledApiEnabled = useFeatureFlag("primer_react_underline_panels_controlled");
|
|
23
|
-
const activationMode = controlledApiEnabled ? (_props$activationMode = props.activationMode) !== null && _props$activationMode !== void 0 ? _props$activationMode : "automatic" : "automatic";
|
|
24
21
|
const t0 = (_props$defaultValue = props.defaultValue) !== null && _props$defaultValue !== void 0 ? _props$defaultValue : props.value;
|
|
25
22
|
let t1;
|
|
26
23
|
if ($[0] !== props.value || $[1] !== t0) {
|
|
@@ -34,60 +31,49 @@ function Tabs(props) {
|
|
|
34
31
|
$[2] = t1;
|
|
35
32
|
} else t1 = $[2];
|
|
36
33
|
const [selectedValue, setSelectedValue] = useControllableState(t1);
|
|
37
|
-
const [focusedValue, setFocusedValue] = React.useState();
|
|
38
34
|
const savedOnValueChange = React.useRef(onValueChange);
|
|
39
35
|
let t2;
|
|
40
|
-
if ($[3] !==
|
|
36
|
+
if ($[3] !== groupId || $[4] !== selectedValue || $[5] !== setSelectedValue) {
|
|
41
37
|
t2 = {
|
|
42
38
|
groupId,
|
|
43
39
|
selectedValue,
|
|
44
|
-
activationMode,
|
|
45
|
-
focusedValue,
|
|
46
40
|
selectTab(value) {
|
|
47
41
|
var _savedOnValueChange$c;
|
|
48
|
-
setFocusedValue(void 0);
|
|
49
|
-
if (controlledApiEnabled && value === selectedValue) return;
|
|
50
42
|
setSelectedValue(value);
|
|
51
43
|
(_savedOnValueChange$c = savedOnValueChange.current) === null || _savedOnValueChange$c === void 0 || _savedOnValueChange$c.call(savedOnValueChange, { value });
|
|
52
|
-
},
|
|
53
|
-
focusTab(value_0) {
|
|
54
|
-
setFocusedValue(value_0);
|
|
55
44
|
}
|
|
56
45
|
};
|
|
57
|
-
$[3] =
|
|
58
|
-
$[4] =
|
|
59
|
-
$[5] =
|
|
60
|
-
$[6] =
|
|
61
|
-
|
|
62
|
-
$[8] = setSelectedValue;
|
|
63
|
-
$[9] = t2;
|
|
64
|
-
} else t2 = $[9];
|
|
46
|
+
$[3] = groupId;
|
|
47
|
+
$[4] = selectedValue;
|
|
48
|
+
$[5] = setSelectedValue;
|
|
49
|
+
$[6] = t2;
|
|
50
|
+
} else t2 = $[6];
|
|
65
51
|
const contextValue = t2;
|
|
66
52
|
let t3;
|
|
67
53
|
let t4;
|
|
68
|
-
if ($[
|
|
54
|
+
if ($[7] !== onValueChange) {
|
|
69
55
|
t3 = () => {
|
|
70
56
|
savedOnValueChange.current = onValueChange;
|
|
71
57
|
};
|
|
72
58
|
t4 = [onValueChange];
|
|
73
|
-
$[
|
|
74
|
-
$[
|
|
75
|
-
$[
|
|
59
|
+
$[7] = onValueChange;
|
|
60
|
+
$[8] = t3;
|
|
61
|
+
$[9] = t4;
|
|
76
62
|
} else {
|
|
77
|
-
t3 = $[
|
|
78
|
-
t4 = $[
|
|
63
|
+
t3 = $[8];
|
|
64
|
+
t4 = $[9];
|
|
79
65
|
}
|
|
80
66
|
useIsomorphicLayoutEffect(t3, t4);
|
|
81
67
|
let t5;
|
|
82
|
-
if ($[
|
|
68
|
+
if ($[10] !== children || $[11] !== contextValue) {
|
|
83
69
|
t5 = /*#__PURE__*/ jsx(TabsContext.Provider, {
|
|
84
70
|
value: contextValue,
|
|
85
71
|
children
|
|
86
72
|
});
|
|
87
|
-
$[
|
|
88
|
-
$[
|
|
89
|
-
$[
|
|
90
|
-
} else t5 = $[
|
|
73
|
+
$[10] = children;
|
|
74
|
+
$[11] = contextValue;
|
|
75
|
+
$[12] = t5;
|
|
76
|
+
} else t5 = $[12];
|
|
91
77
|
return t5;
|
|
92
78
|
}
|
|
93
79
|
//#endregion
|
|
@@ -51,12 +51,6 @@ type CommonTabsProps = {
|
|
|
51
51
|
* unique id is generated automatically.
|
|
52
52
|
*/
|
|
53
53
|
id?: string;
|
|
54
|
-
/**
|
|
55
|
-
* `'automatic'` (default) selects on focus, so Arrow/Home/End keys select immediately. `'manual'`
|
|
56
|
-
* only moves focus; selection commits on Enter/Space/click. Prefer `'manual'` when displaying a
|
|
57
|
-
* panel is not instant (e.g. it triggers a network request).
|
|
58
|
-
*/
|
|
59
|
-
activationMode?: 'automatic' | 'manual';
|
|
60
54
|
};
|
|
61
55
|
type TabsProps = PropsWithChildren<(ControlledTabsProps | UncontrolledTabsProps) & CommonTabsProps>;
|
|
62
56
|
type Label = {
|
|
@@ -12,7 +12,6 @@ function useTab(props) {
|
|
|
12
12
|
const selected = tabs.selectedValue === value;
|
|
13
13
|
const id = `${tabs.groupId}-tab-${value}`;
|
|
14
14
|
const panelId = `${tabs.groupId}-panel-${value}`;
|
|
15
|
-
const isTabStop = tabs.activationMode === "manual" && tabs.focusedValue !== void 0 ? tabs.focusedValue === value : selected;
|
|
16
15
|
let t0;
|
|
17
16
|
if ($[0] !== tabs || $[1] !== value) {
|
|
18
17
|
t0 = function onKeyDown(event) {
|
|
@@ -38,10 +37,6 @@ function useTab(props) {
|
|
|
38
37
|
let t2;
|
|
39
38
|
if ($[7] !== disabled || $[8] !== selected || $[9] !== tabs || $[10] !== value) {
|
|
40
39
|
t2 = function onFocus() {
|
|
41
|
-
if (tabs.activationMode === "manual") {
|
|
42
|
-
if (!disabled) tabs.focusTab(value);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
40
|
if (!selected && !disabled) tabs.selectTab(value);
|
|
46
41
|
};
|
|
47
42
|
$[7] = disabled;
|
|
@@ -52,7 +47,7 @@ function useTab(props) {
|
|
|
52
47
|
} else t2 = $[11];
|
|
53
48
|
const onFocus = t2;
|
|
54
49
|
const t3 = disabled ? true : void 0;
|
|
55
|
-
const t4 =
|
|
50
|
+
const t4 = selected ? 0 : -1;
|
|
56
51
|
let t5;
|
|
57
52
|
if ($[12] !== id || $[13] !== onFocus || $[14] !== onKeyDown || $[15] !== onMouseDown || $[16] !== panelId || $[17] !== selected || $[18] !== t3 || $[19] !== t4) {
|
|
58
53
|
t5 = { tabProps: {
|
|
@@ -5,29 +5,20 @@ import { c } from "react-compiler-runtime";
|
|
|
5
5
|
import { useRef } from "react";
|
|
6
6
|
//#region src/experimental/Tabs/useTabList.ts
|
|
7
7
|
function useTabList(props) {
|
|
8
|
-
const $ = c(
|
|
8
|
+
const $ = c(9);
|
|
9
9
|
const { "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, "aria-orientation": ariaOrientation } = props;
|
|
10
10
|
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
11
|
-
const controlledApiEnabled = useFeatureFlag("primer_react_underline_panels_controlled");
|
|
12
11
|
const tabListRef = useRef(null);
|
|
13
12
|
const mergedRef = useMergedRefs(tabListRef, props.ref);
|
|
14
13
|
const providedOrCreatedRef = useProvidedRefOrCreate(props.ref);
|
|
15
14
|
const readRef = mergedRefEnabled ? tabListRef : providedOrCreatedRef;
|
|
16
15
|
const appliedRef = mergedRefEnabled ? mergedRef : providedOrCreatedRef;
|
|
17
16
|
let t0;
|
|
18
|
-
if ($[0] !== ariaOrientation || $[1] !==
|
|
17
|
+
if ($[0] !== ariaOrientation || $[1] !== readRef) {
|
|
19
18
|
t0 = (event) => {
|
|
20
19
|
const { current: tablist } = readRef;
|
|
21
20
|
if (tablist === null) return;
|
|
22
21
|
const tabs = getFocusableTabs(tablist);
|
|
23
|
-
const getCurrentIndex = () => {
|
|
24
|
-
if (controlledApiEnabled) {
|
|
25
|
-
const activeElement = tablist.ownerDocument.activeElement;
|
|
26
|
-
const focusedIndex = activeElement instanceof HTMLElement ? tabs.indexOf(activeElement) : -1;
|
|
27
|
-
if (focusedIndex !== -1) return focusedIndex;
|
|
28
|
-
}
|
|
29
|
-
return tabs.findIndex(_temp);
|
|
30
|
-
};
|
|
31
22
|
const isVertical = ariaOrientation === "vertical";
|
|
32
23
|
const nextKey = isVertical ? "ArrowDown" : "ArrowRight";
|
|
33
24
|
const prevKey = isVertical ? "ArrowUp" : "ArrowLeft";
|
|
@@ -36,13 +27,13 @@ function useTabList(props) {
|
|
|
36
27
|
event.stopPropagation();
|
|
37
28
|
}
|
|
38
29
|
if (event.key === nextKey) {
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
41
|
-
tabs[(
|
|
30
|
+
const selectedTabIndex = tabs.findIndex(_temp);
|
|
31
|
+
if (selectedTabIndex === -1) return;
|
|
32
|
+
tabs[(selectedTabIndex + 1) % tabs.length].focus();
|
|
42
33
|
} else if (event.key === prevKey) {
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
tabs[(tabs.length +
|
|
34
|
+
const selectedTabIndex_0 = tabs.findIndex(_temp2);
|
|
35
|
+
if (selectedTabIndex_0 === -1) return;
|
|
36
|
+
tabs[(tabs.length + selectedTabIndex_0 - 1) % tabs.length].focus();
|
|
46
37
|
} else if (event.key === "Home") {
|
|
47
38
|
if (tabs[0]) tabs[0].focus();
|
|
48
39
|
} else if (event.key === "End") {
|
|
@@ -50,14 +41,13 @@ function useTabList(props) {
|
|
|
50
41
|
}
|
|
51
42
|
};
|
|
52
43
|
$[0] = ariaOrientation;
|
|
53
|
-
$[1] =
|
|
54
|
-
$[2] =
|
|
55
|
-
|
|
56
|
-
} else t0 = $[3];
|
|
44
|
+
$[1] = readRef;
|
|
45
|
+
$[2] = t0;
|
|
46
|
+
} else t0 = $[2];
|
|
57
47
|
const onKeyDown = t0;
|
|
58
48
|
const t1 = ariaOrientation !== null && ariaOrientation !== void 0 ? ariaOrientation : "horizontal";
|
|
59
49
|
let t2;
|
|
60
|
-
if ($[
|
|
50
|
+
if ($[3] !== appliedRef || $[4] !== ariaLabel || $[5] !== ariaLabelledby || $[6] !== onKeyDown || $[7] !== t1) {
|
|
61
51
|
t2 = { tabListProps: {
|
|
62
52
|
ref: appliedRef,
|
|
63
53
|
"aria-label": ariaLabel,
|
|
@@ -66,15 +56,18 @@ function useTabList(props) {
|
|
|
66
56
|
role: "tablist",
|
|
67
57
|
onKeyDown
|
|
68
58
|
} };
|
|
69
|
-
$[
|
|
70
|
-
$[
|
|
71
|
-
$[
|
|
72
|
-
$[
|
|
73
|
-
$[
|
|
74
|
-
$[
|
|
75
|
-
} else t2 = $[
|
|
59
|
+
$[3] = appliedRef;
|
|
60
|
+
$[4] = ariaLabel;
|
|
61
|
+
$[5] = ariaLabelledby;
|
|
62
|
+
$[6] = onKeyDown;
|
|
63
|
+
$[7] = t1;
|
|
64
|
+
$[8] = t2;
|
|
65
|
+
} else t2 = $[8];
|
|
76
66
|
return t2;
|
|
77
67
|
}
|
|
68
|
+
function _temp2(tab_0) {
|
|
69
|
+
return tab_0.getAttribute("aria-selected") === "true";
|
|
70
|
+
}
|
|
78
71
|
function _temp(tab) {
|
|
79
72
|
return tab.getAttribute("aria-selected") === "true";
|
|
80
73
|
}
|
|
@@ -16,31 +16,6 @@ type UnderlinePanelsProps = {
|
|
|
16
16
|
* ID of the element containing the name for the tab list
|
|
17
17
|
*/
|
|
18
18
|
'aria-labelledby'?: React.AriaAttributes['aria-labelledby'];
|
|
19
|
-
/**
|
|
20
|
-
* The value of the selected tab, keyed to each `UnderlinePanels.Tab`/`UnderlinePanels.Panel`
|
|
21
|
-
* `value`. Provide this (with `onChange`) for a controlled component where the selected tab is
|
|
22
|
-
* the single source of truth.
|
|
23
|
-
*/
|
|
24
|
-
value?: string;
|
|
25
|
-
/**
|
|
26
|
-
* The value of the tab that should be selected by default, keyed to each tab's `value`. Use this
|
|
27
|
-
* for an uncontrolled component. Cannot be combined with `value`.
|
|
28
|
-
*/
|
|
29
|
-
defaultValue?: string;
|
|
30
|
-
/**
|
|
31
|
-
* Fires whenever the selected tab changes, for every selection method including arrow keys.
|
|
32
|
-
* Unlike `UnderlinePanels.Tab`'s `onSelect`, which only fires on click and Enter/Space.
|
|
33
|
-
*/
|
|
34
|
-
onChange?: ({
|
|
35
|
-
value
|
|
36
|
-
}: {
|
|
37
|
-
value: string;
|
|
38
|
-
}) => void;
|
|
39
|
-
/**
|
|
40
|
-
* `'automatic'` (default) selects on focus/arrow keys; `'manual'` only moves focus until
|
|
41
|
-
* Enter/Space/click. Prefer `'manual'` when displaying a panel is not instant.
|
|
42
|
-
*/
|
|
43
|
-
activationMode?: 'automatic' | 'manual';
|
|
44
19
|
/**
|
|
45
20
|
* Custom string to use when generating the IDs of tabs and `aria-labelledby` for the panels
|
|
46
21
|
*/
|
|
@@ -59,12 +34,6 @@ type UnderlinePanelsProps = {
|
|
|
59
34
|
as?: React.ElementType;
|
|
60
35
|
};
|
|
61
36
|
type TabProps = PropsWithChildren<{
|
|
62
|
-
/**
|
|
63
|
-
* A value that uniquely identifies this tab, paired with the `UnderlinePanels.Panel` of the same
|
|
64
|
-
* `value`. Provide this to use domain values (e.g. `'branch'`) with the container's controlled
|
|
65
|
-
* `value`/`onChange` API. When omitted, tabs and panels are paired by their DOM order.
|
|
66
|
-
*/
|
|
67
|
-
value?: string;
|
|
68
37
|
/**
|
|
69
38
|
* Whether this is the selected tab
|
|
70
39
|
*/
|
|
@@ -82,13 +51,7 @@ type TabProps = PropsWithChildren<{
|
|
|
82
51
|
*/
|
|
83
52
|
icon?: FC<IconProps>;
|
|
84
53
|
}>;
|
|
85
|
-
type PanelProps = React.HTMLAttributes<HTMLDivElement
|
|
86
|
-
/**
|
|
87
|
-
* A value that uniquely identifies this panel, paired with the `UnderlinePanels.Tab` of the same
|
|
88
|
-
* `value`. When omitted, tabs and panels are paired by their DOM order.
|
|
89
|
-
*/
|
|
90
|
-
value?: string;
|
|
91
|
-
};
|
|
54
|
+
type PanelProps = React.HTMLAttributes<HTMLDivElement>;
|
|
92
55
|
declare const _default: React.FC<UnderlinePanelsProps> & SlotMarker & {
|
|
93
56
|
Panel: FCWithSlotMarker<PanelProps>;
|
|
94
57
|
Tab: FCWithSlotMarker<TabProps>;
|