Created
December 23, 2015 11:01
-
-
Save kitze/1e34d2376775529f2bef to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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