2018-09-10 17:25:36 -05:00
|
|
|
<template>
|
|
|
|
<svg v-bind="svgAttributes" v-html="svgContent" :class="calculatedClasses"></svg>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
import Caret from "../iconic/svg/smart/caret";
|
|
|
|
import Check from "../iconic/svg/smart/check";
|
|
|
|
import CircleCheck from "../iconic/svg/smart/circle-check";
|
|
|
|
import Link from "../iconic/svg/smart/link";
|
|
|
|
import Lock from "../iconic/svg/smart/lock";
|
|
|
|
import Menu from "../iconic/svg/smart/menu";
|
2020-08-30 17:43:47 -05:00
|
|
|
import QuestionMark from "../iconic/svg/smart/question-mark.svg"
|
2018-09-10 17:25:36 -05:00
|
|
|
import Person from "../iconic/svg/smart/person";
|
|
|
|
import Pencil from "../iconic/svg/smart/pencil";
|
|
|
|
import Star from "../iconic/svg/smart/star";
|
|
|
|
import StarEmpty from "../iconic/svg/smart/star-empty";
|
2018-09-13 14:51:41 -05:00
|
|
|
import Warning from "../iconic/svg/smart/warning";
|
2018-09-10 17:25:36 -05:00
|
|
|
import X from "../iconic/svg/smart/x";
|
|
|
|
|
|
|
|
const APIS = {};
|
|
|
|
const LOADED_APIS = {};
|
|
|
|
|
|
|
|
window._Iconic = {
|
|
|
|
smartIconApis: APIS
|
|
|
|
};
|
|
|
|
|
|
|
|
let globalIdCounter = 0;
|
|
|
|
|
|
|
|
const iconMap = {
|
|
|
|
caret: Caret,
|
|
|
|
check: Check,
|
|
|
|
'circle-check': CircleCheck,
|
|
|
|
link: Link,
|
|
|
|
lock: Lock,
|
|
|
|
menu: Menu,
|
|
|
|
pencil: Pencil,
|
|
|
|
person: Person,
|
2020-08-30 17:43:47 -05:00
|
|
|
'question-mark': QuestionMark,
|
2018-09-10 17:25:36 -05:00
|
|
|
star: Star,
|
|
|
|
'star-empty': StarEmpty,
|
2018-09-13 14:51:41 -05:00
|
|
|
warning: Warning,
|
2018-09-10 17:25:36 -05:00
|
|
|
x: X
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
icon: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
validator: (i) => iconMap[i] !== undefined
|
|
|
|
},
|
|
|
|
|
|
|
|
size: {
|
|
|
|
type: String,
|
|
|
|
default: "lg",
|
|
|
|
validator: (s) => ["sm", "md", "lg"].indexOf(s) >= 0
|
|
|
|
},
|
|
|
|
|
|
|
|
iconSizeOverride: {
|
|
|
|
type: String,
|
|
|
|
validator: (s) => ["sm", "md", "lg", null].indexOf(s) >= 0
|
|
|
|
},
|
|
|
|
|
|
|
|
displaySizeOverride: {
|
|
|
|
type: String,
|
|
|
|
validator: (s) => ["sm", "md", "lg", null].indexOf(s) >= 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
calculatedClasses: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
svgData() {
|
|
|
|
return iconMap[this.icon];
|
|
|
|
},
|
|
|
|
|
|
|
|
svgAttributes() {
|
|
|
|
return this.svgData.attributes;
|
|
|
|
},
|
|
|
|
|
|
|
|
svgName() {
|
|
|
|
return this.svgAttributes['data-icon'];
|
|
|
|
},
|
|
|
|
|
|
|
|
svgContent() {
|
|
|
|
let content = String(this.svgData.content);
|
|
|
|
|
|
|
|
for (let idRep of this.svgData.idReplacements) {
|
|
|
|
let newId = `__new_id_${globalIdCounter}`;
|
|
|
|
globalIdCounter += 1;
|
|
|
|
|
|
|
|
content = content.replace(new RegExp(idRep, "g"), newId);
|
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
rebind() {
|
|
|
|
const apis = APIS;
|
|
|
|
|
|
|
|
if (apis && this.svgName && apis[this.svgName]) {
|
|
|
|
const iconApi = apis[this.svgName](this.$el);
|
|
|
|
for (let func in iconApi) this.$el[func] = iconApi[func]
|
|
|
|
} else {
|
|
|
|
this.$el.update = function() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.calculatedClasses = (this.svgAttributes.class || "").split(" ");
|
|
|
|
|
|
|
|
this.calculatedClasses.push(`iconic-${this.size}`);
|
|
|
|
|
|
|
|
if (this.iconSizeOverride) {
|
|
|
|
this.calculatedClasses.push(`iconic-icon-${this.iconSizeOverride}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.displaySizeOverride) {
|
|
|
|
this.calculatedClasses.push(`iconic-size-${this.displaySizeOverride}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$el.update();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
if (LOADED_APIS[this.svgName] !== true) {
|
|
|
|
for (let sb of this.svgData.scriptBlocks) {
|
2024-09-28 20:58:25 -05:00
|
|
|
try {
|
|
|
|
new Function(sb)(window);
|
|
|
|
} catch (e) {
|
|
|
|
console.log(sb);
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
|
2018-09-10 17:25:36 -05:00
|
|
|
}
|
|
|
|
LOADED_APIS[this.svgName] = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
|
|
|
|
this.$watch(
|
|
|
|
function() { return [this.$attrs, this.icon, this.fluid] },
|
|
|
|
function() {
|
|
|
|
this.rebind()
|
|
|
|
},
|
|
|
|
{
|
|
|
|
immediate: true
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|