1Installation:
2yarn add classnames or npm i classnames
3
4Usage:
5classNames('foo', 'bar'); // => 'foo bar'
6classNames('foo', { bar: true }); // => 'foo bar'
7classNames({ 'foo-bar': true }); // => 'foo-bar'
8classNames({ 'foo-bar': false }); // => ''
9classNames({ foo: true }, { bar: true }); // => 'foo bar'
10classNames({ foo: true, bar: true }); // => 'foo bar'
11
12// lots of arguments of various types
13classNames('foo', { bar: true, duck: false }, 'baz', { quux: true }); // => 'foo bar baz quux'
14
15// other falsy values are just ignored
16classNames(null, false, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1'
17
18TypeInstallation:
19yarn add @types/classnames
1let el = document.getElementById('item');
2
3if (el.className === 'active'){
4 el.className = 'inactive';
5} else {
6 el.className = 'active';
7}