0.0.4-alpha-03 • Published 4 years ago
prefers-mode v0.0.4-alpha-03
prefers-mode
A React library for detecting css media query system preferences: prefers-color-scheme
, prefers-reduced-motion
, & prefers-contrast
.
Usage
# Next.js example
import usePrefersMode, { SCHEME_PREFS, MOTION_PREFS, CONTRAST_PREFS } from 'prefers-mode'
const IndexPage = (props) => {
const prefs = usePrefersMode()
const cls = [
prefs.colorScheme === SCHEME_PREFS.DARK ? 'dark-mode' : 'light-mode',
prefs.reducedMotion === MOTION_PREFS.REDUCE ? 'reduced-motion' : 'motion',
prefs.contrast === CONTRAST_PREFS.MORE ? 'high-contrast' : 'normal-contrast'
].join(' ')
return <div className={cls}>Hello</div>
}
export default IndexPage
See example for a more detailed working Next.js example.
0.0.4-alpha-01
4 years ago
0.0.4-alpha-03
4 years ago
0.0.4-alpha-02
4 years ago
0.0.3
4 years ago
0.0.2
4 years ago
0.0.1
4 years ago