coderplanets_web icon indicating copy to clipboard operation
coderplanets_web copied to clipboard

clearfy media-query break point

Open mydearxym opened this issue 7 years ago • 1 comments
trafficstars

image

see reference

mydearxym avatar Jun 30 '18 03:06 mydearxym

a styled-compoentn example:

const sizes = {
  desktop: 992,
  tablet: 768,
  phone: 376
}

// Iterate through the sizes and create a media template
const media = Object.keys(sizes).reduce((acc, label) => {
  acc[label] = (...args) => css`
    @media (max-width: ${sizes[label] / 16}em) {
      ${css(...args)}
    }
  `

  return acc
}, {})

const Content = styled.div`
  height: 3em;
  width: 3em;
  background: papayawhip;

  /* Now we have our methods on media and can use them instead of raw queries */
  ${media.desktop`background: dodgerblue;`}
  ${media.tablet`background: mediumseagreen;`}
  ${media.phone`background: palevioletred;`}
`;

render(
  <Content />
);

mydearxym avatar Jun 30 '18 04:06 mydearxym