@zcorky/classnames
v1.0.0
Published
Conditionally joining classNames together.
Downloads
3
Readme
classnames
Conditionally joining classNames together.
Install
$ npm install @zcorky/classnames
Usage
classNames('unicorn', 'rainbow');
//=> 'unicorn rainbow'
classNames({awesome: true, foo: false}, 'unicorn', {rainbow: false});
//=> 'awesome unicorn'
classNames('unicorn', null, undefined, 0, 1, {foo: null});
//=> 'unicorn'
const buttonType = 'main';
classNames({[`button-${buttonType}`]: true});
//=> 'button-main'
const Button = props => {
console.log(props);
/*
{
type: 'success',
small: true
}
*/
const buttonClass = classNames(
'button',
{
[`button-${props.type}`]: props.type,
'button-block': props.block,
'button-small': props.small
}
);
console.log(buttonClass);
//=> 'button button-success button-small'
return <button className={buttonClass}>…</button>;
};