@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 CHANGED
@@ -1,11 +1,6 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260809202139
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
@@ -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 };
@@ -1,17 +1,16 @@
1
1
  import theme from "./theme.js";
2
- import { ThemeProviderBase } from "./internal/components/ThemeProviderBase.js";
3
- import { useThemeProvider } from "./internal/hooks/useThemeProvider.js";
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
- //#region src/ThemeProvider.tsx
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 _parentValue$theme;
14
- const $ = c(14);
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 { parentValue, value } = useThemeProvider(props);
27
- const theme$1 = (_parentValue$theme = parentValue.theme) !== null && _parentValue$theme !== void 0 ? _parentValue$theme : theme;
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] !== 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;
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 ($[6] !== resolvedColorScheme || $[7] !== resolvedTheme || $[8] !== value) {
38
- t2 = {
39
- ...value,
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
- resolvedColorScheme
59
+ colorScheme,
60
+ colorMode,
61
+ resolvedColorMode,
62
+ resolvedColorScheme,
63
+ dayScheme,
64
+ nightScheme,
65
+ setColorMode,
66
+ setDayScheme,
67
+ setNightScheme
42
68
  };
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,
53
- value: contextValue,
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
- $[10] = children;
57
- $[11] = contextValue;
58
- $[12] = props.contextOnly;
59
- $[13] = t3;
60
- } else t3 = $[13];
61
- return t3;
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
- * Customize when the icons are hidden to save space. Set to `null` to always show icons.
21
- * Defaults to `xxlarge`; if you know there won't be very many tabs you might set this to a smaller value.
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 ? "xxlarge" : t4;
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);