@primer/react 0.0.0-20260809202139 → 0.0.0-20260810174932
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 +3 -6
- package/dist/ThemeProvider.d.ts +0 -3
- package/dist/ThemeProvider.js +129 -39
- package/dist/UnderlineNav/UnderlineNav.d.ts +3 -2
- package/dist/UnderlineNav/UnderlineNav.js +1 -1
- package/dist/legacy-theme/ts/color-schemes.js +3942 -3942
- package/dist/next/index.d.ts +1 -4
- package/dist/next/index.js +1 -3
- package/dist/theme.d.ts +54 -16
- package/dist/useTheme.d.ts +14 -2
- package/generated/components.json +7 -1
- package/generated/hooks.json +7 -2
- package/package.json +3 -1
- package/dist/ThemeContext.d.ts +0 -20
- package/dist/internal/components/ThemeProviderBase.js +0 -50
- package/dist/internal/hooks/useThemeProvider.js +0 -71
- package/dist/next/ThemeProvider.d.ts +0 -7
- package/dist/next/ThemeProvider.js +0 -35
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
# @primer/react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- [#8212](https://github.com/primer/react/pull/8212) [`6a4c131`](https://github.com/primer/react/commit/6a4c1319a70a5f3b5abc7b81b044bd26d042aa75) Thanks [@mattcosta7](https://github.com/mattcosta7)! - ThemeProvider: Add a CSS-variable-based implementation to `@primer/react/next`
|
|
8
|
-
and deprecate the legacy JavaScript theme implementation.
|
|
3
|
+
## 0.0.0-20260810174932
|
|
9
4
|
|
|
10
5
|
### Patch Changes
|
|
11
6
|
|
|
@@ -15,6 +10,8 @@
|
|
|
15
10
|
|
|
16
11
|
- [#8273](https://github.com/primer/react/pull/8273) [`0c1e401`](https://github.com/primer/react/commit/0c1e401b6b0d57f95f8115ea90af78281751a766) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - NavList: Exclude group headings from navigation list item counts
|
|
17
12
|
|
|
13
|
+
- [#8260](https://github.com/primer/react/pull/8260) [`af3bbeb`](https://github.com/primer/react/commit/af3bbeb0c2bf7b277903066ef1ec3b1ef6ec1d70) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - UnderlineNav: Keep item icons visible by default at the medium breakpoint and above
|
|
14
|
+
|
|
18
15
|
## 38.35.0
|
|
19
16
|
|
|
20
17
|
### Minor Changes
|
package/dist/ThemeProvider.d.ts
CHANGED
|
@@ -21,9 +21,6 @@ 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
|
-
*/
|
|
27
24
|
declare const ThemeProvider: React.FC<React.PropsWithChildren<ThemeProviderProps>>;
|
|
28
25
|
//#endregion
|
|
29
26
|
export { ColorMode, ColorModeWithAuto, Theme, ThemeProvider, ThemeProvider as default, ThemeProviderProps };
|
package/dist/ThemeProvider.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import theme from "./theme.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useSyncedState } from "./hooks/useSyncedState.js";
|
|
3
|
+
import { ThemeContext } from "./ThemeContext.js";
|
|
4
|
+
import { useTheme } from "./useTheme.js";
|
|
4
5
|
import { c } from "react-compiler-runtime";
|
|
5
6
|
import { jsx } from "react/jsx-runtime";
|
|
6
|
-
import "react";
|
|
7
|
+
import React from "react";
|
|
7
8
|
import deepmerge from "deepmerge";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @deprecated Use `ThemeProvider` from `@primer/react/next` to migrate away from JavaScript theme values.
|
|
11
|
-
*/
|
|
9
|
+
const defaultDayScheme = "light";
|
|
10
|
+
const defaultNightScheme = "dark";
|
|
12
11
|
const ThemeProvider = (t0) => {
|
|
13
|
-
var
|
|
14
|
-
const $ = c(
|
|
12
|
+
var _ref, _props$colorMode, _ref2, _props$dayScheme, _ref3, _props$nightScheme;
|
|
13
|
+
const $ = c(34);
|
|
15
14
|
let children;
|
|
16
15
|
let props;
|
|
17
16
|
if ($[0] !== t0) {
|
|
@@ -23,43 +22,134 @@ const ThemeProvider = (t0) => {
|
|
|
23
22
|
children = $[1];
|
|
24
23
|
props = $[2];
|
|
25
24
|
}
|
|
26
|
-
const {
|
|
27
|
-
const theme$1 =
|
|
25
|
+
const { theme: fallbackTheme, colorMode: fallbackColorMode, dayScheme: fallbackDayScheme, nightScheme: fallbackNightScheme } = useTheme();
|
|
26
|
+
const theme$1 = fallbackTheme !== null && fallbackTheme !== void 0 ? fallbackTheme : theme;
|
|
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;
|
|
28
32
|
let t1;
|
|
29
|
-
if ($[3] !==
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
$[
|
|
33
|
-
$[
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
if ($[3] !== colorMode || $[4] !== dayScheme || $[5] !== nightScheme || $[6] !== systemColorMode) {
|
|
34
|
+
resolvedColorMode = resolveColorMode(colorMode, systemColorMode);
|
|
35
|
+
t1 = chooseColorScheme(resolvedColorMode, dayScheme, nightScheme);
|
|
36
|
+
$[3] = colorMode;
|
|
37
|
+
$[4] = dayScheme;
|
|
38
|
+
$[5] = nightScheme;
|
|
39
|
+
$[6] = systemColorMode;
|
|
40
|
+
$[7] = resolvedColorMode;
|
|
41
|
+
$[8] = t1;
|
|
42
|
+
} else {
|
|
43
|
+
resolvedColorMode = $[7];
|
|
44
|
+
t1 = $[8];
|
|
45
|
+
}
|
|
46
|
+
const colorScheme = t1;
|
|
36
47
|
let t2;
|
|
37
|
-
if ($[
|
|
38
|
-
t2 =
|
|
39
|
-
|
|
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 = {
|
|
40
58
|
theme: resolvedTheme,
|
|
41
|
-
|
|
59
|
+
colorScheme,
|
|
60
|
+
colorMode,
|
|
61
|
+
resolvedColorMode,
|
|
62
|
+
resolvedColorScheme,
|
|
63
|
+
dayScheme,
|
|
64
|
+
nightScheme,
|
|
65
|
+
setColorMode,
|
|
66
|
+
setDayScheme,
|
|
67
|
+
setNightScheme
|
|
42
68
|
};
|
|
43
|
-
$[
|
|
44
|
-
$[
|
|
45
|
-
$[
|
|
46
|
-
$[
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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;
|
|
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,
|
|
54
103
|
children
|
|
55
104
|
});
|
|
56
|
-
$[
|
|
57
|
-
$[
|
|
58
|
-
$[
|
|
59
|
-
$[
|
|
60
|
-
|
|
61
|
-
|
|
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, {
|
|
114
|
+
value: contextValue,
|
|
115
|
+
children: t5
|
|
116
|
+
});
|
|
117
|
+
$[31] = contextValue;
|
|
118
|
+
$[32] = t5;
|
|
119
|
+
$[33] = t6;
|
|
120
|
+
} else t6 = $[33];
|
|
121
|
+
return t6;
|
|
62
122
|
};
|
|
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
|
+
}
|
|
63
153
|
function applyColorScheme(theme, colorScheme) {
|
|
64
154
|
if (!theme.colorSchemes) return {
|
|
65
155
|
resolvedTheme: theme,
|
|
@@ -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);
|