index.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <div
  3. v-if="isExternal"
  4. :style="styleExternalIcon"
  5. class="svg-external-icon svg-icon"
  6. v-on="$listeners"
  7. />
  8. <svg v-else :class="svgClass" aria-hidden="true" v-on="$listeners">
  9. <use :xlink:href="iconName" />
  10. </svg>
  11. </template>
  12. <script>
  13. import { isExternal } from '@/utils/validate'
  14. export default {
  15. name: 'VabRemixIcon',
  16. props: {
  17. iconClass: {
  18. type: String,
  19. required: true,
  20. },
  21. className: {
  22. type: String,
  23. default: '',
  24. },
  25. },
  26. computed: {
  27. isExternal() {
  28. return isExternal(this.iconClass)
  29. },
  30. iconName() {
  31. return `#remix-icon-${this.iconClass}`
  32. },
  33. svgClass() {
  34. if (this.className) {
  35. return 'svg-icon ' + this.className
  36. } else {
  37. return 'svg-icon'
  38. }
  39. },
  40. styleExternalIcon() {
  41. return {
  42. mask: `url(${this.iconClass}) no-repeat 50% 50%`,
  43. '-webkit-mask': `url(${this.iconClass}) no-repeat 50% 50%`,
  44. }
  45. },
  46. },
  47. }
  48. </script>
  49. <style lang="scss" scoped>
  50. .svg-icon {
  51. width: 1.125em;
  52. height: 1.125em;
  53. overflow: hidden;
  54. fill: currentColor;
  55. &:hover {
  56. opacity: 0.8;
  57. }
  58. }
  59. .svg-external-icon {
  60. display: inline-block;
  61. background-color: currentColor;
  62. mask-size: cover !important;
  63. }
  64. </style>