Skip to content

Instantly share code, notes, and snippets.

@willmendesneto
Created March 20, 2021 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willmendesneto/fc4b5537f3712e3bd3d2e32f4731dacb to your computer and use it in GitHub Desktop.
Save willmendesneto/fc4b5537f3712e3bd3d2e32f4731dacb to your computer and use it in GitHub Desktop.
Helper for CSS-In-JS Media Query integration on Components
/**
* Helper for CSS-In-JS Media Query integration on Components
*
* Usage:
* // It's using `styled-components` package, but it can be used in any CSS-IN-JS package solution
*
* import styled from 'styled-components';
*.
*. const MyDiv = styled.div`
display: inline-block;
position: absolute;
right: 0;
${screen.md} {
display: block;
}
`;
*/
// Screen sizes used in your app
const sizes = {
sm: '320px',
md: '768px',
lg: '1024px',
xl: '1280px',
};
// Breakpoints based on your configuration
export const breakpoints = {
sm: `@media (min-width: ${sizes.sm})`,
md: `@media (min-width: ${sizes.md})`,
lg: `@media (min-width: ${sizes.lg})`,
xl: `@media (min-width: ${sizes.xl})`,
max: `${sizes.xlg}`,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment