feat(webui): smooth theme changes and sun-moon transitions (#6450)

* feat(webui): smooth theme changes and sun-moon transitions

* test(webui): respect theme cooldown in diagram checks
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-25 19:15:27 +08:00
1 parent 4f7c4f0885
commit 3ede000ad4
12 files changed
+305 -17

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
:root[data-theme-transition="dark"] {
--theme-ink-delay: 180ms;
}
:root[data-theme-transition="light"] {
--theme-ink-delay: 100ms;
}
/* Keep text from dissolving into a matching gray while the canvas changes. */
:root[data-theme-transition] :is(
body,
.thread-workspace,
.workbench-body,
.workbench-pane,
main.bg-background,
.bg-sidebar,
.text-sidebar-muted-foreground,
[data-testid="thread-header"] > div,
[data-testid="hero-greeting"]
) {
transition: background-color 280ms linear, border-color 280ms linear, color 0s linear var(--theme-ink-delay);
}
:root[data-theme-transition] .thread-composer-surface {
transition: background-color 280ms linear, box-shadow 280ms linear, opacity 160ms ease-out;
}
:root[data-theme-transition] .thread-composer-surface textarea::placeholder {
transition: color 0s linear var(--theme-ink-delay);
}
+22 -3
View File
@@ -4,9 +4,11 @@ import {
useCallback,
useContext,
useEffect,
useRef,
useState,
type ReactNode,
} from "react";
import "./theme-transition.css";
type Theme = "light" | "dark";
const STORAGE_KEY = "nanobot-webui.theme";
@@ -50,6 +52,15 @@ export function useTheme(): {
return "light";
});
const switchTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
useEffect(() => () => {
if (switchTimer.current !== null) {
clearTimeout(switchTimer.current);
switchTimer.current = null;
delete document.documentElement.dataset.themeTransition;
}
}, []);
useEffect(() => {
applyTheme(theme);
try {
@@ -59,10 +70,18 @@ export function useTheme(): {
}
}, [theme]);
const setTheme = useCallback((t: Theme) => setThemeState(t), []);
const setTheme = useCallback((next: Theme) => {
if (next === theme || switchTimer.current !== null) return;
document.documentElement.dataset.themeTransition = next;
setThemeState(next);
switchTimer.current = setTimeout(() => {
delete document.documentElement.dataset.themeTransition;
switchTimer.current = null;
}, 600);
}, [theme]);
const toggle = useCallback(
() => setThemeState((t) => (t === "dark" ? "light" : "dark")),
[],
() => setTheme(theme === "dark" ? "light" : "dark"),
[setTheme, theme],
);
return { theme, toggle, setTheme };
}