项目
在 GitHub 查看 How is it different from
sindresorhus/class-names
关于
Conditionally join CSS class names together - Especially useful with React
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文class-names
Conditionally join CSS class names together - Especially useful with React
Install
$ npm install @sindresorhus/class-names
Usage
import classNames from '@sindresorhus/class-names';
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'
import classNames from '@sindresorhus/class-names';
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>;
};
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
How is it different from classnames?
- Dedupes by default.
- Does not coerce numbers to strings.
- Does not support array input. Just use the spread operator.
Related
- react-extras - Useful components and utilities for working with React
探索相关项目
加载中…