Created
July 25, 2021 13:25
-
-
Save kosciolek/a0e357c6efe71d4260f468d5468f457e to your computer and use it in GitHub Desktop.
responsive grid
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 "@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