docs: complete handbook and prepare component verification tasks

This commit is contained in:
maoyingjie
2026-10-27 21:46:42 +08:00
parent 4da00943f1
commit 26df6e88a2
32 changed files with 2207 additions and 39 deletions
+47
View File
@@ -0,0 +1,47 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Button,
Spinner,
Skeleton,
Popover,
PopoverContent,
PopoverDialog,
PopoverHeading,
} from "@heroui-vue/components";
const reduced = ref(false);
const target = ref<HTMLElement>();
</script>
<template>
<section
ref="target"
:data-reduce-motion="reduced ? 'true' : undefined"
class="motion-demo"
>
<label>
<input v-model="reduced" type="checkbox" />
减少动态效果
</label>
<div class="flex items-center gap-4">
<Spinner aria-label="加载中" />
<Skeleton class="h-6 w-32" />
<Button>点按动画</Button>
</div>
<Popover>
<Button>查看进出场动画</Button>
<PopoverContent :to="target">
<PopoverDialog>
<PopoverHeading>动画与卸载</PopoverHeading>
<p>关闭时保留退出阶段;减少动态效果时禁用装饰动画。</p>
</PopoverDialog>
</PopoverContent>
</Popover>
</section>
</template>
<style scoped>
.motion-demo {
width: 100%;
display: grid;
gap: 20px;
}
</style>
+28
View File
@@ -0,0 +1,28 @@
<script setup lang="ts">
import { ref } from "vue";
import { Button, Link, buttonVariants } from "@heroui-vue/components";
import { tv } from "@heroui-vue/styles";
const count = ref(0);
const customButton = tv({
extend: buttonVariants,
variants: { emphasis: { strong: "font-bold" } },
});
</script>
<template>
<div class="flex flex-wrap items-center gap-3">
<a href="#自定义变体" :class="buttonVariants({ variant: 'secondary' })">
链接采用按钮外观
</a>
<Button
as-child
v-slot="{ isPressed }"
:class="customButton({ emphasis: 'strong' })"
@click="count++"
>
<button type="button" :data-custom-state="isPressed ? 'pressed' : 'idle'">
自定义根节点 · {{ count }}
</button>
</Button>
<Link href="/components/button">查看 Button API</Link>
</div>
</template>
+52
View File
@@ -0,0 +1,52 @@
<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>
+33
View File
@@ -0,0 +1,33 @@
<script setup lang="ts">
import { ref } from "vue";
import { Button } from "@heroui-vue/components";
const pending = ref(false);
</script>
<template>
<div class="flex flex-wrap items-center gap-3">
<Button as-child v-slot="{ isPressed, isHovered, isFocusVisible }">
<button class="handbook-state-button">
{{
isPressed
? "按下中"
: isHovered
? "悬停中"
: isFocusVisible
? "键盘焦点"
: "与我交互"
}}
</button>
</Button>
<Button is-disabled>禁用</Button>
<Button :is-pending="pending">{{ pending ? "加载中" : "正常操作" }}</Button>
<label>
<input v-model="pending" type="checkbox" />
加载状态
</label>
</div>
</template>
<style scoped>
.handbook-state-button[data-pressed="true"] {
outline: 2px solid var(--focus);
}
</style>
+72
View File
@@ -0,0 +1,72 @@
<script setup lang="ts">
import { ref } from "vue";
import {
Button,
Card,
Input,
Popover,
PopoverContent,
PopoverDialog,
PopoverHeading,
} from "@heroui-vue/components";
const theme = ref("light");
const target = ref<HTMLElement>();
</script>
<template>
<div class="handbook-theme-demo">
<label>
预览主题
<select v-model="theme">
<option value="light">浅色</option>
<option value="dark">深色</option>
</select>
</label>
<section
ref="target"
:class="theme"
class="theme-preview"
data-theme="ocean"
>
<Card>
<strong>自定义主题</strong>
<p>组件通过同一组语义变量更新外观。</p>
</Card>
<Input aria-label="主题预览邮箱" placeholder="输入你的邮箱" />
<Popover>
<Button>打开主题弹层</Button>
<PopoverContent :to="target">
<PopoverDialog>
<PopoverHeading>同一主题容器</PopoverHeading>
<p>to 指向局部容器,保留 CSS 变量继承。</p>
</PopoverDialog>
</PopoverContent>
</Popover>
</section>
</div>
</template>
<style scoped>
.handbook-theme-demo {
width: 100%;
display: grid;
gap: 16px;
}
.theme-preview {
display: grid;
gap: 16px;
padding: 20px;
border-radius: 16px;
background: var(--background);
color: var(--foreground);
}
[data-theme="ocean"] {
--accent: oklch(0.62 0.2 253.83);
--accent-foreground: var(--snow);
}
select {
background: var(--field-background);
color: var(--field-foreground);
border: 1px solid var(--border);
border-radius: 6px;
padding: 4px 8px;
}
</style>