Skip to content

Simple dark mode switcher using css custom property

Notifications You must be signed in to change notification settings

brtheo/darkmode-switcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Darkmode Switcher

Simple way to toggle between dark or light mode based on the use of CSS custom property. Default applied mode is the one corresponding to the user's preference.

Installation

npm install @brtheo/darkmode-switcher --save

Usage

By default the name of the toggling css class and the local storage key is darkmode. You can change these names in each functions' parameters.

:root {
  --bgcolor: var(--white)
}
.darkmode {
  --bgcolor: var(--black)
}
// Main.js
import {initDarkmode} from './darkmode-switcher'
initDarkmode()

//myButton.js
import {switchDarkmode} from './darkmode-switcher'
handleClick = () => switchDarkmode()

About

Simple dark mode switcher using css custom property

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published