0.1.5 • Published 6 months ago

@agilxp/dark-mode-toggle v0.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

DarkModeToggle

What is it?

A component you can use to toggle dark mode in a React app based on Tailwind class toggling.

Getting started

Requirements

The component uses @heroicons/react and @headlessui/react. It also assumes that you are using Tailwind and have it properly configured.

Usage

npm install --save DarkModeToggle
or
yarn add DarkModeToggle

Change the tailwind.config.js to

/** @type {import('tailwindcss').Config} */
module.exports = {
    // ...
    darkMode: 'class',
    // ...
}

And add the component where you want to toggle light/dark mode with

import DarkModeToggle from 'DarkModeToggle';

<DarkModeToggle/>

Properties

All props are optionals and used to override a default.

prop namedefault
lightIconSunIcon
darkIconMoonIcon
systemIconComputerDesktopIcon

Capabilities

There are 3 possibilities when toggling:

  • light mode
  • dark mode
  • system (this will change based on the system preferences)

It uses media query to check the system settings and local storage to save an eventual override. This means that users will have their choices saved on the next visit.

0.1.5

6 months ago

0.1.4

6 months ago

0.1.3

6 months ago

0.1.2

6 months ago

0.1.1

6 months ago