Skip to content

Instantly share code, notes, and snippets.

@roginfarrer
Created January 16, 2021 20:40
Show Gist options
  • Save roginfarrer/95208f60f593f93825cd31d78a3cf0ce to your computer and use it in GitHub Desktop.
Save roginfarrer/95208f60f593f93825cd31d78a3cf0ce to your computer and use it in GitHub Desktop.
CSS Vars with System Props
// Box takes in props that then assigns each responsive prop to the appropriate breakpoint
// Negates needing to update breakpoints based on theme within the styled-component
const Box = styled.div`
// base styles
@media screen and (min-width: ${props => props.breakpoints.breakpointOne}) {
// other styles
}
@media screen and (min-width: ${props => props.breakpoints.breakpointTwo}) {
// other styles
}
`
const WrappedBox = props => (
<Box breakpoints={{breakpointOne: '25em', breakpointTwo: '32em'}} {...props} />
)
// <Box color="$blue200" borderRadius="$pill" />
// $blue200 maps to var(--color-blue200)
const theme = {
colors: {
blue200: 'blue'
},
radii: {
small: 'small',
large: 'large',
pill: 'pill'
}
}
const cssVars = makeVars(theme);
// cssVars:
// `
// --color-blue200: blue;
// --radii-small: small;
// --radii-large: large;
// --radii-pill: pill;
// `
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment