Last active
April 20, 2017 07:03
-
-
Save fgnass/b678ef44e484896e16db9941a1ff2885 to your computer and use it in GitHub Desktop.
Pattern for styled components with lots of states
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, { css } from 'styled-components'; | |
const Button = styled.button` | |
font-size: 1em; | |
margin: 1em; | |
border: 2px solid palevioletred; | |
border-radius: 3px; | |
/* This gets hard to read if there is more than one state: */ | |
background: ${props => props.primary && 'palevioletred'}; | |
color: ${props => props.primary ? 'white' : 'palevioletred'}; | |
`; | |
const Button = styled.button` | |
font-size: 1em; | |
margin: 1em; | |
border: 2px solid palevioletred; | |
border-radius: 3px; | |
color: palevioletred; | |
/* Use nested css blocks instead: */ | |
${props => props.primary && css` | |
background: palevioletred; | |
color: white; | |
`} | |
`; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment