Skip to content

Commit

Permalink
fix: add type for unknown appConfig (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
devTeaa authored Oct 25, 2023
1 parent b853088 commit 7d9bcf3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/runtime/Icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import { ref, computed, watch } from 'vue'
import { useAppConfig, useNuxtApp, useState } from '#imports'
const nuxtApp = useNuxtApp()
const appConfig = useAppConfig()
const appConfig = useAppConfig() as {
nuxtIcon: {
size?: string
class?: string
aliases?: Record<string, string>
}
}
const props = defineProps({
name: {
Expand All @@ -22,7 +28,13 @@ const props = defineProps({
const state = useState<Record<string, IconifyIcon | undefined>>('icons', () => ({}))
const isFetching = ref(false)
const iconName = computed(() => ((appConfig.nuxtIcon?.aliases || {})[props.name] || props.name).replace(/^i-/, ''))
const iconName = computed(() => {
if (appConfig.nuxtIcon.aliases && appConfig.nuxtIcon.aliases[props.name]) {
return appConfig.nuxtIcon.aliases[props.name].replace(/^i-/, '')
}
return props.name.replace(/^i-/, '')
})
const icon = computed<IconifyIcon | undefined>(() => state.value?.[iconName.value])
const component = computed(() => nuxtApp.vueApp.component(iconName.value as string))
const sSize = computed(() => {
Expand Down
16 changes: 14 additions & 2 deletions src/runtime/IconCSS.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
import { computed } from 'vue'
import { useAppConfig } from '#imports'
const appConfig = useAppConfig()
const appConfig = useAppConfig() as {
nuxtIcon: {
size?: string
class?: string
aliases?: Record<string, string>
}
}
const props = defineProps({
name: {
Expand All @@ -15,7 +21,13 @@ const props = defineProps({
}
})
const iconName = computed(() => ((appConfig.nuxtIcon?.aliases || {})[props.name] || props.name).replace(/^i-/, ''))
const iconName = computed(() => {
if (appConfig.nuxtIcon.aliases && appConfig.nuxtIcon.aliases[props.name]) {
return appConfig.nuxtIcon.aliases[props.name].replace(/^i-/, '')
}
return props.name.replace(/^i-/, '')
})
const iconUrl = computed(() => `url('https://api.iconify.design/${iconName.value.replace(':', '/')}.svg')`)
const sSize = computed(() => {
// Disable size if appConfig.nuxtIcon.size === false
Expand Down

0 comments on commit 7d9bcf3

Please sign in to comment.