parsley/app/javascript/components/AppIcon.vue

121 lines
2.4 KiB
Vue
Raw Normal View History

2018-03-30 17:08:09 -05:00
<template>
<span class="icon" :class="sizeClass" @click="$emit('click', $event)">
<svg v-html="svgContent" v-bind="svgAttributes"></svg>
</span>
</template>
<script>
2018-04-01 21:43:23 -05:00
import CaretBottom from "open-iconic/svg/caret-bottom";
import CaretTop from "open-iconic/svg/caret-top";
2018-04-02 00:10:06 -05:00
import Check from "open-iconic/svg/check";
import CircleCheck from "open-iconic/svg/circle-check.svg";
2018-04-03 18:31:20 -05:00
import LinkBroken from "open-iconic/svg/link-broken";
import LinkIntact from "open-iconic/svg/link-intact";
2018-03-30 17:08:09 -05:00
import LockLocked from "open-iconic/svg/lock-locked";
import LockUnlocked from "open-iconic/svg/lock-unlocked";
2018-04-01 21:43:23 -05:00
import Person from "open-iconic/svg/person";
2018-04-03 18:31:20 -05:00
import Pencil from "open-iconic/svg/pencil";
2018-04-03 10:29:57 -05:00
import Star from "open-iconic/svg/star";
2018-04-01 21:43:23 -05:00
import X from "open-iconic/svg/x";
2018-03-30 17:08:09 -05:00
const iconMap = {
2018-04-01 21:43:23 -05:00
'caret-bottom': CaretBottom,
'caret-top': CaretTop,
2018-04-02 00:10:06 -05:00
check: Check,
'circle-check': CircleCheck,
2018-04-03 18:31:20 -05:00
'link-broken': LinkBroken,
'link-intact': LinkIntact,
2018-03-30 17:08:09 -05:00
'lock-locked': LockLocked,
2018-04-01 21:43:23 -05:00
'lock-unlocked': LockUnlocked,
2018-04-03 18:31:20 -05:00
pencil: Pencil,
2018-04-01 21:43:23 -05:00
person: Person,
2018-04-03 10:29:57 -05:00
star: Star,
2018-04-01 21:43:23 -05:00
x: X
2018-03-30 17:08:09 -05:00
};
const sizeMap = {
sm: 'is-small',
md: '' ,
lg: 'is-medium',
xl: 'is-large'
};
export default {
props: {
icon: {
validator: (i) => iconMap[i] !== undefined
},
size: {
required: false,
type: String,
validator: (s) => sizeMap[s] !== undefined,
default: 'md'
}
},
computed: {
svgObj() {
return iconMap[this.icon];
},
svgAttributes() {
const attrs = {
class: this.size
};
for (let a of ['viewBox', 'xmlns']) {
if (this.svgObj.attributes[a]) {
attrs[a] = this.svgObj.attributes[a];
}
}
return attrs;
},
svgContent() {
return this.svgObj.content;
},
sizeClass() {
return sizeMap[this.size];
}
}
}
</script>
<style lang="scss" scoped>
.icon {
svg {
width: 100%;
height: 100%;
fill: currentColor;
&.sm {
2018-04-03 18:31:20 -05:00
width: 0.6em;
height: 0.6em;
}
&.md {
2018-03-30 17:08:09 -05:00
width: 1em;
height: 1em;
}
2018-04-03 18:31:20 -05:00
&.lg {
2018-03-30 17:08:09 -05:00
width: 1.33em;
height: 1.33em;
}
2018-04-03 18:31:20 -05:00
&.xl {
2018-03-30 17:08:09 -05:00
width: 2em;
height: 2em;
}
2018-04-03 18:31:20 -05:00
/*&.xl {*/
/*width: 3em;*/
/*height: 3em;*/
/*}*/
2018-03-30 17:08:09 -05:00
}
}
</style>