File size: 1,280 Bytes
689359a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | "use client";
import { Moon, Sun } from "lucide-react";
import { useTranslations } from "next-intl";
import { useTheme } from "next-themes";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { cn } from "@/lib/utils";
/**
* Flips between the light and dark theme. The icon is picked by the `dark`
* class on <html>, not by React state, so the server render already matches.
*/
export function ThemeToggle({ className, tooltipSide = "top" }: { className?: string; tooltipSide?: "top" | "right" | "bottom" | "left" }) {
const t = useTranslations("shell");
const { resolvedTheme, setTheme } = useTheme();
const label = t("theme.toggle");
return (
<Tooltip>
<TooltipTrigger asChild>
<button
type="button"
onClick={() => setTheme(resolvedTheme === "dark" ? "light" : "dark")}
aria-label={label}
className={cn("rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-sidebar-accent hover:text-foreground", className)}
>
<Sun className="size-4 dark:hidden" />
<Moon className="hidden size-4 dark:block" />
</button>
</TooltipTrigger>
<TooltipContent side={tooltipSide}>{label}</TooltipContent>
</Tooltip>
);
}
|