Last active
December 8, 2018 19:46
-
-
Save sht5/6ccb59b93bc845b54eca9dafa1720d86 to your computer and use it in GitHub Desktop.
emotionJS media queries example with facepaint
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
//this part needs to be defined only once in an app | |
//media_queries_definition.js | |
import facepaint from 'facepaint' | |
const breakpoints = [768, 1200]; | |
export const mq = facepaint( | |
breakpoints.map(bp => `@media (min-width: ${bp}px)`) | |
) | |
// some_component.styles.js | |
import styled from 'react-emotion' | |
import {mq} from 'css/general_styles.styles'; | |
export const MyButton = styled('div')` | |
margin-left:auto; | |
margin-right: auto; | |
background-color: ${props => props.primary ? "blue" : "black"} | |
${mq({ | |
height: [25, 50, 100], | |
width: [100, 200, 300], | |
})} | |
`; | |
// some_component.js | |
import React from 'react'; | |
import {MyButton} from './some_component.styles.js' | |
const SomeComponent= () => { | |
return ( | |
<MyButton primary> click me </MyButton> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment