1.0.1 • Published 1 year ago

@anatoliygatt/dark-mode-toggle v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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