@zcorky/classnames
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

classnames

NPM version Coverage Status Dependencies Build Status license issues

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>;
};

Relatived

/@zcorky/classnames/

    Package Sidebar

    Install

    npm i @zcorky/classnames

    Weekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    5.1 kB

    Total Files

    5

    Last publish

    Collaborators

    • uniquecolesmith