Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Created July 11, 2019 19:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save JeffreyWay/734b53ceacc3fc94d604b59993917cec to your computer and use it in GitHub Desktop.
Save JeffreyWay/734b53ceacc3fc94d604b59993917cec to your computer and use it in GitHub Desktop.
class Svg {
constructor(name) {
let div = document.createElement('div');
div.innerHTML = require('../images/badges/' + name); // be careful with dynamic webpack requires.
let fragment = document.createDocumentFragment();
fragment.appendChild(div);
this.svg = fragment.querySelector('svg');
}
classes(classes) {
if (classes) {
this.svg.classList.add(classes);
}
return this;
}
width(width) {
if (width) {
this.svg.setAttribute('width', width);
}
return this;
}
height(height) {
if (height) {
this.svg.setAttribute('height', height);
}
return this;
}
toString() {
return this.svg.outerHTML;
}
}
export default {
props: ['name', 'classes', 'width', 'height'],
render(h) {
return h('div', {
domProps: {
innerHTML: new Svg(this.name)
.classes(this.classes)
.width(this.width)
.height(this.height)
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment