docs(Header): display color mode button

This commit is contained in:
Benjamin Canac
2024-10-02 15:33:28 +02:00
parent 077a9210db
commit 0986f5e4b7
2 changed files with 39 additions and 1 deletions

View File

@@ -32,7 +32,7 @@ const navigation = inject<Ref<NavItem[]>>('navigation')
<UContentSearchButton />
</UTooltip>
<!-- <UColorModeButton /> -->
<ColorModeButton />
<UButton
color="gray"

View File

@@ -0,0 +1,38 @@
<template>
<ClientOnly v-if="!colorMode?.forced">
<UButton
:icon="isDark ? appConfig.ui.icons.dark : appConfig.ui.icons.light"
color="gray"
variant="ghost"
v-bind="{
...$attrs
}"
:aria-label="`Switch to ${isDark ? 'light' : 'dark'} mode`"
@click="isDark = !isDark"
/>
<template #fallback>
<div class="w-8 h-8" />
</template>
</ClientOnly>
</template>
<script setup lang="ts">
defineOptions({
inheritAttrs: false
})
const colorMode = useColorMode()
const appConfig = useAppConfig()
// Computed
const isDark = computed({
get() {
return colorMode.value === 'dark'
},
set() {
colorMode.preference = colorMode.value === 'dark' ? 'light' : 'dark'
}
})
</script>