UNPKG

1.37 kBJavaScriptView Raw
1import { css } from 'styled-components'
2
3const sizes = {
4 phone: 321,
5 phoneMax: 414,
6 tablet: 768,
7 mobileNav: 889,
8 tabletMax: 960,
9 laptop: 1024,
10 desktop: 1440
11}
12
13const breakpoints = {
14 landscape: '(orientation: landscape)',
15 portrait: '(orientation: portrait)'
16}
17
18Object.keys(sizes).forEach((label) => {
19 breakpoints[`below${label.charAt(0).toUpperCase()}${label.substr(1)}`] =
20 `(max-width: ${sizes[label] - 1}px)`
21 breakpoints[`above${label.charAt(0).toUpperCase()}${label.substr(1)}`] =
22 `(min-width: ${sizes[label]}px)`
23})
24
25export { breakpoints, sizes }
26
27export default Object.keys(sizes).reduce((accumulator, label) => {
28 // use em in breakpoints to work properly cross-browser and support users
29 // changing their browsers font-size: https://zellwk.com/blog/media-query-units/
30 const remSize = sizes[label] / 10
31 accumulator[label] = (...args) => css`
32 @media (min-width: ${remSize}em) {
33 ${css(...args)}
34 }
35 `
36 return accumulator
37}, {})
38
39export const breakpointsVerbose = Object.keys(breakpoints).reduce((accumulator, label) => {
40 // use em in breakpoints to work properly cross-browser and support users
41 // changing their browsers font-size: https://zellwk.com/blog/media-query-units/
42 accumulator[label] = (...args) => css`
43 @media ${breakpoints[label]} {
44 ${css(...args)}
45 }
46 `
47 return accumulator
48}, {})