Skip to content

Instantly share code, notes, and snippets.

@melbourne2991
Last active May 22, 2019 08:41
Show Gist options
  • Save melbourne2991/9d4688d5f8e7b2c424ecf2e4b4ad6a1d to your computer and use it in GitHub Desktop.
Save melbourne2991/9d4688d5f8e7b2c424ecf2e4b4ad6a1d to your computer and use it in GitHub Desktop.
Responsive utilities styled components
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