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 🙏

© 2024 – Pkg Stats / Ryan Hefner

bem-cx

v0.3.2

Published

bem-cx is designed for generating css classNames for use primarily in react components. It doesn't depend on react, so you could use it elsewhere.

Downloads

8

Readme

bem-cx is designed for generating css classNames for use primarily in react components. It doesn't depend on react, so you could use it elsewhere.

Install

npm install bem-cx

Docs

The docs can be found in the docs directory, though they might not make sense without the examples below.

Example

There are two flavors of bem-cx. The first is very simple but requires more typing. The example is in JSX.

import makeBem from 'bem-cx'; // or require('bem-cx').default
const bem = makeBem('Foo');

class Foo {
  render(){
      return (
        <div className={bem}>
          Foo
          <div className={bem.el('Header')}>
            Foo__Header
            <div className={bem.el('Header').el('Title')}>
              Foo__Header__Title
            </div>
          </div>
          <div className={bem.el('Content')}>
            <div className={bem.el('Content').el('Example').mod(true && 'active')}>
              Foo__Content__Example Foo__Content__Example--active
            </div>
            <div className={bem
              .el('Content')
              .el('Example')
              .mod({
                a: true,
                b: false,
                c: false
              })}
              >
              Foo__Content__Example
              Foo__Content__Example--a
              Foo__Content__Example--c
            </div>
          </div>
        </div>
      );
  }
}

This is the same as above but uses CxStack. CxStack has the same api as the above but also provides .elAt takes a level as its first argument.

Level 0 is the root, so direct children of the root node will have the level 1.

This saves you from needing to type everything on the hierarchy for each element. Aside from .mod this is the main value proposition of this library.

import {CxStack} from 'bem-cx'; // or require('bem-cx').CxStack

class Foo {
  render(){
      const bem = new CxStack('Foo');
      return (
        <div className={bem}>
          Foo
          <div className={bem.elAt(1, 'Header')}>
            Foo__Header
            <div className={bem.elAt(2, 'Title')}>
              Foo__Header__Title
            </div>
          </div>
          <div className={bem.elAt(1, 'Content')}>
            <div className={bem.elAt(2, 'Example').mod(true && 'active')}>
              Foo__Content__Example Foo__Content__Example--active
            </div>
            <div className={bem
              .elAt(2, 'Example')
              .mod({
                a: true,
                b: false,
                c: false
              })}
              >
              Foo__Content__Example
              Foo__Content__Example--a
              Foo__Content__Example--c
            </div>
          </div>
        </div>
      );
  }
}