GithubHelp home page GithubHelp logo

anatoliygatt / dark-mode-toggle Goto Github PK

View Code? Open in Web Editor NEW
116.0 3.0 3.0 1.83 MB

๐ŸŒ“ A dark mode toggle component for React.

Home Page: https://dark-mode-toggle-sb.netlify.app

License: MIT License

Shell 0.78% TypeScript 98.83% HTML 0.38%
react accessible component dark-mode dark-mode-toggle javascript react-component toggle typescript

dark-mode-toggle's Introduction


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:

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 โ€” 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
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

dark-mode-toggle's People

Contributors

anatoliygatt avatar dependabot[bot] avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.