Created
July 28, 2024 14:36
-
-
Save naopoyo/a86f5f9414a7b547d7df338a5d2f1873 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use client' | |
import { ComputerIcon, MoonIcon, SunIcon } from 'lucide-react' | |
import { useTheme } from 'next-themes' | |
import { useEffect, useState } from 'react' | |
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group' | |
export default function ThemeSwitcher() { | |
const [mounted, setMounted] = useState(false) | |
const { theme, setTheme } = useTheme() | |
useEffect(() => { | |
setMounted(true) | |
}, []) | |
if (!mounted || theme === undefined) { | |
return | |
} | |
return ( | |
<ToggleGroup | |
className='rounded-full border p-1' | |
size='sm' | |
type='single' | |
value={theme} | |
onValueChange={(value) => setTheme(value)} | |
> | |
<ToggleGroupItem className='rounded-full' value='dark' aria-label='Toggle dark'> | |
<MoonIcon size={16} /> | |
</ToggleGroupItem> | |
<ToggleGroupItem className='rounded-full' value='system' aria-label='Toggle system'> | |
<ComputerIcon size={16} /> | |
</ToggleGroupItem> | |
<ToggleGroupItem className='rounded-full' value='light' aria-label='Toggle light'> | |
<SunIcon size={16} /> | |
</ToggleGroupItem> | |
</ToggleGroup> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment