bem-helper
Helper to create BEM-style classnames
Install
npm install @dr/bem-helper
Usage
var bem = require("@dr/bem-helper");
var className = bem("dr-module", "list");
var className = bem("dr-module", { loaded: true });
var className = bem("dr-module", "list", { expanded: true });
var className = bem.single("dr-module", "list", { expanded: true });
var className = bem("dr-module", "list", { expanded: true, rated: 3 });
var className = bem.single("dr-module", "list", { rated: 3 });
var block = "dr-module";
var boundBem = bem.bind(null, block);
var className = boundBem("list", { expanded: true });
var boundSingle = bem.single.bind(null, block);
var className = boundSingle("list", { expanded: true });
API
bem
A function that creates all applicable combinations of classnames for an element in BEM-style.
Arguments
block
(string) - The block element for the classname....args
(string|object) - Optional. Elements are described by strings and modifiers are described by objects: keys are use as the modifier names and boolean values trigger whether the modifier is active, and any other type is used as a value; {expanded: true}
> "--expanded"
, {rating: 3}
> "--rating-3"
.
bem.single
Same as bem
above - but it only returns a single classname.