Socket
Socket
Sign inDemoInstall

@anatoliygatt/dark-mode-toggle

Package Overview
Dependencies
64
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @anatoliygatt/dark-mode-toggle

A dark mode toggle component for React.


Version published
Maintainers
1
Created

Changelog

Source

1.0.1 (2022-12-24)

Bug Fixes

  • README: update github ci workflow status badge url (1908ec9)

Readme

Source

dark-mode-toggle Demo

dark-mode-toggle

A dark mode toggle component for React. Inspired by Tim Silva's Dark/Light Mode Toggle Switch Pattern A11y Dribbble shot.


Github CI Workflow Status NPM Version License


📖 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:

PropTypeDefault valueDescription
modestringdarkThe color scheme mode.
darkstringundefinedThe dark mode label text.
lightstringundefinedThe light mode label text.
onChangeFunctionundefinedThe callback invoked when the mode changes.
sizestringsmThe size of the toggle switch (w/o labels). There are 3 available sizes:
  • sm — 48x28px
  • md — 72x42px
  • lg — 96x56px
N.B. If label(s) are used, their font size is going to scale proportionally to the toggle switch as follows:
  • sm — 12px
  • md — 18px
  • lg — 24px
inactiveLabelColorstring#b9bdc1The color of the label(s) when the toggle switch is in an inactive/off state.
inactiveLabelColorOnHoverstring#fcfefeThe color of the label(s) on hover, when the toggle switch is in an inactive/off state.
inactiveLabelColorOnActivestring#cdd1d5The color of the label(s) on active, when the toggle switch is in an inactive/off state.
activeLabelColorstring#5b5e62The color of the label(s) when the toggle switch is in an active/on state.
activeLabelColorOnHoverstring#404346'The color of the label(s) on hover, when the toggle switch is in an active/on state.
activeLabelColorOnActivestring#010101The color of the label(s) on active, when the toggle switch is in an active/on state.
inactiveTrackColorstring#dce0e3The color of the track when the toggle switch is in an inactive/off state.
inactiveTrackColorOnHoverstring#fcfefeThe color of the track on hover, when the toggle switch is in an inactive/off state.
inactiveTrackColorOnActivestring#cdd1d5The color of the track on active, when the toggle switch is in an inactive/off state.
activeTrackColorstring#404346The color of the track when the toggle switch is in an active/on state.
activeTrackColorOnHoverstring#2d2f31The color of the track on hover, when the toggle switch is in an active/on state.
activeTrackColorOnActivestring#141516The color of the track on active, when the toggle switch is in an active/on state.
inactiveThumbColorstring#2d2f31The color of the thumb when the toggle switch is in an inactive/off state.
activeThumbColorstring#dce0e3The color of the thumb when the toggle switch is in an active/on state.
focusRingColorstringrgb(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

Keywords

FAQs

Last updated on 24 Dec 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc