Conditionally join CSS class names together - Especially useful with React
Install
$ npm install @sindresorhus/class-names
Usage
const classNames = ; ;//=> 'unicorn rainbow' ;//=> 'awesome unicorn' ;//=> 'unicorn' const buttonType = 'main';;//=> 'button-main'
const classNames = ; const Button = { console; /* { type: 'success', small: true } */ const buttonClass = ; console; //=> 'button button-success button-small' return <button =>…</button>;};
API
classNames(…input)
Conditionally join CSS class names together.
input
Type: string | object
Accepts a combination of strings and objects. When an object, only object keys with truthy values are included. Anything else is ignored.
FAQ
classnames
?
How is it different from - Dedupes by default.
- Doesn't coerce numbers to strings.
- Doesn't support array input. Just use the spread operator.
Related
- react-extras - Useful components and utilities for working with React
License
MIT © Sindre Sorhus