compiled icon indicating copy to clipboard operation
compiled copied to clipboard

Conditional CSS rules for ClassNames

Open itsdouges opened this issue 5 years ago • 0 comments

We've implemented conditional logical expressions in #379. We now need to add support to ClassNames api.

<ClassNames>
  {({ css }) => <div className={css({ color: 'red', ...isPrimary && { color: 'blue' } }} />}
</ClassNames>

In this change it might also make sense to update the AST output, currently it will output a string, e.g. color-blue font-size-20 - but with conditional CSS it would have to output an array.

If we wrap the output in ax we get around that. E.g. the example above becomes:

<ClassNames>
  {({ css }) => <div className={ax(['color-red', isPrimary && 'color-blue'])} />}
</ClassNames>

itsdouges avatar Dec 07 '20 10:12 itsdouges