@checkstack/ui 0.2.2 → 0.2.3
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 +10 -0
- package/package.json +1 -1
- package/src/components/ThemeProvider.tsx +17 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @checkstack/ui
|
|
2
2
|
|
|
3
|
+
## 0.2.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f6464a2: Fix theme toggle showing incorrect state when system theme is used
|
|
8
|
+
|
|
9
|
+
- Added `resolvedTheme` property to `ThemeProvider` that returns the actual computed theme ("light" or "dark"), resolving "system" to the user's OS preference
|
|
10
|
+
- Updated `NavbarThemeToggle` and `ThemeToggleMenuItem` to use `resolvedTheme` instead of `theme` for determining toggle state
|
|
11
|
+
- Changed default theme from "light" to "system" so non-logged-in users respect their OS color scheme preference
|
|
12
|
+
|
|
3
13
|
## 0.2.2
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -10,11 +10,20 @@ interface ThemeProviderProps {
|
|
|
10
10
|
|
|
11
11
|
interface ThemeProviderState {
|
|
12
12
|
theme: Theme;
|
|
13
|
+
/** The actual resolved theme ("light" or "dark"), accounting for system preference */
|
|
14
|
+
resolvedTheme: "light" | "dark";
|
|
13
15
|
setTheme: (theme: Theme) => void;
|
|
14
16
|
}
|
|
15
17
|
|
|
18
|
+
const getSystemTheme = (): "light" | "dark" => {
|
|
19
|
+
return globalThis.matchMedia("(prefers-color-scheme: dark)").matches
|
|
20
|
+
? "dark"
|
|
21
|
+
: "light";
|
|
22
|
+
};
|
|
23
|
+
|
|
16
24
|
const initialState: ThemeProviderState = {
|
|
17
25
|
theme: "system",
|
|
26
|
+
resolvedTheme: "light",
|
|
18
27
|
setTheme: () => {
|
|
19
28
|
// Will be implemented by provider
|
|
20
29
|
},
|
|
@@ -29,29 +38,23 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({
|
|
|
29
38
|
...props
|
|
30
39
|
}) => {
|
|
31
40
|
const [theme, setTheme] = useState<Theme>(
|
|
32
|
-
() => (localStorage.getItem(storageKey) as Theme) || defaultTheme
|
|
41
|
+
() => (localStorage.getItem(storageKey) as Theme) || defaultTheme,
|
|
33
42
|
);
|
|
34
43
|
|
|
44
|
+
// Compute the resolved theme (what's actually displayed)
|
|
45
|
+
const resolvedTheme: "light" | "dark" =
|
|
46
|
+
theme === "system" ? getSystemTheme() : theme;
|
|
47
|
+
|
|
35
48
|
useEffect(() => {
|
|
36
49
|
const root = globalThis.document.documentElement;
|
|
37
50
|
|
|
38
51
|
root.classList.remove("light", "dark");
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const systemTheme = globalThis.matchMedia("(prefers-color-scheme: dark)")
|
|
42
|
-
.matches
|
|
43
|
-
? "dark"
|
|
44
|
-
: "light";
|
|
45
|
-
|
|
46
|
-
root.classList.add(systemTheme);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
root.classList.add(theme);
|
|
51
|
-
}, [theme]);
|
|
52
|
+
root.classList.add(resolvedTheme);
|
|
53
|
+
}, [resolvedTheme]);
|
|
52
54
|
|
|
53
55
|
const value = {
|
|
54
56
|
theme,
|
|
57
|
+
resolvedTheme,
|
|
55
58
|
setTheme: (newTheme: Theme) => {
|
|
56
59
|
localStorage.setItem(storageKey, newTheme);
|
|
57
60
|
setTheme(newTheme);
|