@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
|
@@ -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,
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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
|
|
78
|
-
const
|
|
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 (
|
|
53
|
+
if (selectedFromProps !== prevSelectedFromProps) {
|
|
85
54
|
setPrevSelectedFromProps(selectedFromProps);
|
|
86
|
-
if (selectedFromProps !== void 0 && 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
|
|
120
|
-
|
|
121
|
-
|
|
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:
|
|
141
|
-
|
|
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,
|
|
@@ -5,7 +5,8 @@ import { FocusKeys as FocusKeys$1, focusZone } from "@primer/behaviors";
|
|
|
5
5
|
function useFocusZone(settings = {}, dependencies = []) {
|
|
6
6
|
const containerRef = useProvidedRefOrCreate(settings.containerRef);
|
|
7
7
|
const useActiveDescendant = !!settings.activeDescendantFocus;
|
|
8
|
-
const
|
|
8
|
+
const passedActiveDescendantRef = typeof settings.activeDescendantFocus === "boolean" || !settings.activeDescendantFocus ? void 0 : settings.activeDescendantFocus;
|
|
9
|
+
const activeDescendantControlRef = useProvidedRefOrCreate(passedActiveDescendantRef);
|
|
9
10
|
const disabled = settings.disabled;
|
|
10
11
|
const abortController = React.useRef();
|
|
11
12
|
useEffect(() => {
|
|
@@ -1,68 +1,83 @@
|
|
|
1
|
+
import { c } from "react-compiler-runtime";
|
|
1
2
|
import React from "react";
|
|
2
3
|
import { iterateFocusableElements } from "@primer/behaviors/utils";
|
|
3
4
|
//#region src/hooks/useMenuInitialFocus.ts
|
|
4
5
|
const useMenuInitialFocus = (open, containerRef, anchorRef) => {
|
|
5
|
-
|
|
6
|
-
* We need to pick the first element to focus based on how the menu was opened,
|
|
7
|
-
* however, we need to wait for the menu to be open to set focus.
|
|
8
|
-
* This is why we use set openingKey in state and have 2 effects
|
|
9
|
-
*/
|
|
6
|
+
const $ = c(9);
|
|
10
7
|
const [openingGesture, setOpeningGesture] = React.useState(void 0);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
let t0;
|
|
9
|
+
let t1;
|
|
10
|
+
if ($[0] !== anchorRef) {
|
|
11
|
+
t0 = function inferOpeningKey() {
|
|
12
|
+
const anchorElement = anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current;
|
|
13
|
+
const clickHandler = (event) => {
|
|
14
|
+
if (event.detail !== 0) setOpeningGesture("mouse-click");
|
|
15
|
+
};
|
|
16
|
+
const keydownHandler = (event_0) => {
|
|
17
|
+
if ([
|
|
18
|
+
"Space",
|
|
19
|
+
"Enter",
|
|
20
|
+
"ArrowDown",
|
|
21
|
+
"ArrowUp"
|
|
22
|
+
].includes(event_0.code)) setOpeningGesture(event_0.code);
|
|
23
|
+
};
|
|
24
|
+
anchorElement === null || anchorElement === void 0 || anchorElement.addEventListener("click", clickHandler);
|
|
25
|
+
anchorElement === null || anchorElement === void 0 || anchorElement.addEventListener("keydown", keydownHandler);
|
|
26
|
+
return () => {
|
|
27
|
+
anchorElement === null || anchorElement === void 0 || anchorElement.removeEventListener("click", clickHandler);
|
|
28
|
+
anchorElement === null || anchorElement === void 0 || anchorElement.removeEventListener("keydown", keydownHandler);
|
|
29
|
+
};
|
|
15
30
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
31
|
+
t1 = [anchorRef];
|
|
32
|
+
$[0] = anchorRef;
|
|
33
|
+
$[1] = t0;
|
|
34
|
+
$[2] = t1;
|
|
35
|
+
} else {
|
|
36
|
+
t0 = $[1];
|
|
37
|
+
t1 = $[2];
|
|
38
|
+
}
|
|
39
|
+
React.useEffect(t0, t1);
|
|
40
|
+
let t2;
|
|
41
|
+
let t3;
|
|
42
|
+
if ($[3] !== anchorRef || $[4] !== containerRef || $[5] !== open || $[6] !== openingGesture) {
|
|
43
|
+
t2 = function moveFocusOnOpen() {
|
|
44
|
+
if (!open || !(containerRef !== null && containerRef !== void 0 && containerRef.current)) return;
|
|
45
|
+
const iterable = iterateFocusableElements(containerRef.current);
|
|
46
|
+
if (openingGesture === "mouse-click") if (anchorRef !== null && anchorRef !== void 0 && anchorRef.current) anchorRef.current.focus();
|
|
47
|
+
else throw new Error("For focus management, please attach anchorRef");
|
|
48
|
+
else if (openingGesture && [
|
|
20
49
|
"ArrowDown",
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
50
|
+
"Space",
|
|
51
|
+
"Enter"
|
|
52
|
+
].includes(openingGesture)) {
|
|
53
|
+
const firstElement = iterable.next().value;
|
|
54
|
+
setTimeout(() => firstElement === null || firstElement === void 0 ? void 0 : firstElement.focus());
|
|
55
|
+
} else if ("ArrowUp" === openingGesture) {
|
|
56
|
+
const elements = [...iterable];
|
|
57
|
+
const lastElement = elements[elements.length - 1];
|
|
58
|
+
setTimeout(() => lastElement.focus());
|
|
59
|
+
} else {
|
|
60
|
+
const firstElement_0 = iterable.next().value;
|
|
61
|
+
setTimeout(() => firstElement_0 === null || firstElement_0 === void 0 ? void 0 : firstElement_0.focus());
|
|
62
|
+
}
|
|
29
63
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const firstElement = iterable.next().value;
|
|
48
|
-
/** We push imperative focus to the next tick to prevent React's batching */
|
|
49
|
-
setTimeout(() => firstElement === null || firstElement === void 0 ? void 0 : firstElement.focus());
|
|
50
|
-
} else if ("ArrowUp" === openingGesture) {
|
|
51
|
-
const elements = [...iterable];
|
|
52
|
-
const lastElement = elements[elements.length - 1];
|
|
53
|
-
setTimeout(() => lastElement.focus());
|
|
54
|
-
} else {
|
|
55
|
-
/** if the menu was not opened with the anchor, we default to the first element
|
|
56
|
-
* for example: with keyboard shortcut (see stories/fixtures)
|
|
57
|
-
*/
|
|
58
|
-
const firstElement = iterable.next().value;
|
|
59
|
-
setTimeout(() => firstElement === null || firstElement === void 0 ? void 0 : firstElement.focus());
|
|
60
|
-
}
|
|
61
|
-
}, [
|
|
62
|
-
open,
|
|
63
|
-
openingGesture,
|
|
64
|
-
anchorRef
|
|
65
|
-
]);
|
|
64
|
+
t3 = [
|
|
65
|
+
open,
|
|
66
|
+
openingGesture,
|
|
67
|
+
anchorRef,
|
|
68
|
+
containerRef
|
|
69
|
+
];
|
|
70
|
+
$[3] = anchorRef;
|
|
71
|
+
$[4] = containerRef;
|
|
72
|
+
$[5] = open;
|
|
73
|
+
$[6] = openingGesture;
|
|
74
|
+
$[7] = t2;
|
|
75
|
+
$[8] = t3;
|
|
76
|
+
} else {
|
|
77
|
+
t2 = $[7];
|
|
78
|
+
t3 = $[8];
|
|
79
|
+
}
|
|
80
|
+
React.useEffect(t2, t3);
|
|
66
81
|
};
|
|
67
82
|
//#endregion
|
|
68
83
|
export { useMenuInitialFocus };
|
|
@@ -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
|
-
|
|
24
|
+
focusCurrentTarget(returnFocusRef);
|
|
22
25
|
};
|
|
23
26
|
};
|
|
24
27
|
t2 = [
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ThemeContext } from "../../ThemeContext.js";
|
|
2
|
+
import { c } from "react-compiler-runtime";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/internal/components/ThemeProviderBase.tsx
|
|
5
|
+
const ThemeProviderBase = (t0) => {
|
|
6
|
+
const $ = c(11);
|
|
7
|
+
const { children, contextOnly, value } = t0;
|
|
8
|
+
if (contextOnly) {
|
|
9
|
+
let t1;
|
|
10
|
+
if ($[0] !== children || $[1] !== value) {
|
|
11
|
+
t1 = /*#__PURE__*/ jsx(ThemeContext.Provider, {
|
|
12
|
+
value,
|
|
13
|
+
children
|
|
14
|
+
});
|
|
15
|
+
$[0] = children;
|
|
16
|
+
$[1] = value;
|
|
17
|
+
$[2] = t1;
|
|
18
|
+
} else t1 = $[2];
|
|
19
|
+
return t1;
|
|
20
|
+
}
|
|
21
|
+
const t1 = value.colorMode === "auto" ? "auto" : value.colorScheme.includes("dark") ? "dark" : "light";
|
|
22
|
+
let t2;
|
|
23
|
+
if ($[3] !== children || $[4] !== t1 || $[5] !== value.dayScheme || $[6] !== value.nightScheme) {
|
|
24
|
+
t2 = /*#__PURE__*/ jsx("div", {
|
|
25
|
+
"data-component": "ThemeProvider",
|
|
26
|
+
"data-color-mode": t1,
|
|
27
|
+
"data-light-theme": value.dayScheme,
|
|
28
|
+
"data-dark-theme": value.nightScheme,
|
|
29
|
+
children
|
|
30
|
+
});
|
|
31
|
+
$[3] = children;
|
|
32
|
+
$[4] = t1;
|
|
33
|
+
$[5] = value.dayScheme;
|
|
34
|
+
$[6] = value.nightScheme;
|
|
35
|
+
$[7] = t2;
|
|
36
|
+
} else t2 = $[7];
|
|
37
|
+
let t3;
|
|
38
|
+
if ($[8] !== t2 || $[9] !== value) {
|
|
39
|
+
t3 = /*#__PURE__*/ jsx(ThemeContext.Provider, {
|
|
40
|
+
value,
|
|
41
|
+
children: t2
|
|
42
|
+
});
|
|
43
|
+
$[8] = t2;
|
|
44
|
+
$[9] = value;
|
|
45
|
+
$[10] = t3;
|
|
46
|
+
} else t3 = $[10];
|
|
47
|
+
return t3;
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
export { ThemeProviderBase };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useSyncedState } from "../../hooks/useSyncedState.js";
|
|
2
|
+
import { useTheme } from "../../useTheme.js";
|
|
3
|
+
import { c } from "react-compiler-runtime";
|
|
4
|
+
import React from "react";
|
|
5
|
+
//#region src/internal/hooks/useThemeProvider.ts
|
|
6
|
+
const defaultColorMode = "day";
|
|
7
|
+
const defaultDayScheme = "light";
|
|
8
|
+
const defaultNightScheme = "dark";
|
|
9
|
+
function useThemeProvider(props) {
|
|
10
|
+
var _ref, _props$colorMode, _ref2, _props$dayScheme, _ref3, _props$nightScheme;
|
|
11
|
+
const $ = c(12);
|
|
12
|
+
const parentValue = useTheme();
|
|
13
|
+
const [colorMode, setColorMode] = useSyncedState((_ref = (_props$colorMode = props.colorMode) !== null && _props$colorMode !== void 0 ? _props$colorMode : parentValue.colorMode) !== null && _ref !== void 0 ? _ref : defaultColorMode);
|
|
14
|
+
const [dayScheme, setDayScheme] = useSyncedState((_ref2 = (_props$dayScheme = props.dayScheme) !== null && _props$dayScheme !== void 0 ? _props$dayScheme : parentValue.dayScheme) !== null && _ref2 !== void 0 ? _ref2 : defaultDayScheme);
|
|
15
|
+
const [nightScheme, setNightScheme] = useSyncedState((_ref3 = (_props$nightScheme = props.nightScheme) !== null && _props$nightScheme !== void 0 ? _props$nightScheme : parentValue.nightScheme) !== null && _ref3 !== void 0 ? _ref3 : defaultNightScheme);
|
|
16
|
+
const systemColorMode = useSystemColorMode();
|
|
17
|
+
const resolvedColorMode = colorMode === "auto" ? systemColorMode : colorMode;
|
|
18
|
+
const colorScheme = resolvedColorMode === "day" || resolvedColorMode === "light" ? dayScheme : nightScheme;
|
|
19
|
+
let t0;
|
|
20
|
+
if ($[0] !== colorMode || $[1] !== colorScheme || $[2] !== dayScheme || $[3] !== nightScheme || $[4] !== resolvedColorMode || $[5] !== setColorMode || $[6] !== setDayScheme || $[7] !== setNightScheme) {
|
|
21
|
+
t0 = {
|
|
22
|
+
colorScheme,
|
|
23
|
+
colorMode,
|
|
24
|
+
resolvedColorMode,
|
|
25
|
+
dayScheme,
|
|
26
|
+
nightScheme,
|
|
27
|
+
setColorMode,
|
|
28
|
+
setDayScheme,
|
|
29
|
+
setNightScheme
|
|
30
|
+
};
|
|
31
|
+
$[0] = colorMode;
|
|
32
|
+
$[1] = colorScheme;
|
|
33
|
+
$[2] = dayScheme;
|
|
34
|
+
$[3] = nightScheme;
|
|
35
|
+
$[4] = resolvedColorMode;
|
|
36
|
+
$[5] = setColorMode;
|
|
37
|
+
$[6] = setDayScheme;
|
|
38
|
+
$[7] = setNightScheme;
|
|
39
|
+
$[8] = t0;
|
|
40
|
+
} else t0 = $[8];
|
|
41
|
+
const value = t0;
|
|
42
|
+
let t1;
|
|
43
|
+
if ($[9] !== parentValue || $[10] !== value) {
|
|
44
|
+
t1 = {
|
|
45
|
+
parentValue,
|
|
46
|
+
value
|
|
47
|
+
};
|
|
48
|
+
$[9] = parentValue;
|
|
49
|
+
$[10] = value;
|
|
50
|
+
$[11] = t1;
|
|
51
|
+
} else t1 = $[11];
|
|
52
|
+
return t1;
|
|
53
|
+
}
|
|
54
|
+
function subscribeToSystemColorMode(callback) {
|
|
55
|
+
var _window, _window$matchMedia;
|
|
56
|
+
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)");
|
|
57
|
+
media === null || media === void 0 || media.addEventListener("change", callback);
|
|
58
|
+
return () => media === null || media === void 0 ? void 0 : media.removeEventListener("change", callback);
|
|
59
|
+
}
|
|
60
|
+
function useSystemColorMode() {
|
|
61
|
+
return React.useSyncExternalStore(subscribeToSystemColorMode, getSystemColorMode, _temp);
|
|
62
|
+
}
|
|
63
|
+
function _temp() {
|
|
64
|
+
return "day";
|
|
65
|
+
}
|
|
66
|
+
function getSystemColorMode() {
|
|
67
|
+
var _window2, _window2$matchMedia, _window2$matchMedia$c;
|
|
68
|
+
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";
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { useThemeProvider };
|