1.1.0 • Published 6 years ago

js-media-queries v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

JS Media Queries

Allows the use of media queries in javascript. Caches result on first call, and then updates the value on window resize event.

How it Works

Example use case.

import setMediaQueries from 'js-media-queries';

// The media queries to register
// Must have a key registered for 0px
// Must be numbers only
const mediaQueries = {
  xxs: 0,
  xs: 320,
  s: 480,
  m: 768,
  l: 1024,
  xl: 1224,
  xxl: 1824
};

const getBreakPoint = setMediaQueries(mediaQueries);

// Call getBreakPoint to get the current break point
// The break point is cached and recalculated when the window is resized
// will return the key of the breakpoint (xxs, xs, s, m, l, xl)
const breakPoint = getBreakPoint();

// Example use case
const screenSize = {
  xxs: 'small screen mobile',
  xs: 'medium screen mobile',
  s: 'large screen mobile',
  m: 'iPad',
  l: 'small screen desktop',
  xl: 'medium screen desktop',
  xxl: 'large screen desktop'
};

console.log(`You are currently on a ${screenSize[breakPoint]}`);

Todo

  1. Add unit tests

Contributors

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago