91 lines
2.4 KiB
Vue
91 lines
2.4 KiB
Vue
<script setup lang="ts">
|
|
import { useColorMode } from "@vueuse/core";
|
|
import {
|
|
Button,
|
|
Popover,
|
|
PopoverTrigger,
|
|
PopoverContent,
|
|
PopoverDialog,
|
|
PopoverHeading,
|
|
ToggleButtonGroup,
|
|
ToggleButton,
|
|
} from "@heroui-vue/components";
|
|
import { IconSun, IconMoon, IconDeviceDesktop } from "@tabler/icons-vue";
|
|
const mode = useColorMode({
|
|
storageKey: "vitepress-theme-appearance",
|
|
emitAuto: true,
|
|
});
|
|
const choices = [
|
|
{ id: "light", label: "浅色主题", icon: IconSun },
|
|
{ id: "dark", label: "深色主题", icon: IconMoon },
|
|
{ id: "auto", label: "跟随系统", icon: IconDeviceDesktop },
|
|
] as const;
|
|
function setTheme(value: unknown) {
|
|
if (value === "light" || value === "dark" || value === "auto")
|
|
mode.value = value;
|
|
}
|
|
</script>
|
|
<template>
|
|
<ToggleButtonGroup
|
|
class="docs-theme-wide"
|
|
is-detached
|
|
:model-value="mode"
|
|
selection-mode="single"
|
|
disallow-empty-selection
|
|
aria-label="外观"
|
|
size="sm"
|
|
@update:model-value="setTheme"
|
|
>
|
|
<ToggleButton
|
|
v-for="choice in choices"
|
|
:id="choice.id"
|
|
:key="choice.id"
|
|
is-icon-only
|
|
variant="ghost"
|
|
:aria-label="choice.label"
|
|
>
|
|
<component :is="choice.icon" aria-hidden="true" :size="15" />
|
|
</ToggleButton>
|
|
</ToggleButtonGroup>
|
|
<Popover>
|
|
<PopoverTrigger as-child>
|
|
<Button
|
|
class="docs-theme-compact"
|
|
variant="ghost"
|
|
is-icon-only
|
|
size="sm"
|
|
aria-label="选择外观"
|
|
>
|
|
<IconSun v-if="mode === 'light'" :size="18" />
|
|
<IconMoon v-else-if="mode === 'dark'" :size="18" />
|
|
<IconDeviceDesktop v-else :size="18" />
|
|
</Button>
|
|
</PopoverTrigger>
|
|
<PopoverContent placement="bottom end">
|
|
<PopoverDialog>
|
|
<PopoverHeading class="sr-only">外观</PopoverHeading>
|
|
<ToggleButtonGroup
|
|
is-detached
|
|
:model-value="mode"
|
|
selection-mode="single"
|
|
disallow-empty-selection
|
|
aria-label="外观"
|
|
size="sm"
|
|
@update:model-value="setTheme"
|
|
>
|
|
<ToggleButton
|
|
v-for="choice in choices"
|
|
:id="choice.id"
|
|
:key="choice.id"
|
|
is-icon-only
|
|
variant="ghost"
|
|
:aria-label="choice.label"
|
|
>
|
|
<component :is="choice.icon" aria-hidden="true" :size="16" />
|
|
</ToggleButton>
|
|
</ToggleButtonGroup>
|
|
</PopoverDialog>
|
|
</PopoverContent>
|
|
</Popover>
|
|
</template>
|