Last active
May 22, 2019 08:41
-
-
Save melbourne2991/9d4688d5f8e7b2c424ecf2e4b4ad6a1d to your computer and use it in GitHub Desktop.
Responsive utilities styled components
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 { CSSObject } from "styled-components" | |
export type BreakPointStyles<B> = { [K in keyof B]: CSSObject } | |
const breakpoints = { | |
sm: "768px", | |
md: "992px", | |
} | |
const responsive = (styles: BreakPointStyles<typeof breakpoints>) => { | |
const output: CSSObject = {} | |
Object.keys(styles).forEach(breakpoint => { | |
output[ | |
`@media (min-width: ${(breakpoints as any)[breakpoint]})` | |
] = (styles as any)[breakpoint] | |
}) | |
return output | |
} | |
const mixins = { | |
responsive, | |
} | |
const colors = { | |
primary: "yellow", | |
} | |
export const theme = { | |
colors, | |
mixins, | |
} | |
// Usage: | |
// const StyledPreviewDateContainer = styled.div(({ theme }) => ({ | |
// color: '#000', | |
// display: "flex", | |
// ...theme.mixins.responsive({ | |
// sm: { | |
// margin: "0 0 0 1rem" | |
// } | |
// }) | |
// })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment