@primer/react 0.0.0-20260722112739 → 0.0.0-20260722195949
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 +13 -9
- package/dist/ActionBar/ActionBar.js +4 -0
- package/dist/ActionBar/index.d.ts +4 -1
- package/dist/ActionList/Description.js +1 -0
- package/dist/ActionList/Divider.js +1 -0
- package/dist/ActionList/Group.js +1 -1
- package/dist/ActionList/List.js +20 -14
- package/dist/ActionList/TrailingAction.js +1 -0
- package/dist/AnchoredOverlay/AnchoredOverlay.js +6 -3
- package/dist/Autocomplete/AutocompleteInput.js +10 -7
- package/dist/Banner/Banner.js +2 -2
- package/dist/Blankslate/Blankslate.d.ts +15 -0
- package/dist/Blankslate/Blankslate.js +5 -0
- package/dist/ButtonGroup/ButtonGroup.js +15 -8
- package/dist/Checkbox/Checkbox.js +16 -9
- package/dist/DataTable/ErrorDialog.d.ts +3 -0
- package/dist/DataTable/ErrorDialog.js +1 -0
- package/dist/DataTable/Pagination.d.ts +3 -0
- package/dist/DataTable/Pagination.js +1 -0
- package/dist/DataTable/Table.d.ts +33 -0
- package/dist/DataTable/Table.js +13 -0
- package/dist/Details/Details.js +1 -1
- package/dist/Dialog/Dialog.js +12 -5
- package/dist/FeatureFlags/DefaultFeatureFlags.js +2 -1
- package/dist/FilteredActionList/FilteredActionList.js +31 -20
- package/dist/FilteredActionList/FilteredActionListInput.d.ts +4 -1
- package/dist/FilteredActionList/FilteredActionListInput.js +1 -0
- package/dist/FilteredActionList/FilteredActionListLoaders.d.ts +3 -0
- package/dist/FilteredActionList/FilteredActionListLoaders.js +1 -0
- package/dist/FormControl/FormControlCaption.d.ts +1 -0
- package/dist/FormControl/FormControlCaption.js +1 -0
- package/dist/FormControl/FormControlLabel.js +1 -0
- package/dist/FormControl/FormControlLeadingVisual.js +1 -0
- package/dist/Overlay/Overlay.js +1 -1
- package/dist/PageHeader/PageHeader.js +32 -23
- package/dist/PageLayout/PageLayout.js +2 -2
- package/dist/SegmentedControl/{SegmentedControl-a004561f.css → SegmentedControl-de65527b.css} +2 -2
- package/dist/SegmentedControl/{SegmentedControl-a004561f.css.map → SegmentedControl-de65527b.css.map} +1 -1
- package/dist/SegmentedControl/SegmentedControl.module.css.js +1 -1
- package/dist/SegmentedControl/SegmentedControlButton.js +2 -1
- package/dist/SegmentedControl/SegmentedControlIconButton.js +2 -1
- package/dist/SelectPanel/SelectPanel.d.ts +3 -0
- package/dist/SelectPanel/SelectPanel.js +2 -1
- package/dist/SelectPanel/SelectPanelMessage.js +1 -0
- package/dist/Stack/Stack.js +1 -0
- package/dist/TextInput/TextInput.js +13 -6
- package/dist/ThemeProvider.d.ts +4 -1
- package/dist/ThemeProvider.js +76 -43
- package/dist/Timeline/Timeline.js +3 -3
- package/dist/TooltipV2/Tooltip.js +19 -11
- package/dist/TopicTag/TopicTagGroup.d.ts +3 -0
- package/dist/TopicTag/TopicTagGroup.js +1 -0
- package/dist/experimental/Tabs/Tabs.js +3 -2
- package/dist/experimental/Tabs/types.d.ts +10 -3
- package/dist/experimental/Tabs/useTabList.js +18 -10
- package/dist/experimental/UnderlinePanels/UnderlinePanels.js +69 -42
- package/dist/experimental/index.js +5 -5
- package/dist/hooks/useMergedRefs.d.ts +4 -4
- package/dist/hooks/useMergedRefs.js +8 -5
- package/dist/hooks/useProvidedRefOrCreate.d.ts +7 -10
- package/dist/hooks/useProvidedRefOrCreate.js +7 -10
- package/dist/index.d.ts +2 -2
- package/dist/legacy-theme/ts/color-schemes.js +4252 -0
- package/dist/theme.d.ts +1142 -1
- package/dist/theme.js +3 -1
- package/dist/useTheme.d.ts +3 -1
- package/dist/utils/types/KeyPaths.d.ts +4 -0
- package/generated/hooks.json +15 -0
- package/package.json +4 -2
package/dist/Stack/Stack.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
1
2
|
import { useProvidedRefOrCreate } from "../hooks/useProvidedRefOrCreate.js";
|
|
2
3
|
import { AriaStatus } from "../live-region/AriaStatus.js";
|
|
4
|
+
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
3
5
|
import Text_default from "../Text/Text.js";
|
|
4
6
|
import _VisuallyHidden_module_css_default from "../_VisuallyHidden.module.css.js";
|
|
5
7
|
import VisuallyHidden from "../_VisuallyHidden.js";
|
|
@@ -11,14 +13,19 @@ import UnstyledTextInput from "../internal/components/UnstyledTextInput.js";
|
|
|
11
13
|
import { getCharacterCountState } from "../utils/character-counter.js";
|
|
12
14
|
import { clsx } from "clsx";
|
|
13
15
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
-
import React, { useCallback, useId, useState } from "react";
|
|
16
|
+
import React, { useCallback, useId, useRef, useState } from "react";
|
|
15
17
|
import { isValidElementType } from "react-is";
|
|
16
18
|
import { AlertFillIcon } from "@primer/octicons-react";
|
|
17
19
|
//#region src/TextInput/TextInput.tsx
|
|
18
20
|
const TextInput = /*#__PURE__*/ React.forwardRef(({ icon: IconComponent, leadingVisual: LeadingVisual, trailingVisual: TrailingVisual, trailingAction, block, className, contrast, disabled, loading, loaderPosition = "auto", loaderText = "Loading", monospace, validationStatus, size: sizeProp, onFocus, onBlur, variant: variantProp, width: widthProp, minWidth: minWidthProp, maxWidth: maxWidthProp, type = "text", required, characterLimit, onChange, value, defaultValue, "data-component": dataComponent, ...inputProps }, ref) => {
|
|
19
21
|
var _counter$isOverLimit;
|
|
20
22
|
const [isInputFocused, setIsInputFocused] = useState(false);
|
|
21
|
-
const
|
|
23
|
+
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
24
|
+
const inputRef = useRef(null);
|
|
25
|
+
const mergedRef = useMergedRefs(inputRef, ref);
|
|
26
|
+
const providedOrCreatedRef = useProvidedRefOrCreate(ref);
|
|
27
|
+
const readRef = mergedRefEnabled ? inputRef : providedOrCreatedRef;
|
|
28
|
+
const appliedRef = mergedRefEnabled ? mergedRef : providedOrCreatedRef;
|
|
22
29
|
const isControlled = value !== void 0;
|
|
23
30
|
const [uncontrolledLength, setUncontrolledLength] = useState(() => defaultValue !== void 0 ? String(defaultValue).length : 0);
|
|
24
31
|
const currentLength = isControlled ? String(value).length : uncontrolledLength;
|
|
@@ -29,9 +36,9 @@ const TextInput = /*#__PURE__*/ React.forwardRef(({ icon: IconComponent, leading
|
|
|
29
36
|
const showTrailingLoadingIndicator = loading && (loaderPosition === "trailing" || Boolean(loaderPosition === "auto" && !LeadingVisual));
|
|
30
37
|
const isSegmentedInputType = type === "date" || type === "time" || type === "datetime-local";
|
|
31
38
|
const focusInput = (e) => {
|
|
32
|
-
if (e.target !==
|
|
33
|
-
var
|
|
34
|
-
(
|
|
39
|
+
if (e.target !== readRef.current || !isSegmentedInputType) {
|
|
40
|
+
var _readRef$current;
|
|
41
|
+
(_readRef$current = readRef.current) === null || _readRef$current === void 0 || _readRef$current.focus();
|
|
35
42
|
}
|
|
36
43
|
};
|
|
37
44
|
const leadingVisualId = useId();
|
|
@@ -88,7 +95,7 @@ const TextInput = /*#__PURE__*/ React.forwardRef(({ icon: IconComponent, leading
|
|
|
88
95
|
children: typeof LeadingVisual !== "string" && isValidElementType(LeadingVisual) ? /*#__PURE__*/ jsx(LeadingVisual, {}) : LeadingVisual
|
|
89
96
|
}),
|
|
90
97
|
/*#__PURE__*/ jsx(UnstyledTextInput, {
|
|
91
|
-
ref:
|
|
98
|
+
ref: appliedRef,
|
|
92
99
|
disabled,
|
|
93
100
|
onFocus: handleInputFocus,
|
|
94
101
|
onBlur: handleInputBlur,
|
package/dist/ThemeProvider.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
3
|
//#region src/ThemeProvider.d.ts
|
|
4
|
+
type Theme = {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
4
7
|
type ColorMode = 'day' | 'night' | 'light' | 'dark';
|
|
5
8
|
type ColorModeWithAuto = ColorMode | 'auto';
|
|
6
9
|
type ThemeProviderProps = {
|
|
@@ -20,4 +23,4 @@ type ThemeProviderProps = {
|
|
|
20
23
|
};
|
|
21
24
|
declare const ThemeProvider: React.FC<React.PropsWithChildren<ThemeProviderProps>>;
|
|
22
25
|
//#endregion
|
|
23
|
-
export { ColorMode, ColorModeWithAuto, ThemeProvider, ThemeProvider as default, ThemeProviderProps };
|
|
26
|
+
export { ColorMode, ColorModeWithAuto, Theme, ThemeProvider, ThemeProvider as default, ThemeProviderProps };
|
package/dist/ThemeProvider.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import theme from "./theme.js";
|
|
1
2
|
import { useSyncedState } from "./hooks/useSyncedState.js";
|
|
2
3
|
import { ThemeContext } from "./ThemeContext.js";
|
|
3
4
|
import { useTheme } from "./useTheme.js";
|
|
4
5
|
import { c } from "react-compiler-runtime";
|
|
5
6
|
import { jsx } from "react/jsx-runtime";
|
|
6
7
|
import React from "react";
|
|
8
|
+
import deepmerge from "deepmerge";
|
|
7
9
|
const defaultDayScheme = "light";
|
|
8
10
|
const defaultNightScheme = "dark";
|
|
9
11
|
const ThemeProvider = (t0) => {
|
|
10
12
|
var _ref, _props$colorMode, _ref2, _props$dayScheme, _ref3, _props$nightScheme;
|
|
11
|
-
const $ = c(
|
|
13
|
+
const $ = c(34);
|
|
12
14
|
let children;
|
|
13
15
|
let props;
|
|
14
16
|
if ($[0] !== t0) {
|
|
@@ -20,7 +22,8 @@ const ThemeProvider = (t0) => {
|
|
|
20
22
|
children = $[1];
|
|
21
23
|
props = $[2];
|
|
22
24
|
}
|
|
23
|
-
const { colorMode: fallbackColorMode, dayScheme: fallbackDayScheme, nightScheme: fallbackNightScheme } = useTheme();
|
|
25
|
+
const { theme: fallbackTheme, colorMode: fallbackColorMode, dayScheme: fallbackDayScheme, nightScheme: fallbackNightScheme } = useTheme();
|
|
26
|
+
const theme$1 = fallbackTheme !== null && fallbackTheme !== void 0 ? fallbackTheme : theme;
|
|
24
27
|
const [colorMode, setColorMode] = useSyncedState((_ref = (_props$colorMode = props.colorMode) !== null && _props$colorMode !== void 0 ? _props$colorMode : fallbackColorMode) !== null && _ref !== void 0 ? _ref : "day");
|
|
25
28
|
const [dayScheme, setDayScheme] = useSyncedState((_ref2 = (_props$dayScheme = props.dayScheme) !== null && _props$dayScheme !== void 0 ? _props$dayScheme : fallbackDayScheme) !== null && _ref2 !== void 0 ? _ref2 : defaultDayScheme);
|
|
26
29
|
const [nightScheme, setNightScheme] = useSyncedState((_ref3 = (_props$nightScheme = props.nightScheme) !== null && _props$nightScheme !== void 0 ? _props$nightScheme : fallbackNightScheme) !== null && _ref3 !== void 0 ? _ref3 : defaultNightScheme);
|
|
@@ -42,68 +45,80 @@ const ThemeProvider = (t0) => {
|
|
|
42
45
|
}
|
|
43
46
|
const colorScheme = t1;
|
|
44
47
|
let t2;
|
|
45
|
-
if ($[9] !==
|
|
46
|
-
t2 =
|
|
48
|
+
if ($[9] !== colorScheme || $[10] !== theme$1) {
|
|
49
|
+
t2 = applyColorScheme(theme$1, colorScheme);
|
|
50
|
+
$[9] = colorScheme;
|
|
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 = {
|
|
58
|
+
theme: resolvedTheme,
|
|
47
59
|
colorScheme,
|
|
48
60
|
colorMode,
|
|
49
61
|
resolvedColorMode,
|
|
62
|
+
resolvedColorScheme,
|
|
50
63
|
dayScheme,
|
|
51
64
|
nightScheme,
|
|
52
65
|
setColorMode,
|
|
53
66
|
setDayScheme,
|
|
54
67
|
setNightScheme
|
|
55
68
|
};
|
|
56
|
-
$[
|
|
57
|
-
$[
|
|
58
|
-
$[
|
|
59
|
-
$[
|
|
60
|
-
$[
|
|
61
|
-
$[
|
|
62
|
-
$[
|
|
63
|
-
$[
|
|
64
|
-
$[
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
$[12] = colorMode;
|
|
70
|
+
$[13] = colorScheme;
|
|
71
|
+
$[14] = dayScheme;
|
|
72
|
+
$[15] = nightScheme;
|
|
73
|
+
$[16] = resolvedColorMode;
|
|
74
|
+
$[17] = resolvedColorScheme;
|
|
75
|
+
$[18] = resolvedTheme;
|
|
76
|
+
$[19] = setColorMode;
|
|
77
|
+
$[20] = setDayScheme;
|
|
78
|
+
$[21] = setNightScheme;
|
|
79
|
+
$[22] = t3;
|
|
80
|
+
} else t3 = $[22];
|
|
81
|
+
const contextValue = t3;
|
|
67
82
|
if (props.contextOnly) {
|
|
68
|
-
let
|
|
69
|
-
if ($[
|
|
70
|
-
|
|
83
|
+
let t4;
|
|
84
|
+
if ($[23] !== children || $[24] !== contextValue) {
|
|
85
|
+
t4 = /*#__PURE__*/ jsx(ThemeContext.Provider, {
|
|
71
86
|
value: contextValue,
|
|
72
87
|
children
|
|
73
88
|
});
|
|
74
|
-
$[
|
|
75
|
-
$[
|
|
76
|
-
$[
|
|
77
|
-
} else
|
|
78
|
-
return
|
|
89
|
+
$[23] = children;
|
|
90
|
+
$[24] = contextValue;
|
|
91
|
+
$[25] = t4;
|
|
92
|
+
} else t4 = $[25];
|
|
93
|
+
return t4;
|
|
79
94
|
}
|
|
80
|
-
const
|
|
81
|
-
let
|
|
82
|
-
if ($[
|
|
83
|
-
|
|
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", {
|
|
84
99
|
"data-component": "ThemeProvider",
|
|
85
|
-
"data-color-mode":
|
|
100
|
+
"data-color-mode": t4,
|
|
86
101
|
"data-light-theme": dayScheme,
|
|
87
102
|
"data-dark-theme": nightScheme,
|
|
88
103
|
children
|
|
89
104
|
});
|
|
90
|
-
$[
|
|
91
|
-
$[
|
|
92
|
-
$[
|
|
93
|
-
$[
|
|
94
|
-
$[
|
|
95
|
-
} else
|
|
96
|
-
let
|
|
97
|
-
if ($[
|
|
98
|
-
|
|
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, {
|
|
99
114
|
value: contextValue,
|
|
100
|
-
children:
|
|
115
|
+
children: t5
|
|
101
116
|
});
|
|
102
|
-
$[
|
|
103
|
-
$[
|
|
104
|
-
$[
|
|
105
|
-
} else
|
|
106
|
-
return
|
|
117
|
+
$[31] = contextValue;
|
|
118
|
+
$[32] = t5;
|
|
119
|
+
$[33] = t6;
|
|
120
|
+
} else t6 = $[33];
|
|
121
|
+
return t6;
|
|
107
122
|
};
|
|
108
123
|
function subscribeToSystemColorMode(callback) {
|
|
109
124
|
var _window, _window$matchMedia;
|
|
@@ -135,5 +150,23 @@ function chooseColorScheme(colorMode, dayScheme, nightScheme) {
|
|
|
135
150
|
case "night": return nightScheme;
|
|
136
151
|
}
|
|
137
152
|
}
|
|
153
|
+
function applyColorScheme(theme, colorScheme) {
|
|
154
|
+
if (!theme.colorSchemes) return {
|
|
155
|
+
resolvedTheme: theme,
|
|
156
|
+
resolvedColorScheme: void 0
|
|
157
|
+
};
|
|
158
|
+
if (!theme.colorSchemes[colorScheme]) {
|
|
159
|
+
console.error(`\`${colorScheme}\` scheme not defined in \`theme.colorSchemes\``);
|
|
160
|
+
const defaultColorScheme = Object.keys(theme.colorSchemes)[0];
|
|
161
|
+
return {
|
|
162
|
+
resolvedTheme: deepmerge(theme, theme.colorSchemes[defaultColorScheme]),
|
|
163
|
+
resolvedColorScheme: defaultColorScheme
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
resolvedTheme: deepmerge(theme, theme.colorSchemes[colorScheme]),
|
|
168
|
+
resolvedColorScheme: colorScheme
|
|
169
|
+
};
|
|
170
|
+
}
|
|
138
171
|
//#endregion
|
|
139
172
|
export { ThemeProvider, ThemeProvider as default };
|
|
@@ -152,7 +152,7 @@ const TimelineItem = /*#__PURE__*/ React.forwardRef((t0, forwardRef) => {
|
|
|
152
152
|
} else t5 = $[17];
|
|
153
153
|
return t5;
|
|
154
154
|
});
|
|
155
|
-
TimelineItem.displayName = "
|
|
155
|
+
TimelineItem.displayName = "Timeline.Item";
|
|
156
156
|
const TimelineBadge = (t0) => {
|
|
157
157
|
const $ = c(10);
|
|
158
158
|
let className;
|
|
@@ -226,7 +226,7 @@ const TimelineBody = /*#__PURE__*/ React.forwardRef((t0, forwardRef) => {
|
|
|
226
226
|
} else t2 = $[8];
|
|
227
227
|
return t2;
|
|
228
228
|
});
|
|
229
|
-
TimelineBody.displayName = "
|
|
229
|
+
TimelineBody.displayName = "Timeline.Body";
|
|
230
230
|
const TimelineBreak = /*#__PURE__*/ React.forwardRef((t0, forwardRef) => {
|
|
231
231
|
const $ = c(15);
|
|
232
232
|
let className;
|
|
@@ -285,7 +285,7 @@ const TimelineBreak = /*#__PURE__*/ React.forwardRef((t0, forwardRef) => {
|
|
|
285
285
|
} else t4 = $[14];
|
|
286
286
|
return t4;
|
|
287
287
|
});
|
|
288
|
-
TimelineBreak.displayName = "
|
|
288
|
+
TimelineBreak.displayName = "Timeline.Break";
|
|
289
289
|
const TimelineActions = /*#__PURE__*/ React.forwardRef((t0, forwardRef) => {
|
|
290
290
|
const $ = c(9);
|
|
291
291
|
let className;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
1
2
|
import { useProvidedRefOrCreate } from "../hooks/useProvidedRefOrCreate.js";
|
|
2
3
|
import { useOnEscapePress } from "../hooks/useOnEscapePress.js";
|
|
3
4
|
import { useId as useId$1 } from "../hooks/useId.js";
|
|
4
5
|
import { warning } from "../utils/warning.js";
|
|
6
|
+
import { useFeatureFlag } from "../FeatureFlags/useFeatureFlag.js";
|
|
5
7
|
import { invariant } from "../utils/invariant.js";
|
|
6
8
|
import Tooltip_module_css_default from "./Tooltip.module.css.js";
|
|
7
9
|
import VisuallyHidden from "../_VisuallyHidden.js";
|
|
@@ -80,7 +82,12 @@ const emptyKeybindingHints = [];
|
|
|
80
82
|
const Tooltip = /*#__PURE__*/ React.forwardRef(({ direction = "s", text, type = "description", children, id, className, keybindingHint = emptyKeybindingHints, delay = "short", _privateDisableTooltip = false, ...rest }, forwardedRef) => {
|
|
81
83
|
const tooltipId = useId$1(id);
|
|
82
84
|
const child = Children.only(children);
|
|
83
|
-
const
|
|
85
|
+
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
86
|
+
const triggerRef = useRef(null);
|
|
87
|
+
const mergedTriggerRef = useMergedRefs(triggerRef, forwardedRef);
|
|
88
|
+
const providedOrCreatedRef = useProvidedRefOrCreate(forwardedRef);
|
|
89
|
+
const readTriggerRef = mergedRefEnabled ? triggerRef : providedOrCreatedRef;
|
|
90
|
+
const appliedTriggerRef = mergedRefEnabled ? mergedTriggerRef : providedOrCreatedRef;
|
|
84
91
|
const tooltipElRef = useRef(null);
|
|
85
92
|
const [calculatedDirection, setCalculatedDirection] = useState(direction);
|
|
86
93
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
|
@@ -88,9 +95,9 @@ const Tooltip = /*#__PURE__*/ React.forwardRef(({ direction = "s", text, type =
|
|
|
88
95
|
const { safeSetTimeout, safeClearTimeout } = useSafeTimeout();
|
|
89
96
|
const openTooltip = () => {
|
|
90
97
|
try {
|
|
91
|
-
if (tooltipElRef.current &&
|
|
98
|
+
if (tooltipElRef.current && readTriggerRef.current && tooltipElRef.current.hasAttribute("popover") && !tooltipElRef.current.matches(":popover-open") && !_privateDisableTooltip) {
|
|
92
99
|
const tooltip = tooltipElRef.current;
|
|
93
|
-
const trigger =
|
|
100
|
+
const trigger = readTriggerRef.current;
|
|
94
101
|
tooltip.showPopover();
|
|
95
102
|
setIsPopoverOpen(true);
|
|
96
103
|
const { top, left, anchorAlign, anchorSide } = getAnchoredPosition(tooltip, trigger, {
|
|
@@ -112,7 +119,7 @@ const Tooltip = /*#__PURE__*/ React.forwardRef(({ direction = "s", text, type =
|
|
|
112
119
|
openTimeoutRef.current = null;
|
|
113
120
|
}
|
|
114
121
|
try {
|
|
115
|
-
if (tooltipElRef.current &&
|
|
122
|
+
if (tooltipElRef.current && readTriggerRef.current && tooltipElRef.current.hasAttribute("popover") && tooltipElRef.current.matches(":popover-open")) {
|
|
116
123
|
tooltipElRef.current.hidePopover();
|
|
117
124
|
setIsPopoverOpen(false);
|
|
118
125
|
} else setIsPopoverOpen(false);
|
|
@@ -122,16 +129,16 @@ const Tooltip = /*#__PURE__*/ React.forwardRef(({ direction = "s", text, type =
|
|
|
122
129
|
};
|
|
123
130
|
const value = useMemo(() => ({ tooltipId }), [tooltipId]);
|
|
124
131
|
useEffect(() => {
|
|
125
|
-
if (!tooltipElRef.current || !
|
|
126
|
-
const isTriggerInteractive = isInteractive(
|
|
127
|
-
const triggerChildren =
|
|
132
|
+
if (!tooltipElRef.current || !readTriggerRef.current) return;
|
|
133
|
+
const isTriggerInteractive = isInteractive(readTriggerRef.current);
|
|
134
|
+
const triggerChildren = readTriggerRef.current.childNodes;
|
|
128
135
|
const hasInteractiveDescendant = Array.from(triggerChildren).some((child) => {
|
|
129
136
|
return child instanceof HTMLElement && isInteractive(child) || Array.from(child.childNodes).some((grandChild) => grandChild instanceof HTMLElement && isInteractive(grandChild));
|
|
130
137
|
});
|
|
131
138
|
!(isTriggerInteractive || hasInteractiveDescendant) && invariant(false, "The `Tooltip` component expects a single React element that contains interactive content. Consider using a `<button>` or equivalent interactive element instead.");
|
|
132
139
|
if (type === "label") {
|
|
133
|
-
const hasAriaLabel =
|
|
134
|
-
const hasAriaLabelInChildren = Array.from(
|
|
140
|
+
const hasAriaLabel = readTriggerRef.current.hasAttribute("aria-label");
|
|
141
|
+
const hasAriaLabelInChildren = Array.from(readTriggerRef.current.childNodes).some((child) => child instanceof HTMLElement && child.hasAttribute("aria-label"));
|
|
135
142
|
warning(hasAriaLabel || hasAriaLabelInChildren, "The label type `Tooltip` is going to be used here to label the trigger element. Please remove the aria-label from the trigger element.");
|
|
136
143
|
}
|
|
137
144
|
if (typeof window !== "undefined") {
|
|
@@ -140,7 +147,7 @@ const Tooltip = /*#__PURE__*/ React.forwardRef(({ direction = "s", text, type =
|
|
|
140
147
|
tooltipElRef.current.setAttribute("popover", "auto");
|
|
141
148
|
}, [
|
|
142
149
|
tooltipElRef,
|
|
143
|
-
|
|
150
|
+
readTriggerRef,
|
|
144
151
|
direction,
|
|
145
152
|
type
|
|
146
153
|
]);
|
|
@@ -157,7 +164,7 @@ const Tooltip = /*#__PURE__*/ React.forwardRef(({ direction = "s", text, type =
|
|
|
157
164
|
return /*#__PURE__*/ jsx(TooltipContext.Provider, {
|
|
158
165
|
value,
|
|
159
166
|
children: /*#__PURE__*/ jsxs(Fragment, { children: [/*#__PURE__*/ React.isValidElement(child) && /*#__PURE__*/ React.cloneElement(child, {
|
|
160
|
-
ref:
|
|
167
|
+
ref: appliedTriggerRef,
|
|
161
168
|
"aria-describedby": (() => {
|
|
162
169
|
if (type !== "description") return child.props["aria-describedby"];
|
|
163
170
|
const existingDescribedBy = child.props["aria-describedby"];
|
|
@@ -229,6 +236,7 @@ const Tooltip = /*#__PURE__*/ React.forwardRef(({ direction = "s", text, type =
|
|
|
229
236
|
})] })
|
|
230
237
|
});
|
|
231
238
|
});
|
|
239
|
+
Tooltip.displayName = "Tooltip";
|
|
232
240
|
Tooltip.__SLOT__ = Symbol("Tooltip");
|
|
233
241
|
//#endregion
|
|
234
242
|
export { Tooltip };
|
|
@@ -13,10 +13,11 @@ import React, { useId } from "react";
|
|
|
13
13
|
* The `Tab`, `TabList`, and `TabPanel` components are provided for convenience to showcase the API & implementation.
|
|
14
14
|
*/
|
|
15
15
|
function Tabs(props) {
|
|
16
|
-
var _props$defaultValue;
|
|
16
|
+
var _props$id, _props$defaultValue;
|
|
17
17
|
const $ = c(13);
|
|
18
18
|
const { children, onValueChange } = props;
|
|
19
|
-
const
|
|
19
|
+
const generatedId = useId();
|
|
20
|
+
const groupId = (_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : generatedId;
|
|
20
21
|
const t0 = (_props$defaultValue = props.defaultValue) !== null && _props$defaultValue !== void 0 ? _props$defaultValue : props.value;
|
|
21
22
|
let t1;
|
|
22
23
|
if ($[0] !== props.value || $[1] !== t0) {
|
|
@@ -45,7 +45,14 @@ type UncontrolledTabsProps = {
|
|
|
45
45
|
value: string;
|
|
46
46
|
}) => void;
|
|
47
47
|
};
|
|
48
|
-
type
|
|
48
|
+
type CommonTabsProps = {
|
|
49
|
+
/**
|
|
50
|
+
* Optional id used as the base for generated tab and panel ids. If omitted, a
|
|
51
|
+
* unique id is generated automatically.
|
|
52
|
+
*/
|
|
53
|
+
id?: string;
|
|
54
|
+
};
|
|
55
|
+
type TabsProps = PropsWithChildren<(ControlledTabsProps | UncontrolledTabsProps) & CommonTabsProps>;
|
|
49
56
|
type Label = {
|
|
50
57
|
'aria-label': string;
|
|
51
58
|
};
|
|
@@ -73,7 +80,7 @@ type TabPanelProps = {
|
|
|
73
80
|
value: string;
|
|
74
81
|
};
|
|
75
82
|
type TabListHookProps<T extends HTMLElement> = TabListProps & {
|
|
76
|
-
/** Optional ref to use for the tablist. If none is provided, one will be generated automatically */ref?: React.
|
|
83
|
+
/** Optional ref to use for the tablist. If none is provided, one will be generated automatically */ref?: React.Ref<T | null>;
|
|
77
84
|
};
|
|
78
85
|
type TabListHookResult<T extends HTMLElement> = {
|
|
79
86
|
/** Props to be spread onto the tablist element */tabListProps: {
|
|
@@ -81,7 +88,7 @@ type TabListHookResult<T extends HTMLElement> = {
|
|
|
81
88
|
'aria-orientation': AriaAttributes['aria-orientation'];
|
|
82
89
|
'aria-label': AriaAttributes['aria-label'];
|
|
83
90
|
'aria-labelledby': AriaAttributes['aria-labelledby'];
|
|
84
|
-
ref: React.
|
|
91
|
+
ref: React.Ref<T | null>;
|
|
85
92
|
role: 'tablist';
|
|
86
93
|
};
|
|
87
94
|
};
|
|
@@ -1,14 +1,22 @@
|
|
|
1
|
+
import { useMergedRefs } from "../../hooks/useMergedRefs.js";
|
|
1
2
|
import { useProvidedRefOrCreate } from "../../hooks/useProvidedRefOrCreate.js";
|
|
3
|
+
import { useFeatureFlag } from "../../FeatureFlags/useFeatureFlag.js";
|
|
2
4
|
import { c } from "react-compiler-runtime";
|
|
5
|
+
import { useRef } from "react";
|
|
3
6
|
//#region src/experimental/Tabs/useTabList.ts
|
|
4
7
|
function useTabList(props) {
|
|
5
8
|
const $ = c(9);
|
|
6
9
|
const { "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, "aria-orientation": ariaOrientation } = props;
|
|
7
|
-
const
|
|
10
|
+
const mergedRefEnabled = useFeatureFlag("primer_react_merged_forwarded_refs");
|
|
11
|
+
const tabListRef = useRef(null);
|
|
12
|
+
const mergedRef = useMergedRefs(tabListRef, props.ref);
|
|
13
|
+
const providedOrCreatedRef = useProvidedRefOrCreate(props.ref);
|
|
14
|
+
const readRef = mergedRefEnabled ? tabListRef : providedOrCreatedRef;
|
|
15
|
+
const appliedRef = mergedRefEnabled ? mergedRef : providedOrCreatedRef;
|
|
8
16
|
let t0;
|
|
9
|
-
if ($[0] !== ariaOrientation || $[1] !==
|
|
17
|
+
if ($[0] !== ariaOrientation || $[1] !== readRef) {
|
|
10
18
|
t0 = (event) => {
|
|
11
|
-
const { current: tablist } =
|
|
19
|
+
const { current: tablist } = readRef;
|
|
12
20
|
if (tablist === null) return;
|
|
13
21
|
const tabs = getFocusableTabs(tablist);
|
|
14
22
|
const isVertical = ariaOrientation === "vertical";
|
|
@@ -33,25 +41,25 @@ function useTabList(props) {
|
|
|
33
41
|
}
|
|
34
42
|
};
|
|
35
43
|
$[0] = ariaOrientation;
|
|
36
|
-
$[1] =
|
|
44
|
+
$[1] = readRef;
|
|
37
45
|
$[2] = t0;
|
|
38
46
|
} else t0 = $[2];
|
|
39
47
|
const onKeyDown = t0;
|
|
40
48
|
const t1 = ariaOrientation !== null && ariaOrientation !== void 0 ? ariaOrientation : "horizontal";
|
|
41
49
|
let t2;
|
|
42
|
-
if ($[3] !==
|
|
50
|
+
if ($[3] !== appliedRef || $[4] !== ariaLabel || $[5] !== ariaLabelledby || $[6] !== onKeyDown || $[7] !== t1) {
|
|
43
51
|
t2 = { tabListProps: {
|
|
44
|
-
ref,
|
|
52
|
+
ref: appliedRef,
|
|
45
53
|
"aria-label": ariaLabel,
|
|
46
54
|
"aria-labelledby": ariaLabelledby,
|
|
47
55
|
"aria-orientation": t1,
|
|
48
56
|
role: "tablist",
|
|
49
57
|
onKeyDown
|
|
50
58
|
} };
|
|
51
|
-
$[3] =
|
|
52
|
-
$[4] =
|
|
53
|
-
$[5] =
|
|
54
|
-
$[6] =
|
|
59
|
+
$[3] = appliedRef;
|
|
60
|
+
$[4] = ariaLabel;
|
|
61
|
+
$[5] = ariaLabelledby;
|
|
62
|
+
$[6] = onKeyDown;
|
|
55
63
|
$[7] = t1;
|
|
56
64
|
$[8] = t2;
|
|
57
65
|
} else t2 = $[8];
|