Theme Switcher
ncdai/theme-switcherUnverifiedComponent
Toggle between system, light, and dark themes in Next.js apps.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/Sumeet011/Portfolio/main/public/r/theme-switcher.jsonSource
1"use client"23import type { JSX } from "react"4import { useSyncExternalStore } from "react"5import { motion } from "motion/react"6import { useTheme } from "next-themes"78import { IconPlaceholder } from "@/registry/icons/icon-placeholder"910function ThemeOption({11 icon,12 value,13 isActive,14 onClick,15}: {16 icon: JSX.Element17 value: string18 isActive?: boolean19 onClick: (value: string) => void20}) {21 return (22 <button23 data-active={isActive}24 className="relative flex size-8 items-center justify-center rounded-full text-muted-foreground transition-[color] hover:text-foreground data-[active=true]:text-foreground [&_svg]:size-4"25 role="radio"26 aria-checked={isActive}27 aria-label={`Switch to ${value} theme`}28 onClick={() => onClick(value)}29 >30 {icon}3132 {isActive && (33 <motion.span34 layoutId="theme-option"35 transition={{ type: "spring", bounce: 0.3, duration: 0.6 }}36 className="absolute inset-0 rounded-full border"37 />38 )}39 </button>40 )41}4243const THEME_OPTIONS = [44 {45 icon: (46 <IconPlaceholder47 lucide="MonitorIcon"48 tabler="IconDeviceDesktop"49 hugeicons="ComputerIcon"50 phosphor="DesktopIcon"51 remixicon="RiComputerLine"52 />53 ),54 value: "system",55 },56 {57 icon: (58 <IconPlaceholder59 lucide="SunIcon"60 tabler="IconSun"61 hugeicons="Sun03Icon"62 phosphor="SunIcon"63 remixicon="RiSunLine"64 />65 ),66 value: "light",67 },68 {69 icon: (70 <IconPlaceholder71 lucide="MoonIcon"72 tabler="IconMoon"73 hugeicons="Moon02Icon"74 phosphor="MoonIcon"75 remixicon="RiMoonLine"76 />77 ),78 value: "dark",79 },80]8182function ThemeSwitcher() {83 const { theme, setTheme } = useTheme()8485 const isMounted = useSyncExternalStore(86 () => () => {},87 () => true,88 () => false89 )9091 if (!isMounted) {92 return <div className="flex h-8 w-24" />93 }9495 return (96 <motion.div97 key={String(isMounted)}98 initial={{ opacity: 0 }}99 animate={{ opacity: 1 }}100 transition={{ duration: 0.3 }}101 className="inline-flex items-center overflow-clip rounded-full bg-background inset-ring-1 inset-ring-border"102 role="radiogroup"103 >104 {THEME_OPTIONS.map((option) => (105 <ThemeOption106 key={option.value}107 icon={option.icon}108 value={option.value}109 isActive={theme === option.value}110// … truncated
What it pulls in
npm packages
Files it writes
More from ncdai
All 48 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Apple Hello Effectapple-hello-effect | ncdai | Components | Unverified | 1 dep | |
| Apple Hello Effect - Hindiapple-hello-effect-hindi | ncdai | Components | Unverified | 1 dep | |
| Apple Hello Effect - Spanishapple-hello-effect-spanish | ncdai | Components | Unverified | 1 dep | |
| Apple Hello Effect - Vietnameseapple-hello-effect-vietnamese | ncdai | Components | Unverified | 1 dep | |
| Brand Assets Menubrand-assets-menu | ncdai | Components | Unverified | 1 dep | |
| chevrons-up-down-iconchevrons-up-down-icon | ncdai | Components | Unverified | 1 dep | |
| Code Block Commandcode-block-command | ncdai | Components | Unverified | 4 deps · 2 files | |
| Consent Managerconsent-manager | ncdai | Components | Unverified | 1 dep |
