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-constructor

v1.1.11

Published

Constructor for BEM in terms of Reactjs

Readme

This repository is created in order to provide constructor for BEM in terms of React.

Usage example:

Within the instructions below we use the following file structure:

.
├── src                             # Source files (alternatively `lib` or `app`)
│   ├── application
│   │   ├── consumers
│   │   │   └── homepage.jsx
│   │   └── templates               # This directory contains all BEM blocks
│   │       ├── section
│   │       │   ├── section.jsx     # This main file in the section BEM block
│   │       │   └── styles.css      # Other file that is used with section BEM block
│   │       └── button              
│   │           ├── button.jsx      # This main file in the anchor BEM block
│   │           └── button.css      # Other file that is used with anchor BEM block
│   └── core
└── package.json

Note: it is not obligatory in terms of this lib to use specifically folder structure above, you can use any namings in accordance with BEM naming methodology, BUT it is obligatory to name the main file in the BEM block folder as the BEM block (section -> section.jsx)

  1. In your package.json, please add the following script into scripts section:

       {
           "scripts": {
               "extract": "node ./node_modules/bem-react-constructor/src/extractScript.js"
           }
       }
  2. Run into your terminal within project root directory npm run extract ./src/application/templates (according to the folder structure above)

    Note: everytime you add a new block, or change existing name of the block, you need to re-run npm run extract ./src/application/templates script

  3. Please, check files dynamicRequire.js and elementsDeclaration.json are available in src/application/templates (whatever you used as a third parameter in the previous step). If not, please go to the step 2 and double-check your third parameter.

  4. Now you are able to use the code by the following way:

    // homepage.jsx (according to the file structure above)
       
    import React from "react";
    import TemplateBuilder from "bem-react-constructor/src/templateBuilder.js";
       
       
    export const Homepage = () => {
       const data = [
           {
               type: "section",
               header: "BEM methodology",  // custom parameter
               children: [
                   {
                       type: "button",
                       title: "Cick 1",
                       clickHandler: () => console.log('clicked button 1')
                   },
                   {
                       type: "button",
                       title: "Cick 2",
                       clickHandler: () => console.log('clicked button 2')
                   }
               ],
               isFullPage: true,           // custom parameter
               background: '#cecece'       // custom parameter
           },
           {
               type: "section",
               header: "Something else",   // custom parameter
               isFullPage: false,          // custom parameter
               background: '#ababab'       // custom parameter
           }
       ];
       
       return (<>{TemplateBuilder.getInstance({
              elementsDeclarationFile: require('../templates/elementsDeclaration.json'),
              dynamicRequireFile: require('../templates/dynamicRequire.js')
          }).build(data)}</>);
    }

    In section.jsx:

    // section.jsx (according to the file structure above)
      
    import React, {useEffect, useState} from "react";
    import "./section.css";
       
       
    export const Section = ({isFullPage, header, background, content, children}) => {
        const [height, setHeight] = useState('200px');
       
        useEffect(() => {
            if (isFullPage)
                setHeight(window.innerHeight || document.documentElement.clientHeight ||
                    document.body.clientHeight + 'px');
        }, [isFullPage]);
       
        return (<div className="section" style={{background, height}}>
            <div className="section__content">
                <p className="section__header">{header}</p>
                {content ?? <></>}
                {children.map((c, k) => <div key={k}>{c}</div>)}
            </div>
        </div>);
    }
       
    export default Section;

    Note: please, put attention, that you need to export default for the current module, in the future it will be fixed in future versions

    In button.jsx:

    // button.jsx (according to the file structure above)
      
    import React from "react";   
    import "./button.css";
       
       
    export const Button = ({title, clickHandler}) => {
        return (<button className="hero__button-test button" 
                  onClick={clickHandler}>{title}</button>);
    }
       
    export default Button;

Available parameters for data configuration:

| Parameter name | Description | Is obligatory | | :--- | :---------- | ---------: | | type | is responsible for BEM block type |true| | children | nested elements, which you should nest by yourself | false |

Disclaimer:

This library does not have any relation with Yandex/bem-react. I use it for myself, but I can see that people search for it and download it. I lead the development on it solo if you would like to take participate, please contact me via the email "[email protected]". I will try to do my best in terms of documenting this library. Please check updates on a weekly base