Giter Site home page Giter Site logo

angular-bem's Introduction

angular-bem

Build Status Join the chat at https://gitter.im/tenphi/angular-bem

A set of directives to simplify your workflow with BEM-markup in AngularJS applications.

Changelog

1.1.0

  • New mod-once attribute to bind modifiers without watchers. Note that there is no sense or capability to use mod and mod-once attributes simultaneously on a single node.
  • New bemConfigProvider with following API:
    • #setSeparators(el, mod, value) - Specify class separators for your own syntax approach.
    • #ignoreValues(bool) - If it's true then no value will add to the modifier class name. Use it if you don't need values in your markup and tired of having to write !! before modifier values. Default value is false.
    • setModCase(modCase) - Specify modifier name case. Use it if you have different naming approach. Posible values: kebab, snake, camel. If you will use the last option the modifier name will not be changed at all. Default value is kebab.

1.0.0

  • New braces-free syntax
  • Automatic one-time bindings without additional syntax
  • Performance improvements
  • New tests

0.4.1

  • Add test coverage.
  • Add one-time binding syntax. (it looks like angular 1.3 one-time binding syntax but it's not the same)
  • Fix bugs

0.4.0

  • Improved performance.

0.3.0

  • Default syntax changed. block__elem--mod-value
  • mod can now accept array and string with space delimiter

Install

$ bower install angular-bem

or

$ npm install angular-bem

Example

Include this module to your app:

angular.module('app', ['tenphi.bem']);

Create a simple markup:

<body ng-app="app">
  <div block="my-block" mod="modName: 'value'">
    <div elem="my-element" mod="modName: 'value'; secondModName"></div>
  </div>
</body>

It will be transformed into following markup:

<div class="my-block my-block--mod-name-value">
  <div class="my-block__my-element my-block__my-element--mod-name-value my-block__my-element--second-mod-name"></div>
</div>

Of course there is a support for conditional modifiers:

<div block="my-block" mod="disabled: $ctrl.isDisabled"></div>

One-time binding syntax

Note that if you use only mod names in mod attribute (without values) then no watchers will be created on this node by angular-bem.

<body ng-app="app">
  <div block="my-block" mod="modName"></div>
</body>

Use mod-once attribute instead of mod to prevent watcher creation.

<body ng-app="app">
  <div block="my-block" mod-once="modName: $ctrl.model.modName"></div>
</body>

Syntax customization

Create your own BEM-like syntax:

app.config(function(bemConfigProvider) {
  bemConfigProvider.setSeparators('--', '__', '_');
});

Now output of previous example will look like:

<div class="my-block my-block__mod-name_value">
  <div class="my-block--my-element my-block--my-element__mod-name_value my-block--my-element__second-mod-name"></div>
</div>

Ignore values

If you don't use values in your markup and tired of having to write !! before modifier values you can easily disable value addition.

app.config(function(bemConfigProvider) {
  bemConfigProvider.ignoreValues();
});

Change modifier naming

By default modifer name will be converted to kabeb case after rendering but you can change it to 'snake' or 'camel' if you use different naming approach. camel option will disable transformation at all.

app.config(function(bemConfigProvider) {
  bemConfigProvider.setModCase('snake');
});

Need to know

  • These directives don't affect scope or other directives. So you can use them at ease wherever you want.
  • You can only specify one element or block on single node. This limitation greatly simplify code of module and your app.
  • There is no way to create an element of parent block inside nested block. It's not a component-way. So please avoid it.

License

MIT © Andrey Yamanov

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.