Skip to content

Instantly share code, notes, and snippets.

@sht5
Last active December 8, 2018 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sht5/6ccb59b93bc845b54eca9dafa1720d86 to your computer and use it in GitHub Desktop.
Save sht5/6ccb59b93bc845b54eca9dafa1720d86 to your computer and use it in GitHub Desktop.
emotionJS media queries example with facepaint
//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