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

ember-cli-bem

v0.1.0

Published

BEM naming for your Ember project

Downloads

5,177

Readme

ember-cli-bem Build Status

Make your project BEM-flavoured. It incapsulates all BEM naming logic, so you don't have to care about it in your components. Simply define blocks, elements and modifiers in your components and templates.

Introduction

Why use another class names addon in your Ember project, if you're already using something like ember-component-css? Because BEM-way classes look ugly in these addons.

For example, compare how to create an element with ember-component-css and with ember-cli-bem:

  {{!-- With ember-component-css --}}
  <div class="{{componentCssClassName}}__container"></div>

  {{!-- With ember-cli-bem --}}
  <div class="{{elem 'container'}}"></div>

Moreover, how to define an element with modifiers? If you want to get following class names header__item header__item_disabled header__item_type_highlighted, plus if disabled modifier applies only if some condition matches, you have to write something like this:

  {{!-- With ember-component-css --}}
  <div class="
    {{componentCssClassName}}__container
    {{if someCondition (concat componentCssClassName '__container_disabled')}}
    {{componentCssClassName}}__type_highlighted
  "></div>

  {{!-- With ember-cli-bem --}}
  <div class="{{elem 'container' disabled=someCondition highlighted=true}}"></div>

Or let's say you just want to define some modifier in your component:

// With ember-component-css
import Ember from 'ember';
export default Ember.Component.extend({
  classNameBindings: ['typeMod'],
  type: 'highlighted',
  typeMod: Ember.computed('componentCssClassName', 'type', function() {
    const type = this.get('type');
    if (type) {
      return `${this.get('componentCssClassName')}_type_${type}`
    } else {
      return '';
    }
  }),
});

// With ember-cli-bem
import Ember from 'ember';
import BEM from 'ember-cli-bem/mixins/bem';

export default Ember.Component.extend({
  blockName: 'button',
  mods: ['type'],
  type: 'highlighted',
});

Once again, ember-cli-bem incapsulates all BEM naming logic, so you don't have to care about it in your components.

Defining Blocks and Elements

To define a block with ember-cli-bem, you should mix BEM mixin into your component. Blocks in ember-cli-bem requires only one field — blockName. If you left this property empty, component will throw an error. blockName just concatenates with classNames property.

If you want to define an element component (with block__element class name and custom logic), you just add elemName property in component definition:

import Ember from 'ember';
import BEM from 'ember-cli-bem/mixins/bem';

export default Ember.Component.extend(BEM, {
  blockName: 'button',
  elemName: 'icon'
});

This component will have a button__icon class.

Defining Modifiers

When you want to define a modifier for your component, you should define mods array, which acts just like classNameBindings, but with some BEM attached:

import Ember from 'ember';
import BEM from 'ember-cli-bem/mixins/bem';

export default Ember.Component.extend(BEM, {
  blockName: 'button',

  mods: [
    'disabled',
    'type',
    'clear:with-clear:without-clear'
  ],

  disabled: true,
  type: 'submit',
  clear: false,
});

This component will have a button class with following modifier classes:

  • button_disabled
  • button_type_submit
  • button_without-clear

Using elem helper

In templates of your BEM-components you could use elem helper to generate BEM class names:

  <div class="{{elem 'icon'}}"></div>
  <div class="{{elem 'caption'}}">
    {{text}}
  </div>

Applying button example, these elements will have button__icon and button__caption classes accordingly.

Also elem helper supports modifiers:

  <div class="{{elem 'container' collapsed=true type='float'}}">
    {{yield}}
  </div>

So container element will have following class names:

  • button__container
  • button__container_collapsed
  • button__container_type_float

Installation

ember install ember-cli-bem

For more information on using ember-cli, visit https://ember-cli.com/.