Last active
September 7, 2022 17:07
-
-
Save azamatsmith/a56fb3f8cd3657db7a6af6ce1f8ea591 to your computer and use it in GitHub Desktop.
Reusable media queries with Styled Components
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
import { css } from 'styled-components'; | |
export const breakpoint = { | |
medium: '48em', | |
large: '64em', | |
}; | |
export const media = { | |
// ns = not small | |
ns: (...args) => | |
css` | |
@media screen and (min-width: ${breakpoint.medium}) { | |
${css(...args)} | |
} | |
`, | |
medium: (...args) => | |
css` | |
@media screen and (min-width: ${breakpoint.medium}) and (max-width: ${breakpoint.large}) { | |
${css(...args)} | |
} | |
`, | |
large: (...args) => | |
css` | |
@media screen and (min-width: ${breakpoint.large}) { | |
${css(...args)} | |
} | |
`, | |
}; |
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
import styled from 'styled-components'; | |
import { media } from 'utils/mediaQuery'; | |
const Title = styled.h1` | |
font-size: 24px; | |
${media.medium` | |
font-size: 30px; | |
`} | |
${media.large` | |
font-size: 36px; | |
`} | |
`; | |
export default Title; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment