4
0

ActionIconGlyph.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. <span v-else-if="decodedTextGlyphIsHtml" v-html="decodedTextGlyph"></span>
  11. <span v-else v-text="decodedTextGlyph"></span>
  12. </span>
  13. </template>
  14. <script setup>
  15. import { computed } from 'vue'
  16. import { HugeiconsIcon } from '@hugeicons/vue'
  17. import { CommandLineIcon } from '@hugeicons/core-free-icons'
  18. import { decodeHtmlEntities, glyphLooksLikeHtml } from './actionIconGlyphHelpers.mjs'
  19. const hugeiconsPrefix = 'hugeicons:'
  20. /** Maps config values like hugeicons:CommandLineIcon to Hugeicons icon definitions. */
  21. const hugeiconsRegistry = {
  22. CommandLineIcon,
  23. }
  24. const props = defineProps({
  25. glyph: {
  26. type: String,
  27. required: false,
  28. default: '',
  29. },
  30. })
  31. const hugeiconsModel = computed(() => {
  32. if (!props.glyph) {
  33. return CommandLineIcon
  34. }
  35. if (!props.glyph.startsWith(hugeiconsPrefix)) {
  36. return null
  37. }
  38. const name = props.glyph.slice(hugeiconsPrefix.length)
  39. const iconModel = hugeiconsRegistry[name]
  40. return iconModel ?? CommandLineIcon
  41. })
  42. const decodedTextGlyph = computed(() => {
  43. if (hugeiconsModel.value) {
  44. return ''
  45. }
  46. return decodeHtmlEntities(props.glyph)
  47. })
  48. const decodedTextGlyphIsHtml = computed(() => glyphLooksLikeHtml(decodedTextGlyph.value))
  49. </script>
  50. <style scoped>
  51. .action-icon-glyph {
  52. display: inline-flex;
  53. vertical-align: middle;
  54. align-items: center;
  55. justify-content: center;
  56. }
  57. .action-icon-glyph-svg {
  58. vertical-align: middle;
  59. }
  60. </style>