Last active
March 7, 2023 04:01
-
-
Save xjeeh/529075192e861c3f290634fa590a6deb to your computer and use it in GitHub Desktop.
Styled Component Media Query
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 "./media"; | |
export const TitleContainer = styled.div` | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
flex-direction: column; | |
padding: 3rem; | |
${media.desktop` | |
height: 245px; | |
padding: 3rem 6rem; | |
`}; | |
${media.widescreen` | |
padding: 3rem 6rem; | |
height: 345px; | |
`}; | |
`; |
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"; | |
const breakpoints = { | |
uhd: 1980, | |
widescreen: 1366, | |
desktop: 1024, | |
tablet: 768, | |
}; | |
export const media = Object.keys(breakpoints).reduce((acc: { [key: string]: (...args: any) => any }, label) => { | |
acc[label] = (...args) => css` | |
@media (min-width: ${breakpoints[label as keyof typeof breakpoints]}px) { | |
${css(...args as [any])}; | |
} | |
`; | |
return acc; | |
}, {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment