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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@anatoliygatt/dark-mode-toggle

v1.0.1

Published

A dark mode toggle component for React.

Downloads

391

Readme

📖 Table of Contents

🚀 Getting Started

⚡️ Quick Start

npm install @anatoliygatt/dark-mode-toggle @emotion/react @emotion/styled
import { useState } from 'react';
import { DarkModeToggle } from '@anatoliygatt/dark-mode-toggle';

function Example() {
  const [mode, setMode] = useState('dark');
  return (
    <DarkModeToggle
      mode={mode}
      dark="Dark"
      light="Light"
      size="lg"
      inactiveTrackColor="#e2e8f0"
      inactiveTrackColorOnHover="#f8fafc"
      inactiveTrackColorOnActive="#cbd5e1"
      activeTrackColor="#334155"
      activeTrackColorOnHover="#1e293b"
      activeTrackColorOnActive="#0f172a"
      inactiveThumbColor="#1e293b"
      activeThumbColor="#e2e8f0"
      onChange={(mode) => {
        setMode(mode);
      }}
    />
  );
}

💻 Live Demo

Open in CodeSandbox

⚙️ Configuration

DarkModeToggle supports the following props:

| Prop | Type | Default value | Description | | -------------------------- | -------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | mode | string | dark | The color scheme mode. | | dark | string | undefined | The dark mode label text. | | light | string | undefined | The light mode label text. | | onChange | Function | undefined | The callback invoked when the mode changes. | | size | string | sm | The size of the toggle switch (w/o labels). There are 3 available sizes:sm — 48x28pxmd — 72x42pxlg — 96x56pxN.B. If label(s) are used, their font size is going to scale proportionally to the toggle switch as follows:sm — 12pxmd — 18pxlg — 24px | | inactiveLabelColor | string | #b9bdc1 | The color of the label(s) when the toggle switch is in an inactive/off state. | | inactiveLabelColorOnHover | string | #fcfefe | The color of the label(s) on hover, when the toggle switch is in an inactive/off state. | | inactiveLabelColorOnActive | string | #cdd1d5 | The color of the label(s) on active, when the toggle switch is in an inactive/off state. | | activeLabelColor | string | #5b5e62 | The color of the label(s) when the toggle switch is in an active/on state. | | activeLabelColorOnHover | string | #404346' | The color of the label(s) on hover, when the toggle switch is in an active/on state. | | activeLabelColorOnActive | string | #010101 | The color of the label(s) on active, when the toggle switch is in an active/on state. | | inactiveTrackColor | string | #dce0e3 | The color of the track when the toggle switch is in an inactive/off state. | | inactiveTrackColorOnHover | string | #fcfefe | The color of the track on hover, when the toggle switch is in an inactive/off state. | | inactiveTrackColorOnActive | string | #cdd1d5 | The color of the track on active, when the toggle switch is in an inactive/off state. | | activeTrackColor | string | #404346 | The color of the track when the toggle switch is in an active/on state. | | activeTrackColorOnHover | string | #2d2f31 | The color of the track on hover, when the toggle switch is in an active/on state. | | activeTrackColorOnActive | string | #141516 | The color of the track on active, when the toggle switch is in an active/on state. | | inactiveThumbColor | string | #2d2f31 | The color of the thumb when the toggle switch is in an inactive/off state. | | activeThumbColor | string | #dce0e3 | The color of the thumb when the toggle switch is in an active/on state. | | focusRingColor | string | rgb(59 130 246 / 0.5) | The color of the toggle switch's focus ring. |

♿️ Accessibility

In order to comply with the web accessibility standards, we must make use of the ariaLabel prop, like so:

function AccessibleExample() {
  return <DarkModeToggle ariaLabel="Toggle color scheme" />;
}

👨🏼‍⚖️ License

MIT