bem
is a small helper function for managing BEM classes.
npm install --save @maxwellmri/bem
bem
can be used 3 ways.
- With an array
const b = bem("Block");
b(["&__component"]) // returns Block__component
ub(["&__component", "&--modified"]) // returns Block__component Block--modifier
- With an string
const b = bem("Block");
b("&__component") // returns Block__component
- With an object (for conditional classes)
const b = bem("Block");
b({ "&__component": true, "&--disabled": false }) // returns Block__component
b({ "&__component": true, "&--disabled": true }) // returns Block__component Block--disabled
- With multiple arguments
const b = bem("Block");
b(["&", "&--disabled"], "random") // returns Block Block--disabled random
b(["&", "&--disabled"], { "fizz": true, "buzz": false }) // returns Block Block--disabled fizz