Skip to content

Commit

Permalink
feat: support i- prefix (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux authored Aug 7, 2023
1 parent 9579404 commit 708b30a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ You can use any name from the https://icones.js.org collection:
<Icon name="uil:github" />
```

It supports the `i-` prefix (for example `i-uil-github`).

### Emoji

```html
Expand Down
6 changes: 4 additions & 2 deletions playground/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
</p>
<p>
CSS:
<IconCSS name="uil:github" />
<IconCSS name="i-uil-github" />
<IconCSS name="uil:github" size="24" />
<IconCSS name="uil:github" size="48" />
<IconCSS name="nuxt" size="48" style="color: #00DC82;" />
</p>
<p>
Failing:
<Icon name="uil:bad">☀️</Icon>
<Icon name="uil:bad">
☀️
</Icon>
<Icon name="uil:bad" />
</p>
</div>
Expand Down
8 changes: 2 additions & 6 deletions src/runtime/Icon.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<!-- eslint-disable vue/multi-word-component-names -->
<script setup lang="ts">
import type { PropType } from 'vue'
import type { IconifyIcon } from '@iconify/vue'
import { Icon as Iconify } from '@iconify/vue/dist/offline'
import { loadIcon } from '@iconify/vue'
Expand All @@ -9,13 +8,10 @@ import { useAppConfig, useNuxtApp, useState } from '#imports'
const nuxtApp = useNuxtApp()
const appConfig = useAppConfig()
const aliases = appConfig?.nuxtIcon?.aliases || {}
type AliasesKeys = keyof typeof aliases
const props = defineProps({
name: {
type: String as PropType<AliasesKeys | (string & {})>,
type: String,
required: true
},
size: {
Expand All @@ -26,7 +22,7 @@ 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)
const iconName = computed(() => ((appConfig.nuxtIcon?.aliases || {})[props.name] || 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
8 changes: 2 additions & 6 deletions src/runtime/IconCSS.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<script setup lang="ts">
import type { PropType } from 'vue'
import { computed } from 'vue'
import { useAppConfig } from '#imports'
const appConfig = useAppConfig()
const aliases = appConfig?.nuxtIcon?.aliases || {}
type AliasesKeys = keyof typeof aliases
const props = defineProps({
name: {
type: String as PropType<AliasesKeys | (string & {})>,
type: String,
required: true
},
size: {
Expand All @@ -19,7 +15,7 @@ const props = defineProps({
}
})
const iconName = computed(() => ((appConfig as any)?.nuxtIcon?.aliases || {})[props.name] || props.name)
const iconName = computed(() => ((appConfig.nuxtIcon?.aliases || {})[props.name] || 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 708b30a

Please sign in to comment.