| 1 |
<script lang="ts" setup> |
| 2 |
import { computed } from "vue"; |
| 3 |
import type { Color } from "@/types"; |
| 4 |
import type { IconUnion } from "@/types/enums/iconModels"; |
| 5 |
import { wrapInCssVar } from "@/utils/helpers"; |
| 6 |
import { defineAsyncComponent } from "vue"; |
| 7 |
import { toTitleCase } from "@/utils/helpers"; |
| 8 |
import { kebabToCamel } from "@/utils/services/snakeCamelService"; |
| 9 |
|
| 10 |
interface Props { |
| 11 |
dimensions?: number; |
| 12 |
color?: Color; |
| 13 |
name: IconUnion; |
| 14 |
} |
| 15 |
|
| 16 |
const props = withDefaults(defineProps<Props>(), { |
| 17 |
dimensions: 24, |
| 18 |
color: "white", |
| 19 |
}); |
| 20 |
|
| 21 |
const iconColor = computed(() => { |
| 22 |
if (!props.color) return ""; |
| 23 |
|
| 24 |
return wrapInCssVar(props.color); |
| 25 |
}); |
| 26 |
|
| 27 |
const selectedIcon = computed(() => { |
| 28 |
return defineAsyncComponent( |
| 29 |
() => |
| 30 |
import( |
| 31 |
`@/components/Icon/Icons/${kebabToCamel(toTitleCase(props.name))}.vue` |
| 32 |
) |
| 33 |
); |
| 34 |
}); |
| 35 |
</script> |
| 36 |
|
| 37 |
<template> |
| 38 |
<svg class="icon" aria-hidden="true">> |
| 39 |
<g> |
| 40 |
<Component :is="selectedIcon" /> |
| 41 |
</g> |
| 42 |
</svg> |
| 43 |
</template> |
| 44 |
|
| 45 |
<style lang="scss" scoped> |
| 46 |
.icon { |
| 47 |
transition: 0.3s ease transform; |
| 48 |
fill: currentColor; |
| 49 |
color: v-bind(iconColor); |
| 50 |
width: v-bind("dimensions + 'px'"); |
| 51 |
height: v-bind("dimensions + 'px'"); |
| 52 |
min-width: v-bind("dimensions + 'px'"); |
| 53 |
} |
| 54 |
</style> |
| 55 |
|