Socket
Book a DemoInstallSign in
Socket

bem-class

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bem-class

Generate BEM class names based by chaining

0.6.1
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

bem-class Build Status

Install

$ npm install --save-dev bem-class

Usage

Create a new block by calling bem.block('some-block-name') and storing the return value. You can apply modifiers to the block by chaining .modifier({ 'someModifier': true }) onto the end of the bem.block('') call.

var bem = require('bem-class');

var age = 17;
var personBlock = bem.block('person')
  .modifier({
    'child': (age < 18)
  });

console.log(personBlock.toString()); // "person person--child"

You can create elements by calling .element('some-element-name') on the result of bem.block('') and storing the return value, or by chaining directly onto the end of the block/modifier call. Elements can also be modified in the same way blocks can, by chaining .modifier({ 'someModifier': false }); onto the end of the element call.

var isWaving = false;
var handElement = personBlock.element('hand')
  .modifier({
    'waving': isWaving
  });

console.log(handElement.toString()); // "person__hand"

var isHungry = true;
var tummyElement = personBlock.element('tummy')
  .modifier({
    'rumbling': isHungry
  });

console.log(tummyElement.toString()); // "person__tummy person__tummy--rumbling"

Shown below is an example render method from a React component:

var bem = require('bem-class');

class SomeComponent extends React.Component {
  render () {
    var container = bem.block('some-block-name');
    var paragraph = container.element('some-element')
      .modifier({
        'some-enabled-modifier': true,
        'some-disabled-modifier': false
      });

    return (
      <div className={container}>
        <p className={paragraph}></p>
      </div>
    );
  }
}

Both BEM_Block and BEM_Element have a toString method which returns the complete, space-separated list of class names pertaining to the current instance.

Keywords

BEM

FAQs

Package last updated on 25 Jun 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.