mirror of
https://github.com/vercel/workflow.git
synced 2026-09-14 19:59:43 +08:00
2cc8c3dc9c
* Run update script * Update deps * Restore code block modifications * Reapply navbar patch * Restore custom proxy config * Add md-metadata * Add new frontmatter
36 lines
837 B
TypeScript
36 lines
837 B
TypeScript
'use client';
|
|
|
|
import { MoonIcon, SunIcon } from 'lucide-react';
|
|
import { useTheme } from 'next-themes';
|
|
import { useEffect, useState } from 'react';
|
|
import { Button } from '../ui/button';
|
|
|
|
export const ThemeToggle = () => {
|
|
const { resolvedTheme, setTheme } = useTheme();
|
|
const [mounted, setMounted] = useState(false);
|
|
|
|
useEffect(() => {
|
|
setMounted(true);
|
|
}, []);
|
|
|
|
const handleClick = () => {
|
|
setTheme(resolvedTheme === 'dark' ? 'light' : 'dark');
|
|
};
|
|
|
|
if (!mounted) {
|
|
return (
|
|
<Button size="icon-sm" type="button" variant="ghost">
|
|
<div className="size-4" />
|
|
</Button>
|
|
);
|
|
}
|
|
|
|
const Icon = resolvedTheme === 'dark' ? MoonIcon : SunIcon;
|
|
|
|
return (
|
|
<Button onClick={handleClick} size="icon-sm" type="button" variant="ghost">
|
|
<Icon className="size-4" />
|
|
</Button>
|
|
);
|
|
};
|