compiled
compiled copied to clipboard
Conditional CSS rules for ClassNames
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>