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

@@ -0,0 +1,45 @@
.theme-toggle-mask {
mask-type: luminance;
forced-color-adjust: none;
}
.theme-toggle-core {
r: 5px;
}
.theme-toggle-cutout {
transform: translate(0, 0);
}
.theme-toggle-rays {
transform-origin: 12px 12px;
transform: rotate(0deg) scale(1);
opacity: 1;
}
.theme-toggle-icon[data-theme="light"] .theme-toggle-core {
r: 8px;
}
.theme-toggle-icon[data-theme="light"] .theme-toggle-cutout {
transform: translate(-7px, 11px);
}
.theme-toggle-icon[data-theme="light"] .theme-toggle-rays {
transform: rotate(-30deg) scale(0.6);
opacity: 0;
}
@media (prefers-reduced-motion: no-preference) {
.theme-toggle-core {
transition: r 280ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.theme-toggle-cutout {
transition: transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.theme-toggle-rays {
transition: transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 160ms ease-out;
}
}
@@ -0,0 +1,41 @@
import { useId } from "react";
import { cn } from "@/lib/utils";
import "./ThemeToggleIcon.css";
export function ThemeToggleIcon({ theme, className }: {
theme: "light" | "dark";
className?: string;
}) {
const id = useId();
const cutoutId = `theme-cutout-${id}`;
const discId = `theme-disc-${id}`;
return (
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
className={cn("theme-toggle-icon h-4 w-4", className)}
data-theme={theme}
>
<defs>
<mask id={cutoutId} maskUnits="userSpaceOnUse" x="-2" y="-2" width="28" height="28" className="theme-toggle-mask">
<rect x="-2" y="-2" width="28" height="28" fill="white" stroke="none" />
<circle className="theme-toggle-cutout" cx="24" cy="-4" r="8" fill="black" stroke="none" />
</mask>
<clipPath id={discId}>
<circle className="theme-toggle-core" cx="12" cy="12" r="8" />
</clipPath>
</defs>
<circle className="theme-toggle-core" cx="12" cy="12" r="8" mask={`url(#${cutoutId})`} />
<g clipPath={`url(#${discId})`}>
<circle className="theme-toggle-cutout" cx="24" cy="-4" r="8" />
</g>
<path className="theme-toggle-rays" d="M12 2v2m0 16v2M4.93 4.93l1.42 1.42m11.3 11.3 1.42 1.42M2 12h2m16 0h2M4.93 19.07l1.42-1.42m11.3-11.3 1.42-1.42" />
</svg>
);
}
+3 -6
View File
@@ -1,7 +1,8 @@
import {
TemporaryChatIcon,
} from "@/components/icons/product-icons";
import { Menu, Moon, Sun } from "lucide-react";
import { Menu } from "lucide-react";
import { ThemeToggleIcon } from "@/components/icons/ThemeToggleIcon";
import { type ReactNode } from "react";
import { useTranslation } from "react-i18next";
@@ -195,11 +196,7 @@ function ThemeButton({
className,
)}
>
{theme === "dark" ? (
<Sun className="h-4 w-4" />
) : (
<Moon className="h-4 w-4" />
)}
<ThemeToggleIcon theme={theme} />
</Button>
);
}