styled-when
Easily declare prop-based conditions when using styled components.
Compatible with styled-components and emotion.
Install
npm i styled-when
Usage
Select when prop's value is truthy. Use for simple checks.
const Button = styledbutton` font-weight: normal; { font-weight: bold; }`
Select when callback returns a truthy value. Use for more complex or multiple conditions.
import when from 'styled-when' const Button = styledbutton` color: white; background: cornflowerblue; border: 1px solid cornflowerblue; { color: cornflowerblue; background: white; }`
Select when value is true
or false
. Use for constant conditions.
import when from 'styled-when' const Button = styledbutton` font-weight: regular; { font-weight: bold; text-transform: uppercase; }`
API
whenprop: string stringwhencallback: Function stringwhencondition: boolean string