mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-21 23:40:39 +01:00
docs(Header): display color mode button
This commit is contained in:
@@ -32,7 +32,7 @@ const navigation = inject<Ref<NavItem[]>>('navigation')
|
||||
<UContentSearchButton />
|
||||
</UTooltip>
|
||||
|
||||
<!-- <UColorModeButton /> -->
|
||||
<ColorModeButton />
|
||||
|
||||
<UButton
|
||||
color="gray"
|
||||
|
||||
38
docs/app/components/color-mode/ColorModeButton.vue
Normal file
38
docs/app/components/color-mode/ColorModeButton.vue
Normal 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>
|
||||
Reference in New Issue
Block a user