Created
October 28, 2019 15:06
-
-
Save eunicekokor/eb8b150fceed8ba5c8c671d8c61a8ebc to your computer and use it in GitHub Desktop.
handling breakpoints /w emotion
This file contains 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
/** @jsx jsx */ | |
import { jsx, css } from '@emotion/core' | |
const breakpoints = {'mobile': 320, 'tablet':768, 'desktop':992, 'desktop-xl': 1200}; | |
const mq = (size) => `@media (min-width: ${breakpoints[size]}px)` | |
render( | |
<div> | |
<div | |
css={{ | |
color: 'green', | |
[mq('mobile')]: { | |
color: 'gray' | |
}, | |
[mq('tablet')]: { | |
color: 'hotpink' | |
} | |
}} | |
> | |
Some text! | |
</div> | |
<p | |
css={css` | |
color: green; | |
${mq('mobile')} { | |
color: gray; | |
} | |
${mq('tablet')} { | |
color: hotpink; | |
} | |
`} | |
> | |
Some other text! | |
</p> | |
</div> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment