-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
/
IconList.vue
93 lines (84 loc) 路 2.09 KB
/
IconList.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<template>
<v-autocomplete
v-model="selection"
v-model:search="search"
:item-props="itemProps"
:items="filteredIcons"
:placeholder="t('search.icons')"
item-title="name"
item-value="name"
variant="outlined"
no-filter
>
<template #prepend-inner>
<v-expand-x-transition>
<v-icon v-if="selection" start>
{{ getIcon(selection) }}
</v-icon>
</v-expand-x-transition>
<code class="me-n1">mdi-</code>
</template>
<template #item="{ props, item }">
<v-list-item v-bind="props">
<template #append>
<v-btn
icon="mdi-content-copy"
size="small"
variant="plain"
@click.stop="copy(item.raw.name)"
/>
</template>
</v-list-item>
</template>
<template #append-inner>
<v-expand-x-transition>
<span v-if="copied" class="text-primary pt-1">
{{ t('copied') }}
</span>
</v-expand-x-transition>
</template>
</v-autocomplete>
</template>
<script setup>
// Data
import icons from '@mdi/svg/meta.json'
import * as paths from '@mdi/js'
const { t } = useI18n()
const copied = shallowRef(false)
const selection = shallowRef()
const search = shallowRef('')
const filteredIcons = computed(() => {
if (!search.value) return icons
return icons
.map(icon => ({
name: icon.name,
distance: Math.max(
distance(search.value, icon.name),
...icon.aliases.map(v => distance(search.value, v))
),
}))
.filter(v => v.distance > 0.7)
.sort((a, b) => {
return b.distance - a.distance
})
})
watch(selection, value => {
value && copy(value)
})
function getIcon (name) {
return 'svg:' + paths[camelize('mdi-' + name)]
}
function itemProps (item) {
return {
prependIcon: getIcon(item.name),
}
}
function copy (item) {
navigator.clipboard.writeText('mdi-' + item).then(() => {
copied.value = true
setTimeout(() => {
copied.value = false
}, 2000)
})
}
</script>