Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/wandersonalves/vue-shadow-badge

:moon: Simple badge directive using shadow-dom (with fallback)
https://github.com/wandersonalves/vue-shadow-badge

badge css pseudo-elements shadow-dom vue

Last synced: 1 day ago
JSON representation

:moon: Simple badge directive using shadow-dom (with fallback)

Awesome Lists containing this project

README

        

# vue-shadow-badge!

![logo](https://github.com/WandersonAlves/vue-shadow-badge/blob/master/prints/vue-badge.png?raw=true)

[![GitHub stars](https://img.shields.io/github/stars/WandersonAlves/vue-shadow-badge.svg?style=flat-square)](https://github.com/WandersonAlves/vue-shadow-badge/stargazers)
[![GitHub license](https://img.shields.io/github/license/WandersonAlves/vue-shadow-badge.svg?style=flat-square)](https://github.com/WandersonAlves/vue-shadow-badge)

## DEPRECATED

element.createShadowRoot is [DEPRECATED](https://developer.mozilla.org/en-US/docs/Web/API/Element/createShadowRoot), and using [element.attachShadow](https://developer.mozilla.org/en-US/docs/Web/API/Element/attachShadow) don't seens to work on the examples. Using fallback currently works (for anyone willing to study this directive). And Vue 3 is close to be released, so, this directive will not receive any update from me. Thanks!

## Instalation

Use `yarn add vue-shadow-badge` or `npm i --save vue-shadow-badge`

## Motivation

In my search for badges, i only found component based badges, for me, this isn't the ideal, so a build a directive based badge that is extensible and highly configurable.

With shadow-dom is easy to create pseudo-elements in any element with a shadowRoot, just look at `src/directives/Badge/utils/shadow-dom.js`.

Sadly, shadow-dom isn't supported in all browsers, so keep in mind this.

https://caniuse.com/#feat=shadowdom

### But...

Now this directive have a fallback for browsers without shadow-dom. If you encounter something strange, please let me know it.

___

## Usage

Simple import globally or locally in your vue app.

Locally:

```
//SomeComponent.vue

import Badge from 'vue-shadow-badge';

export default {
directives: {
Badge
}
}
```

Global:

```
//main.js (or another entry point)

import Vue from 'vue';
import App from './App.vue';
import Badge from 'vue-shadow-badge';

new Vue({
render: h => h(App),
directives: {
Badge
}
}).$mount('#app')
```

Now you can use your new directive like this:

`

Examples

`

or this:

`Hi!`

or even this:

``

___

`badgeConfig` accept some values:

| Prop | Type | Description |
|--------|--------|-----------------------------------------|
| value | number | Sets the value on Badge |
| right | string | Set the right value for badge placement |
| left | string | Set the left value for badge placement |
| down | string | Set the down value for badge placement |
| up | string | Set the up value for badge placement |
| styles | string | Customize your badge! (see above) |

___

## Examples

```

export default {
data() {
return {
badgeConfig: {
value: 2,
right: '-20px',
top: '-4px'
},
buttonBadgeStyle: `
border: 2px solid #662a24;
color: #662a24;
background-color: transparent;
font-size: 0.9em;
`
}
}
}
}

```
You can use `styles` prop to set the positioning of the badge too! Just use `right|top|bottom|left: value`

## Contributing

This is a beginner friendly open source project. Submit your PR, let's discuss some improvements.