npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@aniruddha1806/theme-toggle

v1.0.3

Published

A lightweight, customizable light/dark theme toggle for React

Readme

React Theme Toggle

A lightweight, customizable theme toggle component for React applications with TypeScript support. Easily switch between light and dark themes with smooth transitions and persistent storage.

Installation

npm install @aniruddha1806/theme-toggle

Features

  • 🌙 Light and dark theme switching
  • 💾 Persistent theme storage with localStorage
  • 🎨 Customizable icons and colors
  • ⚡ Smooth transitions and animations
  • 🔧 Flexible configuration options
  • 📱 Responsive design
  • ♿ Accessibility features with ARIA labels
  • 🪶 Zero dependencies and lightweight
  • 📦 TypeScript support with full type definitions

Quick Start

import { ThemeProvider, ThemeToggle } from '@aniruddha1806/theme-toggle';

function App() {
  return (
    <ThemeProvider>
      <div>
        <header>
          <h1>My App</h1>
          <ThemeToggle />
        </header>
        <main>
          <p>Your content here...</p>
        </main>
      </div>
    </ThemeProvider>
  );
}

export default App;

Components

ThemeProvider

Wrap your application with the ThemeProvider to enable theme functionality throughout your app.

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | children | ReactNode | required | Child components to wrap | | defaultTheme | "light" \\| "dark" | "light" | Initial theme when no saved preference exists | | overrideTextColor | boolean | true | Whether to automatically adjust text colors |

ThemeToggle

A button component that toggles between light and dark themes.

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | size | number | 24 | Size of the toggle button in pixels | | className | string | "" | Additional CSS class for styling | | lightIconColor | string | "#FDB813" | Color of the sun icon (light mode) | | darkIconColor | string | "#FFFFFF" | Color of the moon icon (dark mode) |

useTheme Hook

Access theme state and controls from any component within the ThemeProvider.

Returns

| Property | Type | Description | |----------|------|-------------| | theme | "light" \\| "dark" | Current active theme | | toggleTheme | () => void | Function to toggle between themes | | overrideTextColor | boolean | Whether text color override is enabled |

Examples

Basic Usage

Simple theme toggle with default settings:

import { ThemeProvider, ThemeToggle } from '@aniruddha1806/theme-toggle';

function BasicExample() {
  return (
    <ThemeProvider defaultTheme="dark">
      <div style={{ padding: '20px' }}>
        <h1>Welcome to My App</h1>
        <ThemeToggle />
        <p>This content will automatically adapt to the selected theme.</p>
      </div>
    </ThemeProvider>
  );
}

Custom Styled Toggle

Customize the appearance of the theme toggle:

import { ThemeProvider, ThemeToggle } from '@aniruddha1806/theme-toggle';

function CustomStyledExample() {
  return (
    <ThemeProvider>
      <div style={{ padding: '20px' }}>
        <h1>Custom Theme Toggle</h1>
        <ThemeToggle
          size={32}
          lightIconColor="#FF6B35"
          darkIconColor="#4ECDC4"
          className="custom-toggle"
        />
      </div>
    </ThemeProvider>
  );
}

Using the useTheme Hook

Access theme state in any component:

import { ThemeProvider, ThemeToggle, useTheme } from '@aniruddha1806/theme-toggle';

function ThemeAwareComponent() {
  const { theme, toggleTheme } = useTheme();

  return (
    <div style={{
      padding: '20px',
      backgroundColor: theme === 'dark' ? '#2a2a2a' : '#f5f5f5',
      borderRadius: '8px'
    }}>
      <h2>Current theme: {theme}</h2>
      <p>This component adapts its styling based on the current theme.</p>
      <button onClick={toggleTheme}>
        Switch to {theme === 'light' ? 'dark' : 'light'} mode
      </button>
    </div>
  );
}

function App() {
  return (
    <ThemeProvider>
      <div style={{ padding: '20px' }}>
        <ThemeToggle />
        <ThemeAwareComponent />
      </div>
    </ThemeProvider>
  );
}

Navigation Bar with Theme Toggle

Integrate theme toggle into a navigation bar:

import { ThemeProvider, ThemeToggle, useTheme } from '@aniruddha1806/theme-toggle';

function NavigationBar() {
  const { theme } = useTheme();

  const navStyle = {
    display: 'flex',
    justifyContent: 'space-between',
    alignItems: 'center',
    padding: '1rem 2rem',
    backgroundColor: theme === 'dark' ? '#1a1a1a' : '#ffffff',
    borderBottom: `1px solid \${theme === 'dark' ? '#333' : '#e0e0e0'}`,
    boxShadow: '0 2px 4px rgba(0,0,0,0.1)'
  };

  const logoStyle = {
    fontSize: '1.5rem',
    fontWeight: 'bold',
    color: theme === 'dark' ? '#ffffff' : '#333333'
  };

  return (
    <nav style={navStyle}>
      <div style={logoStyle}>MyApp</div>
      <div style={{ display: 'flex', alignItems: 'center', gap: '1rem' }}>
        <a href="/about" style={{ color: theme === 'dark' ? '#ffffff' : '#333333' }}>
          About
        </a>
        <a href="/contact" style={{ color: theme === 'dark' ? '#ffffff' : '#333333' }}>
          Contact
        </a>
        <ThemeToggle size={28} />
      </div>
    </nav>
  );
}

function App() {
  return (
    <ThemeProvider>
      <NavigationBar />
      <main style={{ padding: '2rem' }}>
        <h1>Welcome to MyApp</h1>
        <p>Toggle the theme using the button in the navigation bar.</p>
      </main>
    </ThemeProvider>
  );
}

TypeScript Usage

The component provides full TypeScript support:

import { 
  ThemeProvider, 
  ThemeToggle, 
  useTheme,
  ThemeProviderProps,
  ThemeToggleProps,
  ThemeContextType
} from '@aniruddha1806/theme-toggle';

interface AppProps {
  initialTheme?: 'light' | 'dark';
}

const App: React.FC<AppProps> = ({ initialTheme = 'light' }) => {
  const themeProviderProps: ThemeProviderProps = {
    defaultTheme: initialTheme,
    overrideTextColor: true
  };

  return (
    <ThemeProvider {...themeProviderProps}>
      <AppContent />
    </ThemeProvider>
  );
};

const AppContent: React.FC = () => {
  const { theme, toggleTheme }: ThemeContextType = useTheme();

  const toggleProps: ThemeToggleProps = {
    size: 28,
    lightIconColor: '#f39c12',
    darkIconColor: '#ecf0f1'
  };

  return (
    <div>
      <h1>Current theme: {theme}</h1>
      <ThemeToggle {...toggleProps} />
      <button onClick={toggleTheme}>
        Toggle Theme Programmatically
      </button>
    </div>
  );
};