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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-night-toggle

v1.2.2

Published

A modern dark mode toggle for ReactJs with smooth animations.

Downloads

10

Readme

React Night Toggle

npm version build license downloads

Interactive sun and moon transition

✨ Overview

React Night Toggle is a lightweight and customizable dark mode switch for React apps, built with TypeScript, framer-motion, and lucide-react.
Easily add a night/day theme toggle with smooth animations, customizable icons, and flexible color options.


🚀 Features

  • 🌙 Clean & modern dark mode toggle
  • ⚡ Built with TypeScript
  • 🎨 Customizable icons (uses lucide-react by default)
  • 🎨 Customizable colors via sunColor & moonColor props
  • ✨ Smooth Framer Motion animations
  • 📦 Lightweight and easy to use in any React project

📦 Installation

npm install react-night-toggle
# or
yarn add react-night-toggle
# or
pnpm add react-night-toggle

🔧 Usage

1️⃣ Basic Usage Example

import { useState } from 'react';
import { DarkModeSwitch } from 'react-night-toggle';

export default function App() {
  const [dark, setDark] = useState(false);

  const toggleDarkMode = (checked: boolean) => setDark(checked);

  return (
    <div className={dark ? 'dark' : ''}>
      <DarkModeSwitch
        checked={dark}
        onChange={toggleDarkMode}
        sunColor="orange" // optional, defaults to currentColor
        moonColor="black" // optional, defaults to currentColor
      />
      <h1>{dark ? '🌙 Dark Mode' : '☀️ Light Mode'}</h1>
    </div>
  );
}

2️⃣ Custom Icons Example

You can pass your own icons instead of the default Sun/Moon:

import { useState } from 'react';
import { DarkModeSwitch } from 'react-night-toggle';
import { CloudSun, Star } from 'lucide-react';

export default function App() {
  const [dark, setDark] = useState(false);

  // onChange handler to toggle dark mode
  const toggleDarkMode = (checked: boolean) => setDark(checked);

  return (
    <div>
      <DarkModeSwitch
        checked={dark}
        onChange={toggleDarkMode}
        lightIcon={<CloudSun size={24} />}
        darkIcon={<Star size={24} />}
      />
      <h2>{dark ? 'Dark Mode Enabled 🌙' : 'Light Mode Enabled ☀️'}</h2>
    </div>
  );
}

3️⃣ Follow System Theme Example

You can automatically follow the user’s system color scheme by setting followSystem to true:

import { useState } from 'react';
import { DarkModeSwitch } from 'react-night-toggle';

export default function App() {
  const [dark, setDark] = useState(false);

  return (
    <div>
      <DarkModeSwitch followSystem checked={dark} onChange={setDark} size={40} />
      <h2>{dark ? 'Dark Mode Enabled 🌙' : 'Light Mode Enabled ☀️'}</h2>
    </div>
  );
}

4️⃣ Colored Sun & Moon Example

You can customize the colors of the Sun and Moon icons:

import { useState } from 'react';
import { DarkModeSwitch } from 'react-night-toggle';

export default function App() {
  const [dark, setDark] = useState(false);

  return (
    <div>
      <DarkModeSwitch
        checked={dark}
        onChange={setDark}
        size={56}
        sunColor="orange"
        moonColor="blueviolet"
      />
      <h2>{dark ? 'Dark Mode Enabled 🌙' : 'Light Mode Enabled ☀️'}</h2>
    </div>
  );
}

5️⃣ Large Toggle Example

You can increase the size of the toggle button by passing a numeric value or a string:

import { useState } from 'react';
import { DarkModeSwitch } from 'react-night-toggle';

export default function App() {
  const [dark, setDark] = useState(false);

  return (
    <div>
      <DarkModeSwitch checked={dark} onChange={setDark} size={72} />
      <h2>{dark ? 'Dark Mode Enabled 🌙' : 'Light Mode Enabled ☀️'}</h2>
    </div>
  );
}

✨ This way you can use any React node (Lucide, Material UI, custom SVGs, etc.) for icons.


⚙️ Props

| Prop | Type | Default | Description | | -------------- | ---------------------------- | -------------- | -------------------------------------------------------------------------------------------- | | checked | boolean | — (required) | Whether dark mode is active (true = dark, false = light). | | onChange | (checked: boolean) => void | — (required) | Callback fired when the toggle is switched. | | size | number \| string | 24 | Size of the toggle button (applied to both icons). | | lightIcon | React.ReactNode | <Sun /> | Custom icon for light mode. | | darkIcon | React.ReactNode | <Moon /> | Custom icon for dark mode. | | sunColor | string | currentColor | Color of the default Sun icon. Ignored if lightIcon is provided. | | moonColor | string | currentColor | Color of the default Moon icon. Ignored if darkIcon is provided. | | followSystem | boolean | false | Automatically follow the user’s system color scheme. Overrides checked when set to true. |


🤝 Contributing

Contributions are welcome!
Feel free to open an issue or submit a pull request.


⭐ Show your support

Give a ⭐️ if this project helped you!