Componentmedia2.53 KB gzipZero dependencies
Theme Toggle
Theme switcher with day and night flip animation.
Preview
Live Preview
Installation
Tokens guide →Add to your project via CLI (zero dependencies, code you own):
npx bigbullui add theme-toggleOr install the full npm package:
npm install bigbulluiUsage
tsx4 lines
import { ThemeToggle } from "@/components/ui/theme-toggle"; <ThemeToggle /><ThemeToggle variant="compact" />Source code
theme-toggle.tsx + 1 helperZero third-party dependencies (2 local files shown in tabs below).
tsxtheme-toggle.tsx415 lines
"use client"; import * as React from "react";import { cn } from "./lib/utils"; export interface ThemeToggleProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onChange" | "onToggle"> { /** Controlled dark state */ dark?: boolean; /** Default dark state for uncontrolled mode */ defaultDark?: boolean; /** Callback fired when the theme state flips */ onToggle?: (isDark: boolean) => void; /** Whether to sync the 'dark' class on document.documentElement (default: true) */ syncHtmlDark?: boolean; /** Whether to play a synthesized mechanical ticket punch click sound (default: true) */ enableSound?: boolean; /** Display style: 'ticket' (full ticket stub) or 'compact' (pocket pass) */Props
Interactive Prop Playground
Tweak parsed AST props below to generate ready-to-paste JSX.
tsx3 lines
import { ThemeToggle } from "@/components/ui/theme-toggle"; <ThemeToggle />| Prop | Type | Description |
|---|---|---|
| dark | boolean | Controlled dark state |
| defaultDark | boolean | Default dark state for uncontrolled mode |
| onToggle | (isDark: boolean) => void | Callback fired when the theme state flips |
| syncHtmlDark | boolean | Whether to sync the 'dark' class on document.documentElement (default: true) |
| enableSound | boolean | Whether to play a synthesized mechanical ticket punch click sound (default: true) |
| variant | "ticket" | "compact" | Display style: 'ticket' (full ticket stub) or 'compact' (pocket pass) |
| size | "sm" | "default" | "lg" | Size scale |
| className | string | Optional Tailwind or custom CSS classes merged with component styles. |