Created
May 27, 2020 06:33
-
-
Save kettanaito/496b0b26a0cf75adc6b325b1457664b8 to your computer and use it in GitHub Desktop.
CSS Variables in 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 { createGlobalStyle, css } from 'styled-components' | |
const GlobalStyle = createGlobalStyle` | |
html { | |
/* Maps all colors from the `theme` to CSS variables: */ | |
${({ theme }) => Object.entries(theme.colors).map(([name, value]) => css` | |
--${camelCaseToKebabCase(name)}: ${value}; | |
`)} | |
} | |
` | |
const App = () => ( | |
<> | |
<GlobalStyle> | |
<RestOfTheApp /> | |
</> | |
) |
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 styled from 'styled-components' | |
export const Component = styled.div` | |
/* References a CSS variable: */ | |
color: var(--color-gray-light); | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment