Last active
June 19, 2023 07:45
-
-
Save mortezashojaei/72b23a1ae50af655255682e726c26c11 to your computer and use it in GitHub Desktop.
use media query in styled components ( DRY )
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
const mediaQuery = (key: keyof typeof screens) => { | |
return (style: TemplateStringsArray | String) => `@media (max-width: ${screens[key]}px) { ${style} }`; | |
}; |
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
export default { | |
wideDesktop: 1920, | |
desktop: 1280, | |
smallDesktop: 1024, | |
largeTablet: 768, | |
largeHandset: 480, | |
mediumHandset: 360, | |
smallHandset: 320, | |
}; |
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 mediaQuery from './mediaQuery'; | |
export const Container = styled.div` | |
display: flex; | |
justify-content: space-between; | |
align-items: center; | |
${mediaQuery('smallDesktop')` | |
display: flex; | |
flex-direction:column; | |
justify-content: center; | |
align-items: center; | |
`} | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment