Created
December 29, 2020 15:44
-
-
Save albertdugba/766380c5a29c9706cf15dcf7ddd0a93b to your computer and use it in GitHub Desktop.
Media Query in styled-components
This file contains hidden or 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
import styled,{css} from 'styled-components'; | |
const size = { | |
small: 400, | |
medium: 960, | |
large: 1140, | |
}; | |
const mediaQuery = Object.keys(size).reduce((acc, label) => { | |
acc[label] = (...args) => css` | |
@media (min-width: ${size[label]}px) { | |
${css(...args)} | |
} | |
`; | |
return acc; | |
}, {}); | |
//Usage | |
const Header = styled.div` | |
${mediaQuery.small` | |
background:red; | |
`} | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment