Skip to content

Instantly share code, notes, and snippets.

@leonidkuznetsov18
Last active January 18, 2020 10:46
Show Gist options
  • Select an option

  • Save leonidkuznetsov18/2a052c1a4801a64714f0e59173fcd87c to your computer and use it in GitHub Desktop.

Select an option

Save leonidkuznetsov18/2a052c1a4801a64714f0e59173fcd87c to your computer and use it in GitHub Desktop.
styled components cleaner way for multiple props
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