mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-05 01:01:42 +00:00
- Set VitePress base to '/docs/' for serving documentation at /docs/ route - Update favicon path in head config to '/docs/favicon.ico' - Add build:site script to build website and docs, then merge outputs
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { Moon, Sun } from "lucide-react"
|
|
import { Button } from "@/components/ui/button"
|
|
import { useTheme } from "@/contexts/ThemeContext"
|
|
|
|
export function ModeToggle() {
|
|
const { theme, setTheme } = useTheme()
|
|
|
|
const toggleTheme = () => {
|
|
// 如果当前是 system,则根据系统偏好决定切换到哪个模式
|
|
if (theme === "system") {
|
|
const systemIsDark = window.matchMedia("(prefers-color-scheme: dark)").matches
|
|
setTheme(systemIsDark ? "light" : "dark")
|
|
} else {
|
|
setTheme(theme === "dark" ? "light" : "dark")
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Button
|
|
variant="outline"
|
|
size="icon"
|
|
onClick={toggleTheme}
|
|
className="border-2 border-border shadow-hard hover:translate-y-0.5 hover:shadow-none transition-all"
|
|
title="Toggle theme"
|
|
>
|
|
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
|
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
|
<span className="sr-only">Toggle theme</span>
|
|
</Button>
|
|
)
|
|
}
|