Simple utility function for conditionally joining class names together
This is inspired by JedWatson’s package classnames which I like but is a bit too bloated for my needs. I rarely need to support non-ES5 environments and I only need a subset of the API, so I created a more minimal version of it.
$ npm install --save classnames-minimal
How to use
Pass it an object literal with class names as keys and a predicaty1 value as value. Only the keys with a truthy value will be part of the generated string.
;const classes =;console; // => contains 'block block--highlighted' if this.props.highlighted == true and this.props.disabled == false
If you’re using CSS modules or something similar and you have your class names in an object you can use ES2015’s computed property names really nicely like this…
;;const classes =;console; // => contains the class names generated by CSS modules and filtered by our predicates
MIT © Jonathan Svenheden