Created
July 22, 2021 13:11
-
-
Save joaotanaca/c9b5944faae9142e338c51b62d86480c to your computer and use it in GitHub Desktop.
Mixin for styled-components with types
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 "styled-components"; | |
const breakpoints = { | |
xs: "480px", | |
sm: "768px", | |
md: "992px", | |
lg: "1200px" | |
}; | |
type cssParams = Parameters<typeof css>; | |
const keys = Object.keys(breakpoints) as Array<keyof typeof breakpoints>; | |
export const respondTo = keys.reduce((accumulator, label) => { | |
accumulator[label] = (...args: cssParams) => { | |
return css` | |
@media (min-width: ${breakpoints[label]}) { | |
${css(...args)}; | |
} | |
`; | |
}; | |
return accumulator; | |
}, {} as Record<keyof typeof breakpoints, Function>); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment