forked from sugarforever/chat-ollama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorMode.vue
50 lines (44 loc) · 1.41 KB
/
ColorMode.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
<script setup lang="ts">
const { t } = useI18n()
const colorMode = useColorMode()
const icons = ['i-material-symbols-desktop-windows-outline-rounded', 'i-heroicons-sun-20-solid', 'i-heroicons-moon-20-solid']
const list = computed(() => {
return [
{ label: t('colorMode.system'), value: 'system', icon: icons[0] },
{ label: t('colorMode.light'), value: 'light', icon: icons[1] },
{ label: t('colorMode.dark'), value: 'dark', icon: icons[2] },
]
})
const currentIcon = ref(list.value[0].icon)
const items = computed(() => {
return list.value.map(item => {
return {
...item,
click: () => {
colorMode.preference = item.value
currentIcon.value = item.icon
}
}
})
})
onMounted(() => {
currentIcon.value = list.value.find(el => el.value === colorMode.preference)?.icon || ''
})
</script>
<template>
<UDropdown :items="[items]"
:ui="{ width: 'w-32' }"
:popper="{ placement: 'bottom-start' }">
<UButton :icon="currentIcon"
color="gray"
variant="ghost"
aria-label="Theme"
@touchstart.stop />
<template #item="{ item }">
<div class="flex items-center" :class="{ 'text-primary-500': item.value === colorMode.preference }">
<UIcon :name="item.icon" class="opacity-70 text-lg" />
<span class="ml-2">{{ item.label }}</span>
</div>
</template>
</UDropdown>
</template>