mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-19 14:31:47 +01:00
@@ -17,6 +17,7 @@ import { ref, computed, useSlots } from 'vue'
|
||||
import type { PropType } from 'vue'
|
||||
import type { RouteLocationNormalized } from 'vue-router'
|
||||
import NuxtLink from '#app/components/nuxt-link'
|
||||
import Icon from '../elements/Icon.vue'
|
||||
import { classNames } from '../../utils'
|
||||
import $ui from '#build/ui'
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ import type { Ref, PropType } from 'vue'
|
||||
import type { RouteLocationNormalized } from 'vue-router'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import NuxtLink from '#app/components/nuxt-link'
|
||||
import Icon from '../elements/Icon.vue'
|
||||
import Avatar from '../elements/Avatar.vue'
|
||||
import { classNames, usePopper } from '../../utils'
|
||||
import type { Avatar as AvatarType } from '../../types/avatar'
|
||||
|
||||
40
src/runtime/components/elements/Icon.vue
Normal file
40
src/runtime/components/elements/Icon.vue
Normal file
@@ -0,0 +1,40 @@
|
||||
<template>
|
||||
<span v-if="isFetching" />
|
||||
<Iconify v-else-if="icon" :icon="icon" />
|
||||
<Component :is="component" v-else-if="component" />
|
||||
<span v-else>{{ name }}</span>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { IconifyIcon } from '@iconify/vue'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { Icon as Iconify } from '@iconify/vue/dist/offline'
|
||||
import { loadIcon } from '@iconify/vue'
|
||||
import { useNuxtApp, useState } from '#imports'
|
||||
|
||||
const props = defineProps({
|
||||
name: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
})
|
||||
const nuxtApp = useNuxtApp()
|
||||
const state = useState('u-icons', () => ({}))
|
||||
const isFetching = ref(false)
|
||||
const icon = computed<IconifyIcon | null>(() => state.value?.[props.name])
|
||||
const component = computed(() => nuxtApp.vueApp.component(props.name))
|
||||
const loadIconComponent = async () => {
|
||||
if (component.value) { return }
|
||||
if (!state.value?.[props.name]) {
|
||||
isFetching.value = true
|
||||
state.value[props.name] = await loadIcon(props.name).catch(() => null)
|
||||
isFetching.value = false
|
||||
}
|
||||
}
|
||||
watch(() => props.name, loadIconComponent)
|
||||
!component.value && (await loadIconComponent())
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { name: 'UIcon' }
|
||||
</script>
|
||||
@@ -27,6 +27,7 @@
|
||||
import { computed } from 'vue'
|
||||
import type { PropType } from 'vue'
|
||||
import type { RouteLocationNormalized } from 'vue-router'
|
||||
import Icon from '../elements/Icon.vue'
|
||||
|
||||
const props = defineProps({
|
||||
variant: {
|
||||
|
||||
@@ -25,6 +25,7 @@ import { computed } from 'vue'
|
||||
import { DialogTitle, DialogDescription } from '@headlessui/vue'
|
||||
import Modal from '../overlays/Modal.vue'
|
||||
import Button from '../elements/Button.vue'
|
||||
import Icon from '../elements/Icon.vue'
|
||||
import $ui from '#build/ui'
|
||||
|
||||
const props = defineProps({
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
<script setup lang="ts">
|
||||
import type { Ref } from 'vue'
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import Icon from '../elements/Icon.vue'
|
||||
import { classNames } from '../../utils'
|
||||
import $ui from '#build/ui'
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { get } from 'lodash-es'
|
||||
import Icon from '../elements/Icon.vue'
|
||||
import { classNames } from '../../utils'
|
||||
import $ui from '#build/ui'
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ import {
|
||||
ComboboxOption,
|
||||
ComboboxInput
|
||||
} from '@headlessui/vue'
|
||||
import Icon from '../elements/Icon.vue'
|
||||
import { classNames, usePopper } from '../../utils'
|
||||
import $ui from '#build/ui'
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { Switch } from '@headlessui/vue'
|
||||
import Icon from '../elements/Icon.vue'
|
||||
import $ui from '#build/ui'
|
||||
|
||||
const props = defineProps({
|
||||
|
||||
@@ -46,6 +46,7 @@ import { useFuse } from '@vueuse/integrations/useFuse'
|
||||
import { defu } from 'defu'
|
||||
import type { UseFuseOptions } from '@vueuse/integrations/useFuse'
|
||||
import type { Group, Command } from '../../types/command-palette'
|
||||
import Icon from '../elements/Icon.vue'
|
||||
import Button from '../elements/Button.vue'
|
||||
import CommandPaletteGroup from './CommandPaletteGroup.vue'
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ComboboxOption } from '@headlessui/vue'
|
||||
import type { PropType } from 'vue'
|
||||
import Icon from '../elements/Icon.vue'
|
||||
import Avatar from '../elements/Avatar.vue'
|
||||
import type { Group } from '../../types/command-palette'
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { PropType } from 'vue'
|
||||
import Icon from '../elements/Icon.vue'
|
||||
import Link from '../elements/Link.vue'
|
||||
import Avatar from '../elements/Avatar.vue'
|
||||
import type { Avatar as AvatarType } from '../../types/avatar'
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, onUnmounted, watchEffect } from 'vue'
|
||||
import type { PropType } from 'vue'
|
||||
import Icon from '../elements/Icon.vue'
|
||||
import { useTimer } from '../../composables/useTimer'
|
||||
import { classNames } from '../../utils'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user