CoolFace
Apppublic

code2024/bingo

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
theme-toggle.tsx32 linesDownload Raw Back to components
1'use client'2 3import * as React from 'react'4import { useTheme } from 'next-themes'5 6import { Button } from '@/components/ui/button'7import { IconMoon, IconSun } from '@/components/ui/icons'8 9export function ThemeToggle() {10  const { setTheme, theme } = useTheme()11  const [_, startTransition] = React.useTransition()12 13  return (14    <Button15      variant="ghost"16      size="icon"17      onClick={() => {18        startTransition(() => {19          setTheme(theme === 'light' ? 'dark' : 'light')20        })21      }}22    >23      {!theme ? null : theme === 'dark' ? (24        <IconMoon className="transition-all" />25      ) : (26        <IconSun className="transition-all" />27      )}28      <span className="sr-only">Toggle theme</span>29    </Button>30  )31}32