ActionIconGlyph.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <span class="action-icon-glyph">
  3. <HugeiconsIcon
  4. v-if="hugeiconsModel"
  5. :icon="hugeiconsModel"
  6. width="1em"
  7. height="1em"
  8. class="action-icon-glyph-svg"
  9. />
  10. <!-- eslint-disable vue/no-v-html -- intentional: action icons may use HTML / custom-webui <img> -->
  11. <span
  12. v-else-if="decodedTextGlyphIsHtml"
  13. v-html="decodedTextGlyph"
  14. />
  15. <!-- eslint-enable vue/no-v-html -->
  16. <span
  17. v-else
  18. v-text="decodedTextGlyph"
  19. />
  20. </span>
  21. </template>
  22. <script setup>
  23. import { computed } from 'vue'
  24. import { HugeiconsIcon } from '@hugeicons/vue'
  25. import { CommandLineIcon } from '@hugeicons/core-free-icons'
  26. import { decodeHtmlEntities, glyphLooksLikeHtml } from './actionIconGlyphHelpers.mjs'
  27. const hugeiconsPrefix = 'hugeicons:'
  28. /** Maps config values like hugeicons:CommandLineIcon to Hugeicons icon definitions. */
  29. const hugeiconsRegistry = {
  30. CommandLineIcon
  31. }
  32. const props = defineProps({
  33. glyph: {
  34. type: String,
  35. required: false,
  36. default: ''
  37. }
  38. })
  39. const hugeiconsModel = computed(() => {
  40. if (!props.glyph) {
  41. return CommandLineIcon
  42. }
  43. if (!props.glyph.startsWith(hugeiconsPrefix)) {
  44. return null
  45. }
  46. const name = props.glyph.slice(hugeiconsPrefix.length)
  47. const iconModel = hugeiconsRegistry[name]
  48. return iconModel ?? CommandLineIcon
  49. })
  50. const decodedTextGlyph = computed(() => {
  51. if (hugeiconsModel.value) {
  52. return ''
  53. }
  54. return decodeHtmlEntities(props.glyph)
  55. })
  56. const decodedTextGlyphIsHtml = computed(() => glyphLooksLikeHtml(decodedTextGlyph.value))
  57. </script>
  58. <style scoped>
  59. .action-icon-glyph {
  60. display: inline-flex;
  61. vertical-align: middle;
  62. align-items: center;
  63. justify-content: center;
  64. }
  65. .action-icon-glyph-svg {
  66. vertical-align: middle;
  67. }
  68. </style>