ember-class-names-helper

0.3.0 • Public • Published

{{class-names}} helper

CI status NPM version

Provides a cleaner way for conditionally joining class names in templates.

Before:

<button class="button {{if @primary "button--primary"}} {{if @small "button--small"}} {{if @disabled "is-disabled"}}" type="button">
  Submit
</button>

After:

<button
  class={{class-names
    "button"
    button--primary=@primary
    button--small=@small
    is-disabled=@disabled
  }}
  type="button"
>
  Submit
</button>

Or with {{cn}} alias in a single line:

<button
  class={{cn "button" button--primary=@primary button--small=@small is-disabled=@disabled}}
  type="button"
>
  Submit
</button>

Installation

ember install ember-class-names-helper

The helper relies on a tiny and well-tested library classnames.

Usage

<button
  class={{class-names
    "button"
    (if @fancy "bg-white rounded-lg p-6")
    button--primary=@primary
    is-disabled=@disabled
  }}
  type="button"
/>

Or with {{cn}} alias:

<button
  class={{cn "button" is-disabled=@disabled}}
  type="button"
/>

Compatibility

  • Ember.js v3.20 or above
  • Ember CLI v3.20 or above
  • Node.js v12 or above

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i ember-class-names-helper

Weekly Downloads

513

Version

0.3.0

License

MIT

Unpacked Size

7.84 kB

Total Files

15

Last publish

Collaborators

  • ivanvotti
  • jfh