Created
January 16, 2021 20:40
-
-
Save roginfarrer/95208f60f593f93825cd31d78a3cf0ce to your computer and use it in GitHub Desktop.
CSS Vars with System Props
This file contains hidden or 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
// 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