@@ -4,9 +4,10 @@ import { computed } from "vue"
44import icons from " @/assets/icons.json"
55
66const props = defineProps ({
7- name: { type: String , required: true , default: " warning " },
7+ name: { type: String , required: true , default: " " },
88 size: { type: [String , Number ], default: " 16" },
99 color: { type: String , default: null },
10+ hoverColor: { type: String , required: false },
1011 rotate: { type: [String , Number ], default: 0 },
1112 fill: { type: Boolean , default: false },
1213 scale: { type: [String , Number ], default: 1 },
@@ -15,8 +16,8 @@ const props = defineProps({
1516
1617const styles = computed (() => {
1718 const s = {
18- minWidth: ` ${ props .size } px` ,
19- minHeight: ` ${ props .size } px` ,
19+ minWidth: ` ${ props .size } px` ,
20+ minHeight: ` ${ props .size } px` ,
2021 transformBox: " view-box" ,
2122 transformOrigin: " center center" ,
2223 transform: " " ,
@@ -25,7 +26,7 @@ const styles = computed(() => {
2526 const ops = []
2627 if (props .rotate ) ops .push (` rotate(${ props .rotate } deg)` )
2728 if (props .scale != 1 ) ops .push (` scale(${ props .scale } )` )
28- if (ops .length ) s .transform = ops .join (" " )
29+ if (ops .length ) s .transform = ops .join (" " )
2930
3031 return s
3132})
@@ -38,6 +39,10 @@ const classes = computed(() => {
3839 return iconClasses
3940})
4041
42+ const hoverColorVar = computed (() => {
43+ return ` var(--txt-${ props .hoverColor } )`
44+ })
45+
4146const getIcon = () => {
4247 return icons[props .name .charAt (0 ).toLowerCase () + props .name .slice (1 )]
4348}
@@ -48,7 +53,14 @@ const isSplitted = () => {
4853 </script >
4954
5055<template >
51- <svg viewBox =" 0 0 24 24" :width =" size" :height =" size" :style =" styles" :class =" [classes, loading && $style.loading]" role =" img" >
56+ <svg
57+ viewBox =" 0 0 24 24"
58+ :width =" size"
59+ :height =" size"
60+ :style =" styles"
61+ :class =" [classes, hoverColor && $style.hovered, loading && $style.loading]"
62+ role =" img"
63+ >
5264 <path v-if =" !isSplitted(name)" :d =" getIcon(name)" />
5365 <template v-else >
5466 <path v-if =" !Array.isArray(getIcon(name))" :d =" getIcon(name)" :style =" { opacity: path.opacity }" />
@@ -66,6 +78,14 @@ const isSplitted = () => {
6678</template >
6779
6880<style module>
81+ .hovered {
82+ transition : all 0.3s var (--bezier );
83+
84+ &:hover {
85+ fill : v-bind(hoverColorVar);
86+ }
87+ }
88+
6989.loading {
7090 animation : skeleton 1s ease-in-out infinite ;
7191}
@@ -83,4 +103,4 @@ const isSplitted = () => {
83103 opacity : 1 ;
84104 }
85105}
86- </style >
106+ </style >
0 commit comments