Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vuebits/bem

Simple implementation of BEM in Vue 3
https://github.com/vuebits/bem

bem bem-css bem-methodology bem-naming vue vuejs vuejs3

Last synced: 1 day ago
JSON representation

Simple implementation of BEM in Vue 3

Awesome Lists containing this project

README

        

Vue 3 BEM

*** Maintainers & Contributors welcome ***



Vue.js
BEM

Simple implementation of BEM in Vue 3.x


Based on Vue 2.x library vue-bem-cn

---

## Table of Contents

* [Installation](#installation)
* [API](#api)
* [Documentation](#documentation)

## Installation

`npm i @vuebits/bem` / `yarn add @vuebits/bem`

And install in your entry file (e.g. `main.js`):

```javascript
import { createBem } from '@vuebits/bem';

createApp(App).use(createBem({ /* your config here */ })).mount('#app');
```

## API

### Available functions:

* `createBem (options: BemOptions)`:

```ts
interface BemOptions {
hyphenate?: boolean;
}
```

### Vue instance properties and methods:

* `$bem ({ b, e, m }: BemItem): string[]`:

```ts
interface BemItem {
b?: string;
e?: string;
m?: string | string[] | {[key in string]: boolean};
}
```

## Examples

### Using component name by default:

```vue


Hello world!

import { defineComponent } from 'vue';

export default defineComponent({
name: 'hello-world'
});

.hello-world {
// some styles here
}

```

### Using hyphenated component name:

If you use PascalCase naming convence you should init library with `hyphenate` option:

```js
import { createBem } from '@vuebits/bem';

createApp(App).use(createBem({
hyphenate: true
})).mount('#app');
```

and then:

```vue


Hello world!

import { defineComponent } from 'vue';

export default defineComponent({
name: 'HelloWorld'
});

.hello-world {
// some styles here
}

```

### Custom block name:

```vue


Hello world!

import { defineComponent } from 'vue';

export default defineComponent({
name: 'HelloWorld'
});

.custom-block {
// some styles here
}

```

### Element name:

```vue



Hello world!



This is a description


import { defineComponent } from 'vue';

export default defineComponent({
name: 'HelloWorld'
});

.hello-world {
// some styles here
&__title {
// some styles here
}
&__description {
// some styles here
}
}

```

### Inline modfiers:

```vue



This is a description



This is a description


import { defineComponent } from 'vue';

export default defineComponent({
name: 'HelloWorld'
});

.hello-world {
// some styles here
&__text {
// some styles here
&--underlined {
// some styles here
}
&--highlighted {
// some styles here
}
}
}

```

### Conditional modfiers:

```vue



This is a description


import { defineComponent } from 'vue';

export default defineComponent({
name: 'HelloWorld',
data () {
return {
isHighlighted: false
};
}
});

.hello-world {
// some styles here
&__description {
// some styles here
&--underlined {
// some styles here
}
&--highlighted {
// some styles here
}
}
}

```