Components

React component for shadcn/ui

Theme Toggle

Switch between light and dark themes with animated, sound, and haptic feedback.

Loading…

Features

  • Switches between resolved light and dark themes through next-themes.
  • Animates the theme icon without causing a hydration mismatch.
  • Plays the TentUI metal click sound with subtle selection haptics.
  • Supports custom icons, button variants, and theme-change callbacks.

Installation

pnpm dlx shadcn@latest add @tentui/theme-toggle

Usage

Wrap your application with ThemeProvider from next-themes.

import { ThemeProvider } from "next-themes";
 
<ThemeProvider attribute="class">{children}</ThemeProvider>;

Then render the toggle.

import { ThemeToggle } from "@/components/theme-toggle";
<ThemeToggle variant="outline" />

Use onThemeChange when the application needs to synchronize related browser UI, such as a theme-color meta tag.

<ThemeToggle onThemeChange={(theme) => updateThemeColor(theme)} />

Accessibility

ThemeToggle preserves the underlying button's keyboard and focus behavior. Its accessible label describes the theme that will be activated. Sound and haptics are additive; the icon and document theme provide the visual state.

API reference

PropType

FAQ

How do I install the Theme Toggle with shadcn?

Run npx shadcn@latest add @tentui/theme-toggle after adding the @tentui registry to components.json (installation guide), or run npx shadcn@latest add https://tentui.com/r/theme-toggle.json without it. The CLI copies the toggle with its theme hook and click sound into your project, adds the shadcn button, and installs next-themes, motion, lucide-react, and web-haptics.

How do I add a dark mode toggle to the Next.js App Router?

Wrap your app in ThemeProvider from next-themes with attribute="class", then render <ThemeToggle /> anywhere inside it. The component is already a client component, so you can import it from a server layout or page.

Does the Theme Toggle cause a hydration mismatch or icon flash?

No. Until it mounts on the client it renders an empty placeholder with the label "Toggle theme", then shows the sun or moon for the resolved theme, so the server and client markup always match.

Does it support a system theme option?

It switches between light and dark only. When the theme you switch to matches the operating system, it stores "system" so the site keeps following the OS; add a menu with setTheme("system") if users need to pick it explicitly.

Can I use custom icons or sync the theme-color meta tag?

Yes. Pass lightIcon and darkIcon to replace the sun and moon, and use onThemeChange, which receives "light" or "dark", to update related browser UI. It also accepts every shadcn Button prop, such as variant and className.

Is the Theme Toggle free to use?

Yes. The Theme Toggle is free and source-available: the shadcn CLI copies its source into your project, and you can use it in unlimited personal and client projects under the TentUI License. The license doesn't allow redistributing or reselling the component itself.