isDarkMode

Type:Function
Status:stable
Since:1.0.0
Platform:js
@blackbyte.sugar.js.is

Detect if the user prefer the dark mode. Dark mode is detected using:

  • Match the media query prefers-color-scheme: dark
  • Check if an element has the class -dark on it or any of its parents (up to the document root)

Return

  1. -Boolean

    true if prefer dark mode, false if not

Example

import { isDarkMode } from '@blackbyte/sugar/is'
if (isDarkMode()) {
  // do something cool
}

Settings

  1. ctxwindowWindow

    The window context to use

  2. [rootNode]*-HTMLElement

    An optional root node to check for the -dark class

Todo

  • testsnormal