Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions frontend/src/components/layout/ThemeToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
import { Moon, Sun } from 'lucide-react'
import { Monitor, Moon, Sun } from 'lucide-react'

import { Button } from '@/components/ui/button'
import { useTheme } from '@/lib/hooks/use-theme'
import type { Theme } from '@/lib/hooks/use-theme'
import { useReviewLocale } from '@/lib/reviewLocale'

const THEME_CYCLE: Theme[] = ['light', 'dark', 'system']

function nextTheme(current: Theme): Theme {
const idx = THEME_CYCLE.indexOf(current)
return THEME_CYCLE[(idx + 1) % THEME_CYCLE.length]
}

export function ThemeToggle() {
const { resolvedTheme, setTheme } = useTheme()
const { theme, resolvedTheme, setTheme } = useTheme()
const { text } = useReviewLocale()

const themeLabel = resolvedTheme === 'dark'
? text('切换到浅色模式', 'Switch to light mode')
: text('切换到深色模式', 'Switch to dark mode')
const next = nextTheme(theme)
const themeLabel = next === 'dark'
? text('切换到深色模式', 'Switch to dark mode')
: next === 'system'
? text('切换到跟随系统', 'Switch to system theme')
: text('切换到浅色模式', 'Switch to light mode')

return (
<Button
variant="ghost"
size="icon"
onClick={() => setTheme(resolvedTheme === 'dark' ? 'light' : 'dark')}
onClick={() => setTheme(next)}
aria-label={themeLabel}
title={themeLabel}
className="shrink-0 text-foreground"
>
{resolvedTheme === 'dark' ? (
{theme === 'system' ? (
<Monitor className="h-5 w-5" />
) : resolvedTheme === 'dark' ? (
<Sun className="h-5 w-5" />
) : (
<Moon className="h-5 w-5" />
Expand Down