BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/UI Components/theme-switch-toggle

Theme Switch Toggle

ui-components/theme-switch-toggle
FreeBlock

A theme switch component using a toggle switch.

Install it

npx shadcn@latest add https://ui.raulcarini.dev/r/theme-switch-toggle.json

Source

registry/theme-switch/theme-switch-toggle.tsxui.raulcarini.dev/r/theme-switch-toggle.json
1"use client";
2
3import { MoonIcon, SunIcon } from "lucide-react";
4import { Switch } from "@/components/ui/switch";
5import { useTheme } from "next-themes";
6import { useCallback, useEffect, useState } from "react";
7import { cn } from "@/lib/utils";
8
9const ThemeSwitch = ({
10 className,
11 ...props
12}: React.HTMLAttributes<HTMLDivElement>) => {
13 const { theme, setTheme } = useTheme();
14 const [checked, setChecked] = useState(false);
15
16 // Update checked state when theme changes
17 useEffect(() => {
18 setChecked(theme === "dark");
19 }, [theme]);
20
21 const handleCheckedChange = useCallback(
22 (isChecked: boolean) => {
23 setChecked(isChecked);
24 const newTheme = isChecked ? "dark" : "light";
25 setTheme(newTheme);
26 },
27 [setTheme],
28 );
29
30 return (
31 <div
32 className={cn("relative flex items-center h-9 group", className)}
33 {...props}
34 >
35 <Switch
36 checked={checked}
37 onCheckedChange={handleCheckedChange}
38 className="peer data-checked:bg-input/50 data-unchecked:bg-input/50 absolute inset-0 !h-[inherit] !w-auto [&_span]:!h-full [&_span]:!w-[34px]"
39 />
40 <span className="peer-data-checked:text-muted-foreground/70 pointer-events-none relative ms-0.5 flex min-w-8 items-center justify-center text-center">
41 <SunIcon
42 size={16}
43 aria-hidden="true"
44 className={cn(
45 !checked &&
46 "fill-transparent group-hover:fill-foreground group-hover:rotate-12 group-hover:scale-110 transition-all duration-200 ease-out",
47 )}
48 />
49 </span>
50 <span className="peer-data-unchecked:text-muted-foreground/70 pointer-events-none relative me-0.5 flex min-w-8 items-center justify-center text-center">
51 <MoonIcon
52 size={16}
53 aria-hidden="true"
54 className={cn(
55 checked &&
56 "fill-transparent group-hover:fill-foreground group-hover:rotate-12 group-hover:scale-110 transition-all duration-200 ease-out",
57 )}
58 />
59 </span>
60 </div>
61 );
62};
63
64export default ThemeSwitch;

What it pulls in

npm packages

  • lucide-react
  • next-themes

Other registry items

  • switch

Files it writes

  • registry/theme-switch/theme-switch-toggle.tsx

Facts

Registry
UI Components
Type
registry:block
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-04
Last confirmed
today

Go to the source

ui.raulcarini.dev R4ULtv/ui on GitHub Raw registry item This item as JSON

More from UI Components

All 25 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
GitHub Contributionsgithub-contributionsUI ComponentsBlocksFreeno deps
GitHub Contributions Advancedgithub-contributions-advancedUI ComponentsBlocksFreeno deps
GitHub Contributions Advanced Fetchergithub-contributions-advanced-fetcherUI ComponentsBlocksFreeno deps
GitHub Contributions Fetchergithub-contributions-fetcherUI ComponentsBlocksFreeno deps
GitHub Forksgithub-forksUI ComponentsBlocksFree1 dep
GitHub Issuesgithub-issuesUI ComponentsBlocksFree1 dep
GitHub Pull Requestsgithub-prUI ComponentsBlocksFree1 dep
GitHub Starsgithub-starsUI ComponentsBlocksFree1 dep
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex