mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
import { ChevronsUpDown, Monitor, Moon, Sun } from "lucide-react";
|
|
import { useTranslation } from 'react-i18next';
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu";
|
|
import { useTheme } from "@/hooks/useTheme";
|
|
import { type Theme } from "@/contexts/AppContext";
|
|
|
|
export function ThemePicker() {
|
|
const { t } = useTranslation();
|
|
const { theme, setTheme } = useTheme();
|
|
|
|
const themeOptions: { value: Theme; label: string; icon: React.ComponentType<{ className?: string }> }[] = [
|
|
{ value: "system", label: t('system'), icon: Monitor },
|
|
{ value: "light", label: t('light'), icon: Sun },
|
|
{ value: "dark", label: t('dark'), icon: Moon },
|
|
];
|
|
|
|
const currentTheme = themeOptions.find(option => option.value === theme);
|
|
const CurrentIcon = currentTheme?.icon || Monitor;
|
|
|
|
return (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button variant="outline" className="w-full justify-between">
|
|
<div className="flex items-center gap-2">
|
|
<CurrentIcon className="h-4 w-4" />
|
|
<span>{currentTheme?.label || t('system')}</span>
|
|
</div>
|
|
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end" className="w-[180px]">
|
|
{themeOptions.map((option) => {
|
|
const Icon = option.icon;
|
|
return (
|
|
<DropdownMenuItem
|
|
key={option.value}
|
|
onClick={() => setTheme(option.value)}
|
|
className="flex items-center gap-2"
|
|
>
|
|
<Icon className="h-4 w-4" />
|
|
<span>{option.label}</span>
|
|
{theme === option.value && (
|
|
<div className="ml-auto h-2 w-2 rounded-full bg-primary" />
|
|
)}
|
|
</DropdownMenuItem>
|
|
);
|
|
})}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
);
|
|
} |