Theme Switch Button
ui-components/theme-switchFreeBlock
A theme switch component to toggle between light and dark mode.
Install it
npx shadcn@latest add https://ui.raulcarini.dev/r/theme-switch.jsonSource
1"use client";23import { MoonIcon, SunIcon } from "lucide-react";4import { Button } from "@/components/ui/button";5import { useTheme } from "next-themes";6import { useCallback } from "react";7import { cn } from "@/lib/utils";89const ThemeSwitch = ({10 className,11 ...props12}: React.HTMLAttributes<HTMLButtonElement>) => {13 const { theme, setTheme } = useTheme();1415 const handleToggleTheme = useCallback(() => {16 const newTheme = theme === "light" ? "dark" : "light";17 setTheme(newTheme);18 }, [theme, setTheme]);1920 return (21 <Button22 size="icon"23 variant="ghost"24 className={cn("size-8 group", className)}25 aria-label="Toggle theme between light and dark mode"26 onClick={handleToggleTheme}27 {...props}28 >29 <MoonIcon30 className="hidden dark:block fill-transparent group-hover:fill-foreground group-hover:rotate-12 group-hover:scale-110 transition-all duration-200 ease-out"31 aria-hidden="true"32 />33 <SunIcon34 className="dark:hidden fill-transparent group-hover:fill-foreground group-hover:rotate-12 group-hover:scale-110 transition-all duration-200 ease-out"35 aria-hidden="true"36 />37 </Button>38 );39};4041export default ThemeSwitch;
What it pulls in
npm packages
Other registry items
Files it writes
More from UI Components
All 25 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| GitHub Contributionsgithub-contributions | UI Components | Blocks | Free | no deps | |
| GitHub Contributions Advancedgithub-contributions-advanced | UI Components | Blocks | Free | no deps | |
| GitHub Contributions Advanced Fetchergithub-contributions-advanced-fetcher | UI Components | Blocks | Free | no deps | |
| GitHub Contributions Fetchergithub-contributions-fetcher | UI Components | Blocks | Free | no deps | |
| GitHub Forksgithub-forks | UI Components | Blocks | Free | 1 dep | |
| GitHub Issuesgithub-issues | UI Components | Blocks | Free | 1 dep | |
| GitHub Pull Requestsgithub-pr | UI Components | Blocks | Free | 1 dep | |
| GitHub Starsgithub-stars | UI Components | Blocks | Free | 1 dep |
