@kujoforall/paper-ui 0.2.0 → 0.2.1
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,5 +1,11 @@
|
|
|
1
1
|
# @kujoforall/paper-ui
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e8f8b36: `ThemeProvider` no longer reads storage during its first render, so a server-rendered page (Next) hydrates without a mismatch on `ThemeToggle`. The stored theme is read straight after, before paint; the dark class set by `themeInitScript` is left alone until then, so there is no flash.
|
|
8
|
+
|
|
3
9
|
## 0.2.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme-toggle.d.ts","sourceRoot":"","sources":["../../../src/components/ui/theme-toggle.tsx"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"theme-toggle.d.ts","sourceRoot":"","sources":["../../../src/components/ui/theme-toggle.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAmE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACxG,OAAO,EAAsB,KAAK,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAIpE,KAAK,iBAAiB,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC;IAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CAAE,CAAC;AA2BxG,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,UAAsB,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,+BAkC/G;AAED,6FAA6F;AAC7F,wBAAgB,QAAQ,IAAI,iBAAiB,CAI5C;AAKD,wBAAgB,WAAW,gCAU1B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { Moon, Sun } from "lucide-react";
|
|
4
|
-
import { createContext, useContext, useEffect, useState } from "react";
|
|
4
|
+
import { createContext, useContext, useEffect, useLayoutEffect, useState } from "react";
|
|
5
5
|
import { isTheme, THEME_KEY } from "../../lib/theme.js";
|
|
6
6
|
import { Button } from "./button.js";
|
|
7
7
|
import { Tooltip } from "./tooltip.js";
|
|
@@ -21,11 +21,22 @@ function read(storageKey) {
|
|
|
21
21
|
"system" keeps following the OS after load, not just at it. Pair it with
|
|
22
22
|
themeInitScript() in <head> so the first paint is already right.
|
|
23
23
|
|
|
24
|
+
The first render is the same on the server and in the browser (system, light),
|
|
25
|
+
so a server-rendered page hydrates without a mismatch; the stored choice and the
|
|
26
|
+
system's are read straight after, before the browser paints. Until then the
|
|
27
|
+
`dark` class is left as the init script set it, so there is no flash either.
|
|
28
|
+
|
|
24
29
|
From triptrack and medialogue, 2026-12-05; it replaces the kit's animated toggle,
|
|
25
30
|
which had no system mode and could throw where storage is blocked. */
|
|
26
31
|
export function ThemeProvider({ children, storageKey = THEME_KEY }) {
|
|
27
|
-
const [theme, setThemeState] = useState(
|
|
28
|
-
const [systemDark, setSystemDark] = useState(
|
|
32
|
+
const [theme, setThemeState] = useState("system");
|
|
33
|
+
const [systemDark, setSystemDark] = useState(false);
|
|
34
|
+
const [ready, setReady] = useState(false);
|
|
35
|
+
useLayoutEffect(() => {
|
|
36
|
+
setThemeState(read(storageKey));
|
|
37
|
+
setSystemDark(prefersDark());
|
|
38
|
+
setReady(true);
|
|
39
|
+
}, [storageKey]);
|
|
29
40
|
useEffect(() => {
|
|
30
41
|
const query = window.matchMedia("(prefers-color-scheme: dark)");
|
|
31
42
|
const onChange = (event) => setSystemDark(event.matches);
|
|
@@ -34,8 +45,9 @@ export function ThemeProvider({ children, storageKey = THEME_KEY }) {
|
|
|
34
45
|
}, []);
|
|
35
46
|
const resolved = theme === "system" ? (systemDark ? "dark" : "light") : theme;
|
|
36
47
|
useEffect(() => {
|
|
37
|
-
|
|
38
|
-
|
|
48
|
+
if (ready)
|
|
49
|
+
document.documentElement.classList.toggle("dark", resolved === "dark");
|
|
50
|
+
}, [resolved, ready]);
|
|
39
51
|
const setTheme = (next) => {
|
|
40
52
|
setThemeState(next);
|
|
41
53
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme-toggle.js","sourceRoot":"","sources":["../../../src/components/ui/theme-toggle.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"theme-toggle.js","sourceRoot":"","sources":["../../../src/components/ui/theme-toggle.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACxG,OAAO,EAAE,OAAO,EAAE,SAAS,EAAc,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAc,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAe,CAAC;AAIxC,MAAM,YAAY,GAAG,aAAa,CAA2B,IAAI,CAAC,CAAC;AAEnE,MAAM,WAAW,GAAG,GAAY,EAAE,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,UAAU,CAAC,8BAA8B,CAAC,CAAC,OAAO,CAAC;AAE9H,SAAS,IAAI,CAAC,UAAkB;IAC5B,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,YAAY,CAAC,OA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,gBAAa,aAAa,IAAI,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,YACrG,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,KAAC,IAAI,KAAG,CAAC,CAAC,CAAC,KAAC,GAAG,KAAG,GACpC,GACH,CACb,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { Moon, Sun } from "lucide-react";
|
|
4
|
-
import { createContext, useContext, useEffect, useState, type ReactNode } from "react";
|
|
4
|
+
import { createContext, useContext, useEffect, useLayoutEffect, useState, type ReactNode } from "react";
|
|
5
5
|
import { isTheme, THEME_KEY, type Theme } from "../../lib/theme.ts";
|
|
6
6
|
import { Button } from "./button.tsx";
|
|
7
7
|
import { Tooltip } from "./tooltip.tsx";
|
|
@@ -26,11 +26,23 @@ function read(storageKey: string): Theme {
|
|
|
26
26
|
"system" keeps following the OS after load, not just at it. Pair it with
|
|
27
27
|
themeInitScript() in <head> so the first paint is already right.
|
|
28
28
|
|
|
29
|
+
The first render is the same on the server and in the browser (system, light),
|
|
30
|
+
so a server-rendered page hydrates without a mismatch; the stored choice and the
|
|
31
|
+
system's are read straight after, before the browser paints. Until then the
|
|
32
|
+
`dark` class is left as the init script set it, so there is no flash either.
|
|
33
|
+
|
|
29
34
|
From triptrack and medialogue, 2026-12-05; it replaces the kit's animated toggle,
|
|
30
35
|
which had no system mode and could throw where storage is blocked. */
|
|
31
36
|
export function ThemeProvider({ children, storageKey = THEME_KEY }: { children: ReactNode; storageKey?: string }) {
|
|
32
|
-
const [theme, setThemeState] = useState<Theme>(
|
|
33
|
-
const [systemDark, setSystemDark] = useState(
|
|
37
|
+
const [theme, setThemeState] = useState<Theme>("system");
|
|
38
|
+
const [systemDark, setSystemDark] = useState(false);
|
|
39
|
+
const [ready, setReady] = useState(false);
|
|
40
|
+
|
|
41
|
+
useLayoutEffect(() => {
|
|
42
|
+
setThemeState(read(storageKey));
|
|
43
|
+
setSystemDark(prefersDark());
|
|
44
|
+
setReady(true);
|
|
45
|
+
}, [storageKey]);
|
|
34
46
|
|
|
35
47
|
useEffect(() => {
|
|
36
48
|
const query = window.matchMedia("(prefers-color-scheme: dark)");
|
|
@@ -42,8 +54,8 @@ export function ThemeProvider({ children, storageKey = THEME_KEY }: { children:
|
|
|
42
54
|
const resolved = theme === "system" ? (systemDark ? "dark" : "light") : theme;
|
|
43
55
|
|
|
44
56
|
useEffect(() => {
|
|
45
|
-
document.documentElement.classList.toggle("dark", resolved === "dark");
|
|
46
|
-
}, [resolved]);
|
|
57
|
+
if (ready) document.documentElement.classList.toggle("dark", resolved === "dark");
|
|
58
|
+
}, [resolved, ready]);
|
|
47
59
|
|
|
48
60
|
const setTheme = (next: Theme) => {
|
|
49
61
|
setThemeState(next);
|