prefers-mode
TypeScript icon, indicating that this package has built-in type declarations

0.0.4-alpha-03 • Public • Published

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.

Package Sidebar

Install

npm i prefers-mode

Weekly Downloads

7

Version

0.0.4-alpha-03

License

MIT

Unpacked Size

23 kB

Total Files

6

Last publish

Collaborators

  • thegoleffect