feat: 主题改为弹出菜单选择
This commit is contained in:
@@ -1,15 +1,32 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { NButton, NIcon, NTooltip } from "naive-ui";
|
import { NButton, NIcon, NPopselect } from "naive-ui";
|
||||||
import { cycleTheme, themeChoice } from "../shared/theme";
|
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 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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<n-tooltip :placement="placement">
|
<n-popselect
|
||||||
<template #trigger>
|
:value="themeChoice"
|
||||||
<n-button class="theme-switch" quaternary circle :aria-label="label[themeChoice]" @click="cycleTheme">
|
: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>
|
<template #icon>
|
||||||
<n-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">
|
<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>
|
</n-icon>
|
||||||
</template>
|
</template>
|
||||||
</n-button>
|
</n-button>
|
||||||
</template>
|
</n-popselect>
|
||||||
{{ label[themeChoice] }}
|
|
||||||
</n-tooltip>
|
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user