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

vue-bem-generator

v1.0.3

Published

Vue bem class generator

Downloads

5

Readme

vue-bem-generator

Generate programmatically BEM classes with a light-weight vue plugin.

Install

npm install --save vue-bem-generator

Configuration

import VueBemGenerator from 'vue-bem-generator';

Vue.use(VueBemGenerator);

Basic usage

<template>
  <div :class="bem()">
    <div :class="bemElem('content')">
      <button :class="bemElem('button', ['primary', 'big'])">Go Next</button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'main-block',
};
</script>

// Renders
<div class="main-block">
  <div class="main-block__content">
    <button
      class="main-block__button main-block__button--primary main-block__button--big"
    >
      Go Next
    </button>
  </div>
</div>

Using block name

<template>
  <div :class="bem()">
    Content
  </div>
</template>

<script>
export default {
  name: 'main-block',
};
</script>

// Renders
<div class="main-block">
  Content
</div>

If don't want to use component name, could be used block.

<template>
  <div :class="bem()">
    Content
  </div>
</template>

<script>
export default {
  name: 'main-block',
  block: 'section-block'
};
</script>

// Renders
<div class="section-block">
  Content
</div>

Also block and name would be overwritten with bem method.

<template>
  <div :class="bem('custom-block')">
    Content
  </div>
</template>

<script>
export default {
  name: 'main-block',
  block: 'section-block'
};
</script>

// Renders
<div class="custom-block">
  Content
</div>

Using elements

<template>
  <div :class="bem()">
    <div :class="bemElem('content')">
      Content
    </div>
  </div>
</template>

<script>
export default {
  name: 'main-block',
};
</script>

// Renders
<div class="main-block">
  <div class="main-block__content">
    Content
  </div>
</div>

Usually you don't need nested elements but it could be used by sending an array.

<template>
  <div :class="bem()">
    <div :class="bemElem(['content', 'subcontent'])">
      Content
    </div>
  </div>
</template>

<script>
export default {
  name: 'main-block',
};
</script>

// Renders
<div class="main-block">
  <div class="main-block__content__subcontent">
    Content
  </div>
</div>

If you need an element with different block name use bem method instead bemElem (usually that means you need another component but I'm not going to judge you).

<template>
  <div :class="bem()">
    <div :class="bemElem('content')">
      Content
    </div>
    <div :class="bem('side-block')">
      Content
    </div>
  </div>
</template>

<script>
export default {
  name: 'main-block',
};
</script>

// Renders
<div class="main-block">
  <div class="main-block__content">
    Content
  </div>
  <div class="side-block">
    Content
  </div>
</div>

On elements array, values can be disabled if used falsy values (to enable it again should be used string value).

<template>
  <div :class="bem()">
    <div :class="bemElem([content, subcontent])">
      Content
    </div>
  </div>
</template>

<script>
export default {
  name: 'main-block',
  data() {
    return {
      content: 'content'
      subcontent: false
    };
  }
};
</script>

// Renders
<div class="main-block">
  <div class="main-block__content">
    Content
  </div>
</div>

Using modifiers

String or array could be used for simple modifiers.

<template>
  <div :class="bem()">
    <div :class="bemElem('content')">
      <button :class="bemElem('btn', 'primary')">Update</button>
      <button :class="bemElem('btn', ['danger', 'big'])">Delete</button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'main-block',
};
</script>

// Renders
<div class="main-block">
  <div class="main-block__content">
    <button class="main-block__btn main-block__btn--primary">Update</button>
    <button class="main-block__btn main-block__btn--danger main-block__btn--big">Delete</button>
  </div>
</div>

Of course only modifiers could be used.

<template>
  <div :class="bemMod('fullsize')">
    <div :class="bemElem('head')">
      Head
    </div>
  </div>
</template>

<script>
export default {
  name: 'dialog',
};
</script>

// Renders
<div class="dialog dialog--fullsize">
  <div class="dialog__head">
    Head
  </div>
</div>

In same way like elements, a falsy value can disable a modifier.

<template>
  <div :class="bemMod([color, bordered])">
    Content
  </div>
</template>

<script>
export default {
  name: 'main-block',
  data() {
    return {
      color: 'green',
      bordered: false // Remember to use a string for enable this
    };
  }
};
</script>

// Renders
<div class="main-block main-block-green">
  Content
</div>

Instead sending string or array for modifiers, send an object allowing you to use hyphenate notation.

<template>
  <div :class="bemMod({size: 'fullsize', type: 'confirm'})">
    <div :class="bemElem('head')">
      Head
    </div>
  </div>
</template>

<script>
export default {
  name: 'dialog',
};
</script>

// Renders
<div class="dialog dialog--size-fullsize dialog--type-confirm">
  <div class="dialog__head">
    Head
  </div>
</div>

Instead of string on each object element, boolean values can disable/enable them.

<template>
  <ul :class="bem()">
    <li
      v-for="(item, i) in items"
      :key="i"
      :class="bemElem('item', { selected: item.selected })"
    >
      {{ item.value }}
    </li>
  </ul>
</template>

<script>
export default {
  name: 'list',
  data() {
    return {
      items: [
        { value: 'One task', selected: false },
        { value: 'Other task', selected: true }
      ]
    };
  }
};
</script>

// Renders
<ul class="list">
  <li class="list__item">One task</li>
  <li class="list__item list__item--selected">Other task</li>
</ult>

Api

bem(block, element, modifiers)

Defines BEM class with all 3 optional parameters. If no one is sent, block name is set with block or name component value.

bemElem(element, modifiers)

Set BEM element and modifiers without overwriting block name.

bemMod(modifiers)

Set BEM modifiers without overwriting block name.

Parameters definition

|Parameter |Type |Description | |-----------------|----------------------|-------------------------------------------| |block |string |Overwrite block and name component value | |element |string, array |Define class element value | |modifiers |string, array, object |Define modifiers for current block/element |

Contribution

All pull requests and suggestions are welcome.