
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Friendly BEM class names generator. Great for React.
Bem-cn (aka BEM Class Name) is extra small (minified+gzipped less than 1.6Kb) and extremely simple client-side library and Node.js module.
Important! Only bem-cn@3.x+
compatible with react@16+
.
Please do not use version 2.x or lower.
More details about the problem.
Inspired by b_.
I spent a lot of time finding BEM class name generator, that meets my needs:
When my efforts had led to naught I've created this micro library.
With Node.js:
npm i --save bem-cn
yarn add bem-cn
Works with webpack and browserify:
// CommonJS
var { block } = require('bem-cn');
// ES6
import { block } from 'bem-cn';
const b = block('button');
// Block
b(); // 'button'
// Element
b('icon'); // 'button__icon'
// Modifier
b({ type: 'text' }); // 'button button_type_text'
b({ onlykey: true }); // 'button button_onlykey'
b({ without: false }); // 'button'
b('icon', { name: 'check' }); // 'button__icon button__icon_name_check'
// Mix another classes
b('icon').mix('another'); // 'button__icon another'
b('icon').mix(['one', 'two']); // 'button__icon one two'
// States like in SMACSS: https://smacss.com/book/type-state
b.state({ hidden: true }); // 'button is-hidden'
b.state({ hidden: false }); // 'button'
b.state({ hidden: true, error: true }); // 'button is-hidden is-error'
// More states!
b.is({ loading: true }); // 'button is-loading'
b.has({ content: true }); // 'button has-content'
// Setup custom delimiters
import { setup } from 'bem-cn';
const block = setup({
el: '~~',
mod: '--',
modValue: '-'
});
const b = block('block');
b('element'); // 'block~~element'
b({ mod: 'value' }); // 'block block--mod-value'
// Setup namespace
const block = setup({ ns: 'ns-' });
const b = block('block');
b(); // 'ns-block'
b('element'); // 'ns-block__element'
b({ mod: 'value' }); // 'ns-block ns-block_mod_value'
import block from 'bem-cn';
import React from 'react';
import ReactDOM from 'react-dom';
const b = block('popup');
const Popup = React.createClass({
render() {
const { skin, children } = this.props;
return (
<div className={b()}>
<span className={b('icon')} />
<div className={b('content', { skin })}>
{children}
</div>
</div>
);
}
});
ReactDOM.render(<Popup skin="bright">Hello!</Popup>, target);
/*
<div class="popup">
<span class="popup__icon"></span>
<div class="popup__content popup__content_skin_bright">
Hello!
</div>
</div>
*/
@todo
bem-cn@2.x
or lower has specific chainable API. As a result, each call returns function for a further call. But most components are expecting property className
as a string and using propTypes
object for check this. In this case, you will see a warning. There are the couple of ways to avoid these warnings below.
Use final call without arguments to get a string
<CustomComponent className={b('icon')()} />
Use explicit call of method toString()
:
<CustomComponent className={b('icon').toString()} />
Use less specific propTypes rules:
let CustomComponent = React.createClass({
propTypes: {
className: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.func
])
},
// ...
});
bem-cn
is fully compatible with ES5 browsers. If you are going to support ES3 browsers than just use es5 shim.
FAQs
Friendly BEM class names generator, greate for React
The npm package bem-cn receives a total of 5,240 weekly downloads. As such, bem-cn popularity was classified as popular.
We found that bem-cn demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.