feat: 主题改为弹出菜单选择
This commit is contained in:
@@ -1,32 +1,47 @@
|
|||||||
<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"
|
||||||
<template #icon>
|
trigger="click"
|
||||||
<n-icon>
|
:placement="placement"
|
||||||
<svg v-if="themeChoice === 'system'" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8">
|
@update:value="pick"
|
||||||
<rect x="3" y="4" width="18" height="12" rx="1.5" />
|
>
|
||||||
<path d="M8 20h8M12 16v4" />
|
<n-button class="theme-switch" quaternary circle :aria-label="label[themeChoice]" aria-haspopup="listbox">
|
||||||
</svg>
|
<template #icon>
|
||||||
<svg v-else-if="themeChoice === 'dark'" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8">
|
<n-icon>
|
||||||
<path d="M16 3.2A8.5 8.5 0 1 0 20.8 14 7 7 0 0 1 16 3.2z" />
|
<svg v-if="themeChoice === 'system'" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8">
|
||||||
</svg>
|
<rect x="3" y="4" width="18" height="12" rx="1.5" />
|
||||||
<svg v-else viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8">
|
<path d="M8 20h8M12 16v4" />
|
||||||
<circle cx="12" cy="12" r="4" />
|
</svg>
|
||||||
<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 v-else-if="themeChoice === 'dark'" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8">
|
||||||
</svg>
|
<path d="M16 3.2A8.5 8.5 0 1 0 20.8 14 7 7 0 0 1 16 3.2z" />
|
||||||
</n-icon>
|
</svg>
|
||||||
</template>
|
<svg v-else viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8">
|
||||||
</n-button>
|
<circle cx="12" cy="12" r="4" />
|
||||||
</template>
|
<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" />
|
||||||
{{ label[themeChoice] }}
|
</svg>
|
||||||
</n-tooltip>
|
</n-icon>
|
||||||
|
</template>
|
||||||
|
</n-button>
|
||||||
|
</n-popselect>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user