37 lines
1.4 KiB
Vue
37 lines
1.4 KiB
Vue
<script setup lang="ts">
|
|
import type { DropdownItem } from '~/types/dropdown'
|
|
|
|
type Theme = 'light' | 'dark' | 'system'
|
|
|
|
const colorMode = useColorMode()
|
|
|
|
const themeOptions: DropdownItem[] = [
|
|
{ value: 'light', label: 'Light', icon: 'mynaui:sun' },
|
|
{ value: 'dark', label: 'Dark', icon: 'mynaui:moon' },
|
|
{ value: 'system', label: 'System', icon: 'mynaui:desktop' }
|
|
]
|
|
|
|
const currentOption = computed(() =>
|
|
themeOptions.find(option => option.value === colorMode.preference) || themeOptions[2]
|
|
)
|
|
|
|
const isOpen = ref(false)
|
|
|
|
const selectTheme = (item: DropdownItem) => {
|
|
colorMode.preference = item.value as Theme
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<Dropdown class="relative" v-model="isOpen" @select="selectTheme" :items="themeOptions" verticality="asscending"
|
|
placement="right" width="140px">
|
|
<template #trigger="{ toggle, isOpen }">
|
|
<button aria-label="Open theme switcher" @click="toggle"
|
|
class="p-2 flex items-center justify-center rounded-lg hover:bg-[var(--color-highlight)] transition-colors group"
|
|
:class="isOpen ? 'bg-[var(--color-highlight)]' : 'bg-transparent'">
|
|
<Icon :name="currentOption!.icon!"
|
|
class="text-5 text-[var(--color-subtle)] group-hover:text-[var(--color-text)] transition-colors" />
|
|
</button>
|
|
</template>
|
|
</Dropdown>
|
|
</template> |