feat: 主题改为弹出菜单选择
This commit is contained in:
@@ -1,32 +1,47 @@
|
||||
<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">
|
||||
<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">
|
||||
<rect x="3" y="4" width="18" height="12" rx="1.5" />
|
||||
<path d="M8 20h8M12 16v4" />
|
||||
</svg>
|
||||
<svg v-else-if="themeChoice === 'dark'" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8">
|
||||
<path d="M16 3.2A8.5 8.5 0 1 0 20.8 14 7 7 0 0 1 16 3.2z" />
|
||||
</svg>
|
||||
<svg v-else viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8">
|
||||
<circle cx="12" cy="12" r="4" />
|
||||
<path d="M12 2.5v2.2M12 19.3v2.2M2.5 12h2.2M19.3 12h2.2M5 5l1.6 1.6M17.4 17.4 19 19M19 5l-1.6 1.6M6.6 17.4 5 19" />
|
||||
</svg>
|
||||
</n-icon>
|
||||
</template>
|
||||
</n-button>
|
||||
</template>
|
||||
{{ label[themeChoice] }}
|
||||
</n-tooltip>
|
||||
<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">
|
||||
<rect x="3" y="4" width="18" height="12" rx="1.5" />
|
||||
<path d="M8 20h8M12 16v4" />
|
||||
</svg>
|
||||
<svg v-else-if="themeChoice === 'dark'" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8">
|
||||
<path d="M16 3.2A8.5 8.5 0 1 0 20.8 14 7 7 0 0 1 16 3.2z" />
|
||||
</svg>
|
||||
<svg v-else viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8">
|
||||
<circle cx="12" cy="12" r="4" />
|
||||
<path d="M12 2.5v2.2M12 19.3v2.2M2.5 12h2.2M19.3 12h2.2M5 5l1.6 1.6M17.4 17.4 19 19M19 5l-1.6 1.6M6.6 17.4 5 19" />
|
||||
</svg>
|
||||
</n-icon>
|
||||
</template>
|
||||
</n-button>
|
||||
</n-popselect>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user