Skip to content

Instantly share code, notes, and snippets.

@mortezashojaei
Last active June 19, 2023 07:45
Show Gist options
  • Save mortezashojaei/72b23a1ae50af655255682e726c26c11 to your computer and use it in GitHub Desktop.
Save mortezashojaei/72b23a1ae50af655255682e726c26c11 to your computer and use it in GitHub Desktop.
use media query in styled components ( DRY )
const mediaQuery = (key: keyof typeof screens) => {
return (style: TemplateStringsArray | String) => `@media (max-width: ${screens[key]}px) { ${style} }`;
};
export default {
wideDesktop: 1920,
desktop: 1280,
smallDesktop: 1024,
largeTablet: 768,
largeHandset: 480,
mediumHandset: 360,
smallHandset: 320,
};
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