mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-23 20:55:47 +00:00
28 lines
724 B
TypeScript
28 lines
724 B
TypeScript
"use client"
|
|
|
|
import * as React from "react"
|
|
import { MoonIcon, SunIcon } from "lucide-react"
|
|
import { useTheme } from "next-themes"
|
|
|
|
import { Button } from "@/registry/new-york-v4/ui/button"
|
|
|
|
export function ModeToggle() {
|
|
const { setTheme, resolvedTheme } = useTheme()
|
|
|
|
const toggleTheme = React.useCallback(() => {
|
|
setTheme(resolvedTheme === "dark" ? "light" : "dark")
|
|
}, [resolvedTheme, setTheme])
|
|
|
|
return (
|
|
<Button
|
|
variant="ghost"
|
|
className="group/toggle h-8 w-8 px-0"
|
|
onClick={toggleTheme}
|
|
>
|
|
<SunIcon className="hidden [html.dark_&]:block" />
|
|
<MoonIcon className="hidden [html.light_&]:block" />
|
|
<span className="sr-only">Toggle theme</span>
|
|
</Button>
|
|
)
|
|
}
|