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

bemboo

v2.0.0

Published

A bem generator based on objects for React 16 use.

Downloads

58

Readme

bemboo

b('block').e('element').m({ modifier: true })

Build Status Coverage Status

A bem generator based on objects for React 16 use.

React Usage

import block from 'bemboo'
import React from 'react'

const b = block('Component')
export default active => (
  <section className={b}>
    <article className={b.e('element').m({ active })}>hello</article>
  </section>
)

will generates if active is true:

<section class="Component">
  <article class="Component__element Component__element--active">
    hello
  </article>
</section>

Api

Default export is function block that return a new Block instance.

A blockMaker function is also exported, this function takes a settings mapping and return a block function using these settings.

The Block class (which is also exported) exposes the following functions / attributes:

constructor(block, element = null, modifier = {}, mixed = [], settings = {})

Initialize the Block object. Only block argument is meant to be used externally.

e(element)

Add element to a new instance of this Block and returns it. Can only be set once per Block instance. element argument is a string.

m(modifier)

Add modifier to a new instance of this Block and returns it. Can be used more than once, modifier are merged. modifier is a mapping of modifier -> values. If the value is false the modifier will be ignored, if the value is true it will generate a --modifier and if the value is truthy or 0 a --modifier-value. This modifier will be applied to all already mixed blocks.

mix(...blocks)

This fuction can mix other blocks with this Block instance and return a new instance with both blocks. blocks arguments can be Block instances or strings.

s

The generated string (which is also returned by toString())

Features

// Usage
> const b = block('block')
> b.toString()
'block'
> b.s
'block'

// For the following evaluations an implicit toString() is implied:

> b.e('element')
'block__element'

> b.e('element').m({ modifier: true })
'block__element block__element--modifier'

> b.e('element').m({ modifier: true }).m({ hidden: false, no: 8 })
'block__element block__element--modifier block__element--no-8'

> b.e('element').mix('main')
'block__element main'

> b.e('element').mix(block('main'))
'block__element main'

> b.e('element').m({ modifier: true }).mix('main')
'block__element block__element--modifier main'

> b.e('element').mix('main').m({ modifier: true })
'block__element block__element--modifier main main--modifier'

> b.mix('main', 'header').mix('principal')
'block main header principal'

> b.mix('main', 'header').m({ modifier: true})
'block block--modifier main main--modifier header header--modifier'

> b.mix('main', 'header').m({ modifier: true}).sub('header', 'main--modifier')
'block block--modifier main header--modifier'

// blockMaker allow you to change the default settings:
const block12 = blockMaker({
  namespace: 'bemboo->',
  elementDelimiter: '@',
  modifierDelimiter: '#',
  modifierValueDelimiter: '/',
})

> block2('block2').e('element2').m({ modifier2: true, mod: 'ifier2' })
'bemboo->block2@element2 bemboo->block2@element2#modifier2 bemboo->block2@element2#mod/ifier2'

Decorator

Functions

import block from 'bemboo'
import React from 'react'

export default block(function Component(b, { active }) {
  return (
    <section className={b}>
      <article className={b.e('element').m({ active })}>hello</article>
    </section>
  )
})

Classes

import block from 'bemboo'
import React from 'react'

@block
export default class Component extends React.Component {
  render(b) {
    return (
      <section className={b}>
        <article className={b.e('element').m({ active })}>hello</article>
      </section>
    )
  }
})

Mangling

These decorators use the Component.displayName or the Component name if it isn't set. If you are using a minifier that mangles the function/class names your bem class won't work (and probably be replaced with something like 't__element'). Either disable mangling or use a babel plugin like babel-plugin-add-react-static-displayname