Skip to content

Instantly share code, notes, and snippets.

@kitze
Created December 23, 2015 11:01
Show Gist options
  • Save kitze/1e34d2376775529f2bef to your computer and use it in GitHub Desktop.
Save kitze/1e34d2376775529f2bef to your computer and use it in GitHub Desktop.
import is from '../../plugins/is';
const minWidth = 'min-width';
const maxWidth = 'max-width';
const query = (size, measure) => {
return `@media (${measure}: ${size}px)`
};
const matchMedia = (val) => {
return window.matchMedia(`(${val})`).matches
}
const matchOrientation = (orientation) => {
return matchMedia(`orientation: ${orientation}`)
}
const checkOrRules = (check, rules) => {
if (rules) {
return check ? rules : {}
}
return check;
}
const media = {
width: {
larger: function (size, rules) {
return {
[query(size, minWidth)]: rules
}
}
},
is: {
tablet: {
large: function (rules) {
return checkOrRules(is.tablet(), rules)
},
small: function (rules) {
return checkOrRules(is.tablet(), rules)
}
},
landscape: function (rules) {
return checkOrRules(matchOrientation('landscape'), rules)
},
portrait: function (rules) {
return checkOrRules(matchOrientation('portrait'), rules)
}
}
}
export default media;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment