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

@redneckz/react-bem-helper

v2.0.4

Published

BEM library for React

Downloads

24

Readme

react-bem-helper

BEM library for React

NPM Version Build Status Coverage Status Bundle size

Table of Contents

Installation

$ npm install --save @redneckz/react-bem-helper
$ yarn add @redneckz/react-bem-helper

Motivation

This utility helps to declare BEM entities in terms of React components. Primarily it useful for projects with CSS artifacts (Sass, Less, PostCSS, ...).

Also compared to other libraries this one is aimed at simplicity and incremental adaptation of BEM (even for proprietary projects).

Features

  1. Configurable
  2. BEM mixins support
  3. Modular CSS support
  4. Flow definitions
  5. Very small bundle ~8Kb
  6. Almost no dependencies

Prerequisites

  1. BEM Methodology
  2. Higher-Order Components
  3. Flow
  4. classnames

Usage

.some-button
    padding: 8px

    &--major
        background: blue

    &--size
        &--small
            padding: 4px
        &--large
            padding: 16px
import React from 'react';
import { BEM } from '@redneckz/react-bem-helper';
import styles from './some-button.sass';

const someButton = BEM(styles);

export const SomeButton = someButton(({ className, disabled, children }) => (
    <button className={className} disabled={disabled}>
        {children}
    </button>
));
<React.Fragment>
    <SomeButton major>Major</SomeButton>
    <SomeButton size="small">Small</SomeButton>
    <SomeButton major size="large">
        Large
    </SomeButton>
    <SomeButton disabled>Disabled</SomeButton>
</React.Fragment>

will produce

<button class="some-button some-button--major">Major</button>
<button class="some-button some-button--size--small">Small</button>
<button class="some-button some-button--major some-button--size--large">Large</button>
<button class="some-button" disabled>Disabled</button>

Any valid component can be used to declare block or its elements

export const SomeButton = someButton(
    class extends React.PureComponent {
        render() {
            const { className, disabled, children } = this.props;
            return (
                <button className={className} disabled={disabled}>
                    {children}
                </button>
            );
        }
    },
);
export const SomeButton = someButton('button'); // DOM component

Also library provides several factory functions to declare DOM components with restricted attributes list (div, span, form, button, input, label, textarea)

import React from 'react';
import { BEM, div } from '@redneckz/react-bem-helper';
import styles from './some-button.sass';

const someButton = BEM(styles);

export const SomeButton = someButton(div({ role: 'button' }));

Block with elements

.panel
    display: flex

    &__item
        flex-grow: 0

        &--align
            &--start
                align-self: flex-start
            &--center
                align-self: center
            &--end
                align-self: flex-end

    &__spread
        flex-grow: 1
import React from 'react';
import { BEM, div } from '@redneckz/react-bem-helper';
import styles from './panel.sass';

const panel = BEM(styles);

export const Panel = panel('div');
export const PanelItem = panel.item(div());
export const PanelSpread = panel.spread('div');

Configuration

BEM naming convention

import React from 'react';
import { Config } from '@redneckz/react-bem-helper';

Config.ELEMENT_SEPARATOR = '__';
Config.MODIFIER_SEPARATOR = '--';

Flow

Generate stub for classnames

$ flow-typed create-stub [email protected]

Do not forget to configure includes and ignores to put library into scope.

License

MIT