|
1 | | -<script lang="ts"> |
2 | | -import type { IconProps as NuxtIconProps } from '../../types' |
3 | | -
|
4 | | -export interface IconProps { |
5 | | - name: NuxtIconProps['name'] |
6 | | -} |
7 | | -</script> |
8 | | - |
9 | 1 | <script setup lang="ts"> |
| 2 | +import type { IconProps } from '../../types' |
| 3 | +import type { IconifyRenderMode } from '@iconify/vue' |
| 4 | +import { computed } from 'vue' |
10 | 5 | import { Icon as IconifyIcon } from '@iconify/vue' |
| 6 | +import { useAppConfig } from '#imports' |
| 7 | +import type { RuntimeOptions } from '@nuxt/icon' |
| 8 | +
|
| 9 | +const props = defineProps<IconProps>() |
| 10 | +
|
| 11 | +const appConfig = useAppConfig() |
| 12 | +
|
| 13 | +function resolveCustomizeFn( |
| 14 | + customize: RuntimeOptions['customize'] | boolean | null | undefined, |
| 15 | + globalCustomize: RuntimeOptions['customize'] | undefined |
| 16 | +): RuntimeOptions['customize'] | undefined { |
| 17 | + if (customize === false) return undefined |
| 18 | + if (customize === true || customize === null) return globalCustomize |
| 19 | + return customize |
| 20 | +} |
11 | 21 |
|
12 | | -defineProps<IconProps>() |
| 22 | +const resolvedMode = computed(() => { |
| 23 | + const mode = props.mode || appConfig.icon?.mode |
| 24 | + if (mode === 'css') return 'style' |
| 25 | + return mode as IconifyRenderMode |
| 26 | +}) |
13 | 27 | </script> |
14 | 28 |
|
15 | 29 | <template> |
16 | | - <IconifyIcon v-if="typeof name === 'string'" :icon="name.replace(/^i-/, '')" /> |
| 30 | + <IconifyIcon |
| 31 | + v-if="typeof name === 'string'" |
| 32 | + :icon="name.replace(/^i-/, '')" |
| 33 | + :mode="resolvedMode" |
| 34 | + :width="size || appConfig.icon?.size" |
| 35 | + :height="size || appConfig.icon?.size" |
| 36 | + :customise="resolveCustomizeFn(props.customize, appConfig.icon?.customize)" |
| 37 | + /> |
17 | 38 | <component :is="name" v-else /> |
18 | 39 | </template> |
0 commit comments