GithubHelp home page GithubHelp logo

okonet / bem-cn Goto Github PK

View Code? Open in Web Editor NEW

This project forked from albburtsev/bem-cn

0.0 2.0 0.0 31 KB

Friendly BEM-style class name generator, great for React.

License: MIT License

CoffeeScript 7.23% JavaScript 92.77%

bem-cn's Introduction

bem-cn

Friendly BEM class names generator. Great for React.

Bem-cn (aka BEM Class Name) is extra small (minified+gzipped less than 1Kb) and extremely simple client-side library and Node.js module.

Inspired by b_.

Why?

Why I created yet another node module?

I spent a lot of time finding BEM class name generator, that meets my needs:

  • Simple usage with React
  • Support modifiers without value
  • Mix multiple blocks
  • Friendly chainable API

But now (March 2015) I can't find it. That's why.

Install

With Node.js:

npm i --save bem-cn

Or use Bower for install:

bower install --save bem-cn

Works with webpack and browserify:

var Block = require('bem-cn');

Usage

Let's try:

var b = Block('button');

// Block
b; // 'button'
b(); // 'button'

// Element
b('icon'); // 'button__icon'

// Modifier
b({ type: 'text' });  // 'button button_type_text'
b({ type: 'text' }, { type: 'colored' }); // 'button button_type_text button_type_colored'
b({ onlykey: true });  // 'button button_onlykey'
b({ without: false });  // 'button'

// Mix
b('icon', { name: 'close' }).mix('another'); // 'button__icon button__icon_name_close another'

// States
// As SMACSS states: https://smacss.com/book/type-state
b.state({ hidden: true }); // 'button is-hidden'
b.state({ hidden: false }); // 'button'
b.state({ hidden: true, error: true }); // 'button is-hidden is-error'

// Custom separators
Block.setup({
    el: '~~',
    mod: '-'
});

var b = Block('block');

b('element'); // 'block~~element'
b({ mod: 'value' }); // 'block block-mod-value'

Usage with JSX:

var Block = require('bem-cn'),
    b = Block('popup');

var Popup = React.createClass({
    render: function() {
        return (
            <div className={b.mix(this.props.mix)}>
            	<span className={b('icon')} />
            	<div class={b('content', { skin: this.props.skin })}>
            		{this.props.children}
            	</div>
            </div>
        );
    }
});

React.render(<Popup mix="another" skin="bright" />, target);
/*
<div class="popup another">
	<span class="popup__icon"></span>
	<div class="popup__content popup__content_skin_bright">
	</div>
</div>
 */

bem-cn's People

Contributors

albburtsev avatar okonet avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.