Componentmedia2.53 KB gzipZero dependencies

Theme Toggle

Theme switcher with day and night flip animation.

Preview

Live Preview
Open ↗

Installation

Tokens guide →

Add to your project via CLI (zero dependencies, code you own):

npx bigbullui add theme-toggle

Or install the full npm package:

npm install bigbullui

Usage

tsx4 lines
import { ThemeToggle } from "@/components/ui/theme-toggle"; <ThemeToggle /><ThemeToggle variant="compact" />

Source code

theme-toggle.tsx + 1 helper

Zero 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 />
PropTypeDescription
darkbooleanControlled dark state
defaultDarkbooleanDefault dark state for uncontrolled mode
onToggle(isDark: boolean) => voidCallback fired when the theme state flips
syncHtmlDarkbooleanWhether to sync the 'dark' class on document.documentElement (default: true)
enableSoundbooleanWhether 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
classNamestringOptional Tailwind or custom CSS classes merged with component styles.