-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsvg-icon.vue
76 lines (67 loc) · 1.25 KB
/
svg-icon.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<template>
<svg
:width="sizeValue"
:height="sizeValue"
:viewBox="viewboxValue"
:style="styles"
>
<path :d="path" />
</svg>
</template>
<script>
// todo : move this into own release
const types = {
mdi: {
size: 24,
viewbox: "0 0 24 24",
},
"simple-icons": {
size: 24,
viewbox: "0 0 24 24",
},
default: {
size: 0,
viewbox: "0 0 0 0",
},
}
export default {
name: "icon",
props: {
type: String,
path: { type: String, required: true },
size: { type: Number, default: 24 },
viewbox: String,
flip: {
type: String,
validator: () => ["horizontal", "vertical", "both"].includes(value),
},
rotate: { type: Number, default: 0 },
},
computed: {
styles() {
return {
"--sx": ["both", "horizontal"].includes(this.flip) ? "-1" : "1",
"--sy": ["both", "vertical"].includes(this.flip) ? "-1" : "1",
"--r": isNaN(this.rotate) ? this.rotate : this.rotate + "deg",
}
},
defaults() {
return types[this.type] || types.default
},
sizeValue() {
return this.size || this.defaults.size
},
viewboxValue() {
return this.viewbox || this.defaults.viewbox
},
},
}
</script>
<style scoped>
svg {
transform: rotate(var(--r, 0deg)) scale(var(--sx, 1), var(--sy, 1));
}
path {
fill: currentColor;
}
</style>