Last active
September 30, 2021 09:50
-
-
Save makoru-hikage/cf493c164c3e9e7db6401c0aecebf8b6 to your computer and use it in GitHub Desktop.
A Rescript code used to check if a browser is in Dark Mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList | |
type mediaQueryList = { | |
matches: bool, | |
domString: string | |
} | |
// https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia | |
@val @scope("window") | |
external matchMedia: string => mediaQueryList = "matchMedia" | |
// Check if the browser is in Dark Mode using the MediaQuery | |
let isInDarkMode = matchMedia("(prefers-color-scheme: dark)").matches |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on this: https://stackoverflow.com/questions/56393880/how-do-i-detect-dark-mode-using-javascript