color-scheme-change

1.0.1 • Public • Published

color-scheme-change travis npm downloads javascript style guide

Detect system color scheme changes on the web (Dark Mode)

Listen for changes to the system color scheme in the web browser. Detect when the system switches between Light Mode and Dark Mode.

Built for and used on BitMidi, a free MIDI database. Works in the browser with browserify!

install

npm install color-scheme-change

usage

import colorSchemeChange from 'color-scheme-change'
 
colorSchemeChange(colorScheme => {
  console.log(`Entering ${colorScheme} mode`)
  // Prints either "Entering dark mode" or "Entering light mode"
})

API

remove = colorSchemeChange(onChange)

Listen for changes to the system color scheme in the web browser. Detect when the system switches between Light Mode and Dark Mode.

onChange

A callback function of the following interface: function(colorScheme) {} where colorScheme is either 'light' or 'dark'. The function is called whenever the system enters Light Mode or Dark Mode, respectively.

remove

When the returned remove function is called, all event listeners are cleaned up and the onChange function will no longer be called when the system color scheme changes.

license

MIT. Copyright (c) Feross Aboukhadijeh.

Package Sidebar

Install

npm i color-scheme-change

Weekly Downloads

11

Version

1.0.1

License

MIT

Unpacked Size

4.7 kB

Total Files

5

Last publish

Collaborators

  • feross