Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global config with icon class option #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ _Note: this usage is not recommended as it cannot be tree-shaken._
import Vue from "vue";
import VueTablerIcons from "vue-tabler-icons";

Vue.use(VueTablerIcons);
Vue.use(VueTablerIcons, {
iconClass: 'icon', // add a class to each icon
});
```

Now you can use icons without importing them:
Expand All @@ -95,7 +97,9 @@ The library doesn't automatically registers itself so you need to do it manually

```html
<script>
Vue.use(VueTablerIcons);
Vue.use(VueTablerIcons, {
iconClass: 'icon', // add a class to each icon
});
</script>
```

Expand Down
2 changes: 2 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ export default {
render() {
const size = this.$props.size + 'px';
const attrs = this.$data.attrs || {};
const iconClass = this.$tiConfig.iconClass;

const allAttrs = {
width: attrs.width || size,
height: attrs.height || size,
class: iconClass,
}

return ${svg.replace(/<svg([^>]+)>/, "<svg$1 {...allAttrs}>").replace('icon icon-tabler ', 'icon-tabler ')}
Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ export * from './icons';
import * as components from './icons';

export default {
install(Vue) {
install(Vue, options = {}) {
Vue.config.globalProperties.$tiConfig = Object.assign({}, {
iconClass: '',
}, options);
Object
.entries(components)
.forEach(([name, component]) => Vue.component(name, component));
Expand Down