Files
heroui-vue/apps/docs/demos/handbook-dark-mode.vue
T

53 lines
1.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { computed, ref } from "vue";
import { usePreferredDark } from "@vueuse/core";
import { Button, Card, Input } from "@heroui-vue/components";
const mode = ref("system");
const systemDark = usePreferredDark();
const resolved = computed(() =>
mode.value === "system" ? (systemDark.value ? "dark" : "light") : mode.value,
);
</script>
<template>
<div class="mode-demo">
<label>
外观
<select v-model="mode">
<option value="light">浅色</option>
<option value="dark">深色</option>
<option value="system">跟随系统</option>
</select>
</label>
<section :class="resolved" class="mode-preview">
<Card>
<strong>主题预览</strong>
<p>当前选择:{{ mode }};解析为:{{ resolved }}。</p>
</Card>
<Input aria-label="深色模式预览" placeholder="输入内容" />
<Button>继续</Button>
</section>
</div>
</template>
<style scoped>
.mode-demo {
width: 100%;
display: grid;
gap: 16px;
}
.mode-preview {
display: grid;
gap: 16px;
padding: 20px;
border-radius: 16px;
background: var(--background);
color: var(--foreground);
}
select {
padding: 4px 8px;
background: var(--field-background);
color: var(--field-foreground);
border: 1px solid var(--border);
border-radius: 6px;
}
</style>