feat: 主题改为弹出菜单选择
This commit is contained in:
@@ -1,15 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
import { NButton, NIcon, NTooltip } from "naive-ui";
|
||||
import { cycleTheme, themeChoice } from "../shared/theme";
|
||||
import { NButton, NIcon, NPopselect } from "naive-ui";
|
||||
import { setThemeChoice, themeChoice } from "../shared/theme";
|
||||
|
||||
withDefaults(defineProps<{
|
||||
placement?: "top" | "top-start" | "top-end" | "left" | "left-start" | "left-end" | "bottom" | "bottom-end" | "right";
|
||||
}>(), { placement: "top" });
|
||||
|
||||
withDefaults(defineProps<{ placement?: "top" | "left" | "bottom" | "right" }>(), { placement: "top" });
|
||||
const label = { system: "跟随系统", dark: "深色", light: "浅色" } as const;
|
||||
const options = [
|
||||
{ label: "跟随系统", value: "system" },
|
||||
{ label: "深色", value: "dark" },
|
||||
{ label: "浅色", value: "light" },
|
||||
];
|
||||
|
||||
function pick(value: string) {
|
||||
if (value === "system" || value === "dark" || value === "light") setThemeChoice(value);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<n-tooltip :placement="placement">
|
||||
<template #trigger>
|
||||
<n-button class="theme-switch" quaternary circle :aria-label="label[themeChoice]" @click="cycleTheme">
|
||||
<n-popselect
|
||||
:value="themeChoice"
|
||||
:options="options"
|
||||
trigger="click"
|
||||
:placement="placement"
|
||||
@update:value="pick"
|
||||
>
|
||||
<n-button class="theme-switch" quaternary circle :aria-label="label[themeChoice]" aria-haspopup="listbox">
|
||||
<template #icon>
|
||||
<n-icon>
|
||||
<svg v-if="themeChoice === 'system'" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8">
|
||||
@@ -26,7 +43,5 @@ const label = { system: "跟随系统", dark: "深色", light: "浅色" } as con
|
||||
</n-icon>
|
||||
</template>
|
||||
</n-button>
|
||||
</template>
|
||||
{{ label[themeChoice] }}
|
||||
</n-tooltip>
|
||||
</n-popselect>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user