Skip to content

Instantly share code, notes, and snippets.

@kosciolek
Created July 25, 2021 13:25
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 kosciolek/a0e357c6efe71d4260f468d5468f457e to your computer and use it in GitHub Desktop.
Save kosciolek/a0e357c6efe71d4260f468d5468f457e to your computer and use it in GitHub Desktop.
responsive grid
import { css } from "@emotion/react";
import styled from "@emotion/styled";
export const breakpoints = {
xs: 0,
sm: 460,
md: 820,
lg: 1350,
xl: 1880,
};
export const Grid = styled.div<{
container?: boolean;
item?: boolean;
xs?: number;
sm?: number;
md?: number;
lg?: number;
xl?: number;
}>`
${(p) =>
p.container &&
css`
display: grid;
grid-template-columns: repeat(12, 1fr);
`}
${(p) =>
p.item &&
["xs", "sm", "md", "lg", "xl"]
.filter((size) => p[size as keyof typeof p] !== undefined)
.map(
(size) =>
css`
@media (min-width: ${breakpoints[
size as keyof typeof breakpoints
]}px) {
display: ${p[size as keyof typeof p] === 0 ? "none" : "block"};
grid-column: span ${p[size as keyof typeof p]};
}
`
)}
`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment