npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bem-react-mixin

v1.2.4

Published

A Mixin Helper to write component classNames with a CSS BEM style for ReactJS Components

Downloads

10

Readme

README

In React JS, the recommended way to style components is to add styles at the Component level with Javascript instructions.

This module is not good for that, it only helps you to implement the CSS BEM Classification way with your React Components.

It uses the "classnames" Module (https://github.com/JedWatson/classnames) to do the job.

BEM Css ClassNames are of the form :

  the-block__the-element--the-modifier
  |       |  |         |  |          |
  +-------+  +---------+  +----------+
    BLOCK      ELEMENT      MODIFIER

in fact, we are more in a BCM case :

  the-block__the-component--the-modifier
  |       |  |           |  |          |
  +-------+  +-----------+  +----------+
    BLOCK   REACT-COMPONENT   MODIFIER

This mixins changes host component only by adding the "bem" property and some Context and by initializing it in componentWillMount.

This mixin should not be used before the componentWillMount call

Usage :

=> in Top Parent Component define the block part in the mixins component property:

     mixins: [bem.bemInit('the-app-name')]

=> in the Child Components, add the bem mixin :

     mixins: [bem]

    -> and use the added "this.bem" property in the "className" attribute

     Call method : this.bem[.add(...)|.raw(...)...].render()
     to render bem oriented css classNames.

     Note : the property is also available in the Top Parent Component.

Minimal sample :

     <div className={this.bem.render()} />

     if the component displayName is "CarouselItem" and the top parent component
     defines the mixin as : mixins: [bem.bemInit('the-app-name')], then, the class name
     produced should be :

     <div class="the-app-name__carousel-item" />


Minimal sample mixed with non bem class :

     className={this.bem.raw('panel').add().render()}

     this should produce the class names : "panel the-app-name__carousel-item"

Complete Sample with conditional classes :

     className={this.bem.add('img').
             add('img').mod('selected').if(this.state.isBeingDragged).
             add('img').mod('drag-over').if(this.props.dragOverIndex === this.props.contentIndex).
             render()}

  if conditions are true, the complete sample should produce with block prefix "the-app-name"
  and, with a component displayName "CarouselItem", it should produce class names :

    the-app-name__carousel-item-img
    the-app-name__carousel-item-img--selected
    the-app-name__carousel-item-img--drag-over

Tests :

  type the command line "jest" to play test suite.

How do I get set up?

just add this module into your project :

  npm install --save bem-react-mixin

in the source code import the module :

  var bem = require ('bem-react-mixin');
  

add the mixin in a top or macro component :

  mixins: [..., bem.bemInit('the-block-name')]
    

add the mixin in child or sub-child component :

  mixins: [..., bem]
      

use it in the top/child component :

  this.bem.add('icon')
     .add('icon').mod('connected').if(this.props.isConnected)
     .render();

here is a minimal parent component sample :

  var React             = require('react'),
      bem = require('bem-react-mixin');

  var MainPanel = React.createClass({
      mixins: [bem.bemInit('App')],
      propTypes: {
          name: React.PropTypes.string
      },
      getDefaultProps() {

          return {
              name: 'world'
          };
      },
      _renderClassName() {
          return this.bem
              .add()
              .render();
      },
      render() {

          return (
              <div className={this._renderClassName()}>
                  <h4>Hello {this.props.name} !</h4>
              </div>
          );
      }
  });

  module.exports = MainPanel;

this sample should render :

  <div class="app__main-panel" data-reactid=".0.0">
     <h4 data-reactid=".0.0.0">
        ...
     
     </h4>
  </div>