Last active
January 18, 2020 10:46
-
-
Save leonidkuznetsov18/2a052c1a4801a64714f0e59173fcd87c to your computer and use it in GitHub Desktop.
styled components cleaner way for multiple 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
| import styled, { css } from 'styled-components' | |
| const Button = styled.button(props => css` | |
| height: ${props.height}; | |
| width: ${props.width}; | |
| color: ${props.theme.fontColor}; | |
| background-color: ${props.theme.backgroundColor}; | |
| `) | |
| // OR | |
| const sizeProps = props => css` | |
| ${props.width && `width: ${props.width}`}; | |
| ${props.height && `height: ${props.height}`}; | |
| ${props.maxWidth && `max-width: ${props.maxWidth}`}; | |
| ${props.maxHeight && `max-height: ${props.maxHeight}`}; | |
| `; | |
| const Button = styled.button` | |
| ${sizeProps} | |
| ` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment