feat: initialize Vue component library and aligned documentation

This commit is contained in:
maoyingjie
2026-10-21 09:06:28 +08:00
commit 9d40dc0ecb
149 changed files with 13208 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
import tailwindcss from "@tailwindcss/vite";
import { defineConfig } from "vitepress";
import { docsDataPlugin } from "./docs-data";
import { fileURLToPath } from "node:url";
export default defineConfig({
lang: "zh-CN",
title: "HeroUI Vue",
description: "美观、现代的 Vue UI 组件库",
appearance: true,
cleanUrls: true,
head: [["meta", { name: "theme-color", content: "#f5f5f5" }]],
markdown: { headers: { level: [2, 3] } },
vite: {
plugins: [
tailwindcss(),
{
name: "workspace-source-dev",
apply: "serve",
config: () => ({
resolve: {
alias: [
{
find: /^@heroui-vue\/components$/,
replacement: fileURLToPath(
new URL(
"../../../packages/vue/src/index.ts",
import.meta.url,
),
),
},
{
find: /^@heroui-vue\/styles\/css$/,
replacement: fileURLToPath(
new URL(
"../../../packages/styles/index.css",
import.meta.url,
),
),
},
{
find: /^@heroui-vue\/styles$/,
replacement: fileURLToPath(
new URL(
"../../../packages/styles/src/index.ts",
import.meta.url,
),
),
},
],
dedupe: ["vue"],
},
optimizeDeps: {
exclude: ["@heroui-vue/components", "@heroui-vue/styles"],
},
}),
},
docsDataPlugin(fileURLToPath(new URL("..", import.meta.url))),
],
server: {
host: "127.0.0.1",
port: 5173,
strictPort: true,
watch: { ignored: ["**/.vitepress/dist/**"] },
},
},
});
+118
View File
@@ -0,0 +1,118 @@
import { readFile, readdir } from "node:fs/promises";
import path from "node:path";
import { createMarkdownRenderer } from "vitepress";
import type { Plugin } from "vite";
// Build both highlights and the local search index from the actual documentation.
export function docsDataPlugin(root: string): Plugin {
const id = "\0virtual:docs-data";
let renderer: ReturnType<typeof createMarkdownRenderer>;
return {
name: "heroui-docs-data",
resolveId(source) {
if (source === "virtual:docs-data") return id;
if (/^virtual:docs-highlight\/[a-z0-9-]+$/.test(source))
return "\0" + source;
},
async load(source) {
if (source !== id && !source.startsWith("\0virtual:docs-highlight/"))
return;
renderer ??= createMarkdownRenderer(root, {
theme: { light: "github-light", dark: "github-dark" },
headers: { level: [2, 3] },
});
const md = await renderer;
if (source.startsWith("\0virtual:docs-highlight/")) {
const name = source.slice("\0virtual:docs-highlight/".length);
const file = path.join(root, "demos", name + ".vue");
this.addWatchFile(file);
return (
"export default " +
JSON.stringify(
md.render("```vue\n" + (await readFile(file, "utf8")) + "\n```"),
)
);
}
const highlights: string[] = [];
for (const name of await readdir(path.join(root, "demos"))) {
if (!name.endsWith(".vue")) continue;
const file = path.join(root, "demos", name);
this.addWatchFile(file);
const key = name.slice(0, -4);
highlights.push(
JSON.stringify(key) +
":()=>import(" +
JSON.stringify("virtual:docs-highlight/" + key) +
")",
);
}
const pages = [
"introduction.md",
"guide.md",
"themes.md",
...(await readdir(path.join(root, "components")))
.filter((f) => f.endsWith(".md"))
.map((f) => "components/" + f),
];
const search = [];
const plain = (value: string) =>
value
.replace(/^[| :\-]+$/gm, " ")
.replace(/<[^>]*>/g, " ")
.replace(/[`*#|]/g, " ")
.replace(/\s+/g, " ")
.trim();
for (const name of pages) {
const file = path.join(root, name);
this.addWatchFile(file);
const raw = await readFile(file, "utf8");
const title = raw.match(/^title:\s*(.+)$/m)?.[1] ?? name;
const description = raw.match(/^description:\s*(.+)$/m)?.[1] ?? "";
const url = "/" + name.slice(0, -3);
search.push({ title, section: "概览", url, text: description });
const content = raw.replace(/^---[\s\S]*?---/, "");
// The rendered IDs come from the same Markdown renderer as the real pages.
const env: {
headers?: { title: string; slug: string; children?: unknown[] }[];
} = {};
const rendered = md.render(content, env);
const headings = [
...rendered.matchAll(
/<h([23]) id="([^"]+)"[^>]*>([\s\S]*?)<\/h[23]>/g,
),
];
const chunks = content.split(/^#{2,3}\s+.+$/m).slice(1);
headings.forEach((h, i) =>
search.push({
title,
section: plain(h[3].replace(/<a[\s\S]*?<\/a>/g, "")),
url: url + "#" + h[2],
text: plain(chunks[i] ?? "").slice(0, 2000),
}),
);
}
return (
"export const highlights=" +
"{" +
highlights.join(",") +
"}" +
";export const searchIndex=" +
JSON.stringify(search) +
";"
);
},
handleHotUpdate(ctx) {
if (/\.(md|vue)$/.test(ctx.file)) {
const mod = ctx.server.moduleGraph.getModuleById(id);
if (mod) {
ctx.server.moduleGraph.invalidateModule(mod);
for (const [key, highlight] of ctx.server.moduleGraph.idToModuleMap) {
if (key.startsWith("\0virtual:docs-highlight/"))
ctx.server.moduleGraph.invalidateModule(highlight);
}
ctx.server.ws.send({ type: "full-reload" });
}
}
},
};
}
+4
View File
@@ -0,0 +1,4 @@
declare module "virtual:docs-data" {
export const highlights: Record<string, () => Promise<{ default: string }>>;
export const searchIndex: import("./theme/search").SearchEntry[];
}
+103
View File
@@ -0,0 +1,103 @@
<script setup lang="ts">
import { IconCode, IconCopy } from "@tabler/icons-vue";
import { computed, ref, watch, onBeforeUnmount, useId } from "vue";
import { highlights } from "virtual:docs-data";
const props = defineProps<{ name: string }>();
const demos = import.meta.glob("../../demos/*.vue", {
eager: true,
import: "default",
});
const sources = import.meta.glob("../../demos/*.vue", {
eager: true,
query: "?raw",
import: "default",
});
const component = computed(() => demos[`../../demos/${props.name}.vue`]);
const code = computed(() =>
String(sources[`../../demos/${props.name}.vue`] ?? ""),
);
const expanded = ref(false),
copyStatus = ref("复制代码");
const id = useId();
const highlightedCode = ref("");
watch([expanded, () => props.name], async ([open, name], _, onCleanup) => {
let current = true;
onCleanup(() => {
current = false;
});
highlightedCode.value = "";
if (open) {
try {
const result = await highlights[name]?.();
if (current) highlightedCode.value = result?.default ?? "";
} catch {
// The plain source remains available if a highlight chunk cannot load.
}
}
});
let timer: ReturnType<typeof setTimeout> | undefined;
async function copy() {
clearTimeout(timer);
try {
await navigator.clipboard.writeText(code.value);
copyStatus.value = "已复制";
timer = setTimeout(() => {
copyStatus.value = "复制代码";
}, 2000);
} catch {
expanded.value = true;
copyStatus.value = "复制失败,请手动选择代码";
}
}
onBeforeUnmount(() => clearTimeout(timer));
</script>
<template>
<div class="component-preview-container" :data-name="name">
<div class="preview not-prose">
<div class="demo-row">
<component :is="component" v-if="component" />
<p v-else role="alert">示例不存在:{{ name }}</p>
</div>
</div>
<div class="code-section">
<div class="code-toolbar">
<span class="code-language">
<span class="code-dot" aria-hidden="true" />
Vue
</span>
<div>
<button
:aria-label="(expanded ? '收起' : '展开') + name + ' 示例代码'"
:aria-controls="id"
:aria-expanded="expanded"
@click="expanded = !expanded"
>
<IconCode aria-hidden="true" :size="14" />
{{ expanded ? "收起代码" : "展开代码" }}
</button>
<button :aria-label="'复制' + name + ' 示例代码'" @click="copy">
<IconCopy aria-hidden="true" :size="14" />
复制代码
</button>
</div>
</div>
<p
class="copy-feedback"
:class="{ 'sr-only': copyStatus === '复制代码' }"
role="status"
>
{{ copyStatus === "复制代码" ? "" : copyStatus }}
</p>
<div
v-if="expanded"
:id="id"
class="highlighted-source"
tabindex="0"
:aria-label="name + ' 示例源码'"
>
<div v-if="highlightedCode" v-html="highlightedCode" />
<pre v-else><code>{{ code }}</code></pre>
</div>
</div>
</div>
</template>
+156
View File
@@ -0,0 +1,156 @@
<script setup lang="ts">
import { IconSearch } from "@tabler/icons-vue";
import {
computed,
ref,
watch,
onMounted,
onBeforeUnmount,
nextTick,
} from "vue";
import { withBase, useRouter } from "vitepress";
import {
DialogRoot,
DialogTrigger,
DialogPortal,
DialogOverlay,
DialogContent,
DialogTitle,
DialogDescription,
DialogClose,
} from "reka-ui";
import { searchIndex } from "virtual:docs-data";
import { searchDocs, searchExcerpt } from "./search";
const router = useRouter();
const navigating = ref(false);
const open = ref(false),
query = ref(""),
active = ref(0),
field = ref<HTMLInputElement>();
const results = computed(() => searchDocs(searchIndex, query.value));
watch(query, () => {
active.value = 0;
});
watch(open, (value) => {
if (!value) query.value = "";
else navigating.value = false;
});
function shortcut(event: KeyboardEvent) {
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") {
event.preventDefault();
open.value = !open.value;
}
}
function move(delta: number) {
if (!results.value.length) return;
active.value =
(active.value + delta + results.value.length) % results.value.length;
void nextTick(() =>
document
.getElementById("search-result-" + active.value)
?.scrollIntoView({ block: "nearest" }),
);
}
async function navigateTo(entry: (typeof searchIndex)[number]) {
navigating.value = true;
open.value = false;
await router.go(withBase(entry.url));
await nextTick();
const id = entry.url.split("#")[1];
const target = id
? document.getElementById(decodeURIComponent(id))
: document.querySelector<HTMLElement>(".docs-main h1");
target?.setAttribute("tabindex", "-1");
target?.focus({ preventScroll: true });
}
function navigate() {
const entry = results.value[active.value];
if (entry) void navigateTo(entry);
}
function closeAutoFocus(event: Event) {
if (navigating.value) event.preventDefault();
}
onMounted(() => window.addEventListener("keydown", shortcut));
onBeforeUnmount(() => window.removeEventListener("keydown", shortcut));
</script>
<template>
<DialogRoot v-model:open="open">
<DialogTrigger class="search-trigger" aria-label="搜索文档">
<IconSearch aria-hidden="true" :size="17" />
<span>搜索文档…</span>
<kbd>⌘ / Ctrl K</kbd>
</DialogTrigger>
<DialogPortal>
<DialogOverlay class="search-overlay" />
<DialogContent
class="search-dialog"
@open-auto-focus.prevent="field?.focus()"
@close-auto-focus="closeAutoFocus"
>
<DialogTitle class="sr-only">搜索文档</DialogTitle>
<DialogDescription class="sr-only">
搜索组件、参数和用法;使用方向键选择,回车打开,Esc 关闭。
</DialogDescription>
<div class="search-field">
<input
ref="field"
v-model="query"
placeholder="搜索组件、参数或用法…"
aria-label="搜索组件、参数或用法"
role="combobox"
aria-autocomplete="list"
aria-controls="doc-search-results"
:aria-expanded="Boolean(query.trim())"
:aria-activedescendant="
results.length ? 'search-result-' + active : undefined
"
@keydown.down.prevent="move(1)"
@keydown.up.prevent="move(-1)"
@keydown.enter.prevent="navigate"
/>
<DialogClose class="search-close" aria-label="关闭搜索">
Esc
</DialogClose>
</div>
<div
class="search-results"
id="doc-search-results"
role="listbox"
aria-label="搜索结果"
>
<p v-if="!query.trim()" class="search-empty">
试试搜索「isPending」「主题」或「受控」
</p>
<p v-else-if="!results.length" class="search-empty" role="status">
没有找到“{{ query }}”,试试组件名或参数名。
</p>
<a
v-for="(entry, index) in results"
:id="'search-result-' + index"
:key="entry.url"
:href="withBase(entry.url)"
role="option"
:aria-selected="index === active"
:tabindex="-1"
@mousemove="active = index"
@click.prevent="navigateTo(entry)"
>
<span class="result-title">
{{ entry.title }}
<span>{{ entry.section }}</span>
</span>
<span class="result-excerpt">
{{ searchExcerpt(entry, query) || "查看文档" }}
</span>
</a>
</div>
<div class="search-footer" aria-live="polite">
<span>
{{ query.trim() ? results.length + " 条结果" : "本地文档搜索" }}
</span>
<span>↑ ↓ 选择 ↵ 打开</span>
</div>
</DialogContent>
</DialogPortal>
</DialogRoot>
</template>
+300
View File
@@ -0,0 +1,300 @@
<script setup lang="ts">
import {
IconSun,
IconMoon,
IconMenu2,
IconX,
IconArrowUpRight,
} from "@tabler/icons-vue";
import {
computed,
ref,
watch,
nextTick,
onMounted,
onBeforeUnmount,
} from "vue";
import { useData, useRoute, withBase, onContentUpdated } from "vitepress";
import {
DialogRoot,
DialogTrigger,
DialogPortal,
DialogOverlay,
DialogContent,
DialogTitle,
DialogClose,
} from "reka-ui";
import DocSearch from "./DocSearch.vue";
const { frontmatter, page, isDark } = useData();
const route = useRoute();
const mobile = ref(false),
activeSlug = ref("");
const copyMessage = ref("");
let copyTimer: ReturnType<typeof setTimeout> | undefined;
onBeforeUnmount(() => clearTimeout(copyTimer));
const groups = [
{
title: "开始使用",
items: [
{ title: "介绍", url: "/introduction" },
{ title: "安装", url: "/guide" },
{ title: "主题", url: "/themes" },
],
},
{
title: "组件",
items: [
{ title: "Button 按钮", url: "/components/button" },
{ title: "Card 卡片", url: "/components/card" },
{ title: "Input 输入框", url: "/components/input" },
{ title: "Switch 开关", url: "/components/switch" },
],
},
];
const items = groups.flatMap((g) => g.items);
const currentIndex = computed(() =>
items.findIndex((item) => selected(item.url)),
);
const previous = computed(() => items[currentIndex.value - 1]);
const next = computed(() => items[currentIndex.value + 1]);
function selected(url: string) {
return (
route.path === withBase(url) ||
route.path === withBase(url + ".html") ||
(url === "/components/button" && route.path === withBase("/"))
);
}
const headers = computed(() => page.value.headers ?? []);
const flatHeaders = computed(() =>
headers.value.flatMap((h) => [h, ...(h.children ?? [])]),
);
let ticking = false;
function updateActive() {
ticking = false;
const headings = flatHeaders.value
.map((h) => document.getElementById(h.slug))
.filter((el): el is HTMLElement => Boolean(el));
let active = headings[0]?.id ?? "";
for (const heading of headings) {
if (heading.getBoundingClientRect().top <= 120) active = heading.id;
else break;
}
activeSlug.value = active;
}
function onScroll() {
if (!ticking) {
ticking = true;
requestAnimationFrame(updateActive);
}
}
onMounted(() => {
window.addEventListener("scroll", onScroll, { passive: true });
updateActive();
});
onBeforeUnmount(() => window.removeEventListener("scroll", onScroll));
onContentUpdated(() => {
void nextTick(updateActive);
});
watch(
() => route.path,
() => {
mobile.value = false;
void nextTick(() => {
if (!window.location.hash)
window.scrollTo({ top: 0, behavior: "instant" });
updateActive();
});
},
);
async function copyMarkdownCode(event: MouseEvent) {
const target = (event.target as HTMLElement).closest<HTMLButtonElement>(
"button.copy",
);
if (!target) return;
const code = target.parentElement?.querySelector("pre code")?.textContent;
if (!code) return;
try {
await navigator.clipboard.writeText(code);
target.classList.add("copied");
target.setAttribute("aria-label", "已复制");
copyMessage.value = "代码已复制";
clearTimeout(copyTimer);
copyTimer = setTimeout(() => {
target.classList.remove("copied");
target.setAttribute("aria-label", "复制代码");
copyMessage.value = "";
}, 2000);
} catch {
target.setAttribute("aria-label", "复制失败,请手动选择代码");
copyMessage.value = "复制失败,请手动选择代码";
}
}
</script>
<template>
<div class="docs-layout">
<a class="skip" href="#main">跳至内容</a>
<p class="sr-only" role="status">{{ copyMessage }}</p>
<header class="docs-nav">
<a class="brand" :href="withBase('/components/button')">
heroui
<span>Vue</span>
</a>
<span class="version">v0.0.1</span>
<nav aria-label="主导航">
<a
:href="withBase('/guide')"
:class="{
active:
!frontmatter.component && route.path !== withBase('/themes'),
}"
>
文档
</a>
<a
:href="withBase('/components/button')"
:class="{ active: Boolean(frontmatter.component) }"
>
组件
</a>
<a
:href="withBase('/themes')"
:class="{ active: route.path === withBase('/themes') }"
>
主题
</a>
</nav>
<div class="nav-tools">
<DocSearch />
<button
class="theme-toggle"
:aria-label="isDark ? '切换浅色主题' : '切换深色主题'"
@click="isDark = !isDark"
>
<IconSun v-if="isDark" aria-hidden="true" :size="18" />
<IconMoon v-else aria-hidden="true" :size="18" />
</button>
<DialogRoot v-model:open="mobile">
<DialogTrigger class="mobile-menu" aria-label="打开文档目录">
<IconMenu2 aria-hidden="true" :size="20" />
</DialogTrigger>
<DialogPortal>
<DialogOverlay class="mobile-nav-overlay" />
<DialogContent class="mobile-nav-dialog">
<div class="mobile-nav-heading">
<DialogTitle>文档目录</DialogTitle>
<DialogClose aria-label="关闭文档目录">
<IconX aria-hidden="true" :size="20" />
</DialogClose>
</div>
<nav aria-label="移动端文档导航">
<section v-for="group in groups" :key="group.title">
<h2>{{ group.title }}</h2>
<a
v-for="item in group.items"
:key="item.url"
:href="withBase(item.url)"
:aria-current="selected(item.url) ? 'page' : undefined"
@click="mobile = false"
>
{{ item.title }}
</a>
</section>
</nav>
</DialogContent>
</DialogPortal>
</DialogRoot>
</div>
</header>
<div class="docs-body">
<aside class="docs-sidebar" aria-label="文档导航">
<div class="framework">
<span class="vue-mark">V</span>
Vue
<span class="framework-note">组件库</span>
</div>
<section v-for="group in groups" :key="group.title">
<h2>{{ group.title }}</h2>
<a
v-for="item in group.items"
:key="item.url"
:href="withBase(item.url)"
:class="{ selected: selected(item.url) }"
:aria-current="selected(item.url) ? 'page' : undefined"
>
{{ item.title }}
</a>
</section>
<p class="community">
独立社区实现
<br />
设计基线 HeroUI v3.2.6
</p>
</aside>
<main id="main" class="docs-main">
<div class="breadcrumb">
{{ frontmatter.group ?? "文档" }}
<span>›</span>
{{ frontmatter.title }}
</div>
<h1>{{ frontmatter.title }}</h1>
<p class="page-description">{{ frontmatter.description }}</p>
<div v-if="frontmatter.component" class="source-links">
<a
:href="`https://github.com/heroui-inc/heroui/tree/ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960/packages/react/src/components/${frontmatter.component}`"
target="_blank"
rel="noreferrer"
>
React 参考源码
<IconArrowUpRight aria-hidden="true" :size="12" />
</a>
<a
:href="`https://github.com/heroui-inc/heroui/blob/ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960/packages/styles/components/${frontmatter.component}.css`"
target="_blank"
rel="noreferrer"
>
样式源码
<IconArrowUpRight aria-hidden="true" :size="12" />
</a>
</div>
<div @click="copyMarkdownCode"><Content class="docs-content" /></div>
<nav class="page-navigation" aria-label="相邻页面">
<a v-if="previous" :href="withBase(previous.url)">
<span>上一页</span>
<strong>{{ previous.title }}</strong>
</a>
<a v-if="next" class="page-next" :href="withBase(next.url)">
<span>下一页</span>
<strong>{{ next.title }}</strong>
</a>
</nav>
<footer class="docs-footer">
基于 HeroUI v3 设计的 Vue 实现 ·
<a :href="withBase('/introduction')">实现范围与差异</a>
</footer>
</main>
<aside v-if="headers.length" class="docs-toc" aria-label="本页目录">
<p>本页内容</p>
<template v-for="h in headers" :key="h.slug">
<a
:href="'#' + h.slug"
:class="{ current: activeSlug === h.slug }"
:aria-current="activeSlug === h.slug ? 'location' : undefined"
>
{{ h.title }}
</a>
<a
v-for="child in h.children"
:key="child.slug"
class="nested"
:class="{ current: activeSlug === child.slug }"
:aria-current="activeSlug === child.slug ? 'location' : undefined"
:href="'#' + child.slug"
>
{{ child.title }}
</a>
</template>
</aside>
</div>
</div>
</template>
+12
View File
@@ -0,0 +1,12 @@
import type { Theme } from "vitepress";
import Layout from "./Layout.vue";
import Demo from "./Demo.vue";
import "@heroui-vue/styles/css";
import "./utilities.css";
import "./style.css";
export default {
Layout,
enhanceApp({ app }) {
app.component("ComponentPreview", Demo);
},
} satisfies Theme;
+55
View File
@@ -0,0 +1,55 @@
export interface SearchEntry {
title: string;
section: string;
url: string;
text: string;
}
export function searchDocs(
entries: SearchEntry[],
query: string,
): SearchEntry[] {
const terms = query.toLocaleLowerCase().trim().split(/\s+/).filter(Boolean);
if (!terms.length) return [];
return entries
.map((entry, index) => {
const title = entry.title.toLocaleLowerCase(),
section = entry.section.toLocaleLowerCase(),
text = entry.text.toLocaleLowerCase();
if (
!terms.every((term) =>
(title + " " + section + " " + text).includes(term),
)
)
return null;
const score = terms.reduce(
(score, term) =>
score +
(title.includes(term) ? 12 : 0) +
(section.includes(term) ? 8 : 0) +
(text.includes(term) ? 1 : 0),
0,
);
return { entry, score, index };
})
.filter((item): item is NonNullable<typeof item> => item !== null)
.sort((a, b) => b.score - a.score || a.index - b.index)
.slice(0, 20)
.map((item) => item.entry);
}
export function searchExcerpt(entry: SearchEntry, query: string): string {
const text = entry.text
.replace(/[-:|]{3,}/g, " ")
.replace(/\s+/g, " ")
.trim();
const terms = query.trim().toLocaleLowerCase().split(/\s+/).filter(Boolean);
const positions = terms
.map((term) => text.toLocaleLowerCase().indexOf(term))
.filter((index) => index >= 0);
const start = positions.length ? Math.max(0, Math.min(...positions) - 28) : 0;
return (
(start ? "…" : "") +
text.slice(start, start + 140) +
(text.length > start + 140 ? "…" : "")
);
}
File diff suppressed because it is too large Load Diff
+15
View File
@@ -0,0 +1,15 @@
@import "tailwindcss/theme.css" layer(theme);
@import "../../../../packages/styles/themes/shared/theme.css";
@import "tailwindcss/utilities.css" layer(utilities);
@source "../../demos";
/* Follow the document's explicit theme, including nested preview scopes. */
@custom-variant dark (&:where(.dark, .dark *, [data-theme="dark"], [data-theme="dark"] *));
@custom-variant motion-reduce {
&:is([data-reduce-motion="true"], [data-reduce-motion="true"] *) {
@slot;
}
@media (prefers-reduced-motion: reduce) {
@slot;
}
}
+9
View File
@@ -0,0 +1,9 @@
---
title: 组件
description: 已迁移组件及文档
---
- [Button 按钮](./components/button)
- [Card 卡片](./components/card)
- [Input 输入框](./components/input)
- [Switch 开关](./components/switch)
+142
View File
@@ -0,0 +1,142 @@
---
title: Button 按钮
description: 可点击的按钮组件,支持多种变体与状态
component: button
group: 组件
---
## 用法
```vue
<script setup lang="ts">
import { Button } from "@heroui-vue/components";
</script>
```
<ComponentPreview name="button-basic" />
## 示例
### 变体
<ComponentPreview name="button-variants" />
### 尺寸
<ComponentPreview name="button-sizes" />
### 带图标
<ComponentPreview name="button-with-icons" />
### 仅图标
<ComponentPreview name="button-icon-only" />
### 加载中
此例固定展示上传中的外观;加载期间阻止重复提交,但保留键盘焦点。要体验开始、完成和再次上传,请使用下一例。
<ComponentPreview name="button-loading" />
### 加载中(点击触发)
点击“上传文件”后进入加载状态,2 秒后恢复,可重复操作。
<ComponentPreview name="button-loading-state" />
### 宽度充满
<ComponentPreview name="button-full-width" />
### 禁用状态
<ComponentPreview name="button-disabled" />
### 社交媒体按钮
<ComponentPreview name="button-social" />
### 渲染函数
Vue 使用 `asChild` 将按钮属性与交互合并到一个自定义原生 button,作用域插槽提供状态。对应上游 render 函数示例,不将 render prop 原样搬入 Vue。
<ComponentPreview name="button-render-function" />
### 添加自定义变体
可通过包装组件并添加自定义变体来扩展组件。下面使用与上游相同的 `tv` 扩展方式,提供额外的圆角与尺寸配置。
<ComponentPreview name="button-custom-variants" />
### 添加涟漪效果
通过组合添加涟漪。本示例使用 Vue 和 CSS 实现,支持指针、Enter 和空格触发;不直接依赖上游 React 的 m3-ripple,减少动态效果时缩短动画。
<ComponentPreview name="button-ripple-effect" />
## 自定义样式
### Tailwind CSS
<ComponentPreview name="button-custom-styles" />
使用标准 `class` 属性添加工具类。组件保持上游的尺寸、间距、BEM 结构与状态钩子;类名前缀改为 `hv-`。
```vue
<Button class="rounded-lg">自定义圆角</Button>
```
### 全局 CSS
```css
@layer components {
.hv-button--primary {
--button-bg: oklch(0.6 0.2 300);
}
}
```
## 样式参考
基础类为 `.hv-button`,变体为 `.hv-button--primary` 等;尺寸为 `.hv-button--sm` / `md` / `lg`。支持 `.hv-button--icon-only` 和 `.hv-button--full-width`。
### 交互状态
保留 `data-hovered`、`data-pressed`、`data-focused`、`data-focus-visible`、`data-pending` 状态;键盘焦点样式与鼠标焦点区分。加载期间保留焦点并阻止重复点击,通过 aria-disabled 呈现半透明的原变体颜色。
## API 参考
### Button
| Prop | 类型 | 默认值 | 描述 |
| ------------ | --------------------------------------------------------------------------------------------- | ----------- | --------------------------------------------- |
| `variant` | `'primary' \| 'secondary' \| 'tertiary' \| 'outline' \| 'ghost' \| 'danger' \| 'danger-soft'` | `'primary'` | 视觉样式变体 |
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | 按钮尺寸 |
| `fullWidth` | `boolean` | `false` | 是否占满容器宽度 |
| `isDisabled` | `boolean` | `false` | 是否禁用 |
| `isPending` | `boolean` | `false` | 是否处于加载状态 |
| `isIconOnly` | `boolean` | `false` | 是否仅包含图标 |
| `asChild` | `boolean` | `false` | 将属性与交互合并到默认插槽中唯一的原生 button |
| `type` | `'button' \| 'submit' \| 'reset'` | `'button'` | 原生按钮类型 |
### 事件与插槽
Vue 使用 `@click` 和默认作用域插槽。插槽提供 `isPending`、`isPressed`、`isHovered`、`isFocused`、`isFocusVisible`、`isDisabled`。原生属性、class、style、事件透传至 button。
`onPress` / PressEvent 与 `@click` 的事件模型不同,不宣称完全等价。初版 `disabled` / `loading` 继续作为兼容别名;新代码使用 `isDisabled` / `isPending`。`isPending` 不自动插入加载图标,采用上游的组合方式。`loading` 是相同加载语义的兼容别名,额外自动显示旋转图标;不会设置原生 disabled。`asChild` 下内容由调用者完整组合,默认插槽必须只包含一个原生 button。
### 作用域插槽状态
| 参数 | 类型 | 描述 |
| ---------------- | --------- | -------------------------------- |
| `isPending` | `boolean` | 是否处于加载状态 |
| `isPressed` | `boolean` | 是否正在按下 |
| `isHovered` | `boolean` | 是否悬停 |
| `isFocused` | `boolean` | 是否聚焦 |
| `isFocusVisible` | `boolean` | 是否显示键盘焦点指示器 |
| `isDisabled` | `boolean` | 是否由禁用属性禁用,不与加载混用 |
## 相关组件
[Card 卡片](./card) · [Input 输入框](./input) · [Switch 开关](./switch)
+121
View File
@@ -0,0 +1,121 @@
---
title: Card 卡片
description: 灵活容器组件,用于分组相关内容与操作
component: card
group: 组件
---
## 用法
```vue
<script setup lang="ts">
import {
Card,
CardHeader,
CardTitle,
CardDescription,
CardContent,
CardFooter,
} from "@heroui-vue/components";
</script>
```
<ComponentPreview name="card-default" />
## 组件结构
```vue
<Card>
<CardHeader>
<CardTitle />
<CardDescription />
</CardHeader>
<CardContent />
<CardFooter />
</Card>
```
## 示例
### 变体
Card 提供语义变体,描述 prominence 级别而非具体视觉样式,允许主题以不同方式解读:
<ComponentPreview name="card-variants" />
- `transparent`:透明背景,无阴影,适合嵌套卡片。
- `default`:标准卡片,使用 `--surface`。
- `secondary`:使用 `--surface-secondary`。
- `tertiary`:使用 `--surface-tertiary`。
基线中文说明中的部分表面映射与实际 CSS 不一致;这里以固定提交的 CSS 为准。
### 水平布局
<ComponentPreview name="card-horizontal" />
### 带头像
<ComponentPreview name="card-with-avatar" />
### 带图片
<ComponentPreview name="card-with-images" />
### 搭配表单
<ComponentPreview name="card-with-form" />
头像使用 Reka Avatar 组合;链接与表单使用原生 HTML,标签与输入显式关联。此示例不发送登录请求;图片沿用上游公开资源地址。
## 自定义样式
### Tailwind CSS
<ComponentPreview name="card-custom-styles" />
### 全局 CSS
```css
@layer components {
.hv-card__title {
font-weight: 700;
}
}
```
## 样式参考
| 部件 | CSS 类 | data-slot | 默认元素 |
| --------------- | ----------------------- | ------------------ | -------- |
| Card | `.hv-card` | `card` | div |
| CardHeader | `.hv-card__header` | `card-header` | div |
| CardTitle | `.hv-card__title` | `card-title` | h3 |
| CardDescription | `.hv-card__description` | `card-description` | p |
| CardContent | `.hv-card__content` | `card-content` | div |
| CardFooter | `.hv-card__footer` | `card-footer` | div |
## API 参考
### Card
| Prop | 类型 | 默认值 | 描述 |
| --------- | --------------------------------------------------------- | ----------- | ------------------------------ |
| `variant` | `'transparent' \| 'default' \| 'secondary' \| 'tertiary'` | `'default'` | 表示 prominence 级别的语义变体 |
| `as` | `string` | `'div'` | 渲染的 HTML 元素 |
| `class` | `string / object / array` | — | Vue 标准类名合并 |
### CardHeader / CardTitle / CardDescription / CardContent / CardFooter
各部件支持 `as`、默认插槽和原生属性。默认标签见上表。Vue 使用独立命名导出替代 `Card.Header` 等 React 部件访问方式。
## 无障碍
```vue
<Card as="article" aria-labelledby="card-title">
<CardHeader><CardTitle id="card-title">Article Title</CardTitle></CardHeader>
</Card>
```
## 相关组件
[Button 按钮](./button) · [Input 输入框](./input)
+98
View File
@@ -0,0 +1,98 @@
---
title: Input 输入框
description: 接受标准 HTML 属性的原生单行文本输入组件
component: input
group: 组件
---
## 用法
```vue
<script setup lang="ts">
import { Input } from "@heroui-vue/components";
</script>
```
<ComponentPreview name="input-basic" />
::: info 字段组合
校验、标签与错误消息由 TextField 体系负责。TextField 尚未迁移,当前请使用原生 label、aria-describedby 和 aria-invalid 关联。
:::
## 示例
### 变体
Input 组件支持两种视觉变体:
- **primary**(默认):标准样式带阴影,适用于大多数场景。
- **secondary**:低强调变体无阴影,适用于 Surface 组件内。
<ComponentPreview name="input-variants" />
### 表面样式
在表面容器内使用 `variant="secondary"` 以应用适合背景的低强调变体。
<ComponentPreview name="input-on-surface" />
### 宽度充满
<ComponentPreview name="input-full-width" />
### 输入类型
<ComponentPreview name="input-types" />
### 受控组件
<ComponentPreview name="input-controlled" />
## 自定义样式
### Tailwind CSS
<ComponentPreview name="input-custom-styles" />
### 全局 CSS
```css
@layer components {
.hv-input {
border-radius: 8px;
}
}
```
## 样式参考
基础类 `.hv-input`;变体 `.hv-input--primary` / `.hv-input--secondary`;宽度修饰符 `.hv-input--full-width`。保留原生 hover / focus / disabled 和 `data-invalid` 状态。
## API 参考
### Input
Input 接受标准 HTML input 属性,以及以下 props:
| Prop | 类型 | 默认值 | 描述 |
| --------------------------------------------------- | -------------------------- | ----------- | --------------------------------- |
| `modelValue` | `string` | — | 受控值,使用 v-model |
| `defaultValue` | `string` | `''` | 非受控初始值 |
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 视觉变体 |
| `fullWidth` | `boolean` | `false` | 是否占满容器宽度 |
| `type` | `string` | `'text'` | 原生输入类型 |
| `invalid` | `boolean` | `false` | 设置 aria-invalid 和 data-invalid |
| `disabled` / `readonly` / `required` | `boolean` | `false` | 原生表单状态 |
| `name` / `placeholder` / `autocomplete` / `pattern` | `string` | — | 原生输入属性 |
| `maxlength` / `minlength` | `number` | — | 长度限制 |
| `min` / `max` / `step` | `string / number` | — | 数值与日期约束 |
### 事件与方法
`update:modelValue` 传递字符串;`@input` / `@change` 保留原生事件。`focus()` 可通过模板引用调用。原生表单 reset 还原非受控初始值;受控值由父组件管理。
不把 React 的 `value` + `onChange` 直接复制为 Vue 状态 API。`className` 改为 `class`。TextField 上下文的自动继承尚未实现。
## 相关组件
[Button 按钮](./button) · [Card 卡片](./card)
+179
View File
@@ -0,0 +1,179 @@
---
title: Switch 开关
description: 用于布尔状态的开关组件。
component: switch
group: 组件
---
## 用法
```vue
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
Description,
Label,
SwitchIcon,
SwitchGroup,
FieldError,
} from "@heroui-vue/components";
</script>
```
<ComponentPreview name="switch-basic" />
## 组件结构
```vue
<Switch>
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
启用通知
</SwitchContent>
<Description>允许接收通知</Description>
</Switch>
```
请把 SwitchControl 与标签文本放入 SwitchContent;Description 作为其兄弟节点。Vue 底座使用原生 button 承载 role="switch",不是 React Aria 的 label 结构。
## 示例
### 尺寸
<ComponentPreview name="switch-sizes" />
### 带图标
<ComponentPreview name="switch-with-icons" />
### 禁用
<ComponentPreview name="switch-disabled" />
### 无标签
<ComponentPreview name="switch-without-label" />
### 带描述
<ComponentPreview name="switch-with-description" />
### 默认选中
<ComponentPreview name="switch-default-selected" />
### 受控组件
<ComponentPreview name="switch-controlled" />
### 标签位置
<ComponentPreview name="switch-label-position" />
### 分组
<ComponentPreview name="switch-group" />
### 横向分组
<ComponentPreview name="switch-group-horizontal" />
### 表单集成
<ComponentPreview name="switch-form" />
### 渲染属性
Vue 使用作用域插槽读取选择状态。
<ComponentPreview name="switch-render-props" />
### 渲染函数
Vue 使用 `asChild` 合并根容器属性,默认插槽必须只有一个自定义根元素;内部仍需放置 SwitchContent。
<ComponentPreview name="switch-render-function" />
## 自定义样式
### Tailwind CSS
<ComponentPreview name="switch-custom-styles" />
### 全局 CSS
```css
@layer components {
.hv-switch__control {
border-radius: 12px;
}
}
```
## 样式参考
保留字段根容器、Content、Control、Thumb、Icon 的组合结构和 data-slot;类名前缀为 `hv-`。选中状态使用 `data-selected="true"`,禁用使用 `data-disabled="true"`。尺寸与滑块比例移植自基线 CSS。
## API 参考
### Switch
| Prop | 类型 | 默认值 | 描述 |
| -------------------- | --------------------------------------------------------------------- | ---------- | -------------------------------- |
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Switch 尺寸 |
| `checked` | `boolean` | — | Vue 受控值,使用 v-model:checked |
| `isSelected` | `boolean` | — | 上游同名受控属性,优先于 checked |
| `defaultSelected` | `boolean` | `false` | 非受控初始值 |
| `isDisabled` | `boolean` | `false` | 是否禁用 |
| `isReadOnly` | `boolean` | `false` | 是否只读 |
| `isInvalid` | `boolean` | `false` | ARIA 无效状态 |
| `isRequired` | `boolean` | `false` | 是否必须开启 |
| `name` | `string` | — | 表单字段名称 |
| `value` | `string` | — | 表单提交值 |
| `asChild` | `boolean` | `false` | 合并根属性到唯一自定义容器 |
| `validate` | `(value: boolean) => string \| string[] \| true \| null \| undefined` | — | 自定义校验 |
| `validationBehavior` | `'native' \| 'aria'` | `'native'` | 校验与错误展示方式 |
### SwitchContent / SwitchControl / SwitchThumb / SwitchIcon
分别对应上游 Content、Control、Thumb、Icon。Content 提供可点击的开关语义,其余为可组合样式部件。空默认插槽会自动渲染轨道与滑块;使用自定义插槽时由调用者组合部件。
### 事件与插槽
`update:checked`、`update:isSelected` 与 `change` 都传递 boolean。根作用域插槽提供 isSelected、isDisabled、isReadOnly、isInvalid、isRequired。根 attrs 的 class/style/data-* 应用到字段容器,ARIA 与 DOM 事件透传到 Content 按钮。
### 表单与校验
`validate(value)` 返回错误字符串、字符串数组,或 `true` / `null` / `undefined` 表示通过。`validationBehavior="native"`(默认)通过原生 checkbox 的约束阻止无效表单提交,校验失败后展示错误并将焦点交给开关;`"aria"` 立即设置 ARIA 错误状态,提交由调用者处理。
```vue
<Switch
name="consent"
is-required
:validate="(value) => (value ? true : '请先开启此选项。')"
>
<SwitchContent><SwitchControl><SwitchThumb /></SwitchControl>同意接收通知</SwitchContent>
<Description>可随时在设置中关闭。</Description>
<FieldError />
</Switch>
```
Description 与 FieldError 自动生成唯一 ID,并关联到 Content 的 aria-describedby。表单 reset 恢复非受控初值;受控值由父组件管理。
### SwitchGroup
| Prop | 类型 | 默认值 | 描述 |
| ------------- | ---------------------------- | ------------ | ---------- |
| `orientation` | `'horizontal' \| 'vertical'` | `'vertical'` | 组布局方向 |
SwitchGroup 是布局容器,每个 Switch 独立维护值;请提供 aria-label 或 aria-labelledby 标注分组。
### 当前差异
`disabled` / `required` / `defaultChecked` 作为兼容别名保留。`change` 事件传递 boolean;React Aria 的 PressEvent 仍不等价于 DOM click。根组件的 class/style/data-* 作用于字段容器,ARIA 与 DOM 事件作用于 Content 按钮;Content 上的显式属性可覆盖默认透传。`asChild` 替代 React render prop。FieldError 当前仅接入 Switch 字段,尚未提供完整 TextField / Form 体系。
## 相关组件
[Button 按钮](./button) · [Input 输入框](./input)
+8
View File
@@ -0,0 +1,8 @@
<script setup lang="ts">
import { ref } from "vue";
import { Button } from "@heroui-vue/components";
const pressed = ref(false);
</script>
<template>
<Button @click="pressed = true">{{ pressed ? "按钮已按下" : "点我" }}</Button>
</template>
+35
View File
@@ -0,0 +1,35 @@
<script setup lang="ts">
import { Button } from "@heroui-vue/components";
</script>
<template>
<Button
variant="ghost"
class="gradient-border relative z-0 rounded-full bg-linear-to-t from-neutral-100 to-white px-10 py-3 font-[450] text-neutral-800 shadow-none transition-all duration-300 ease-[cubic-bezier(0.34,1.56,0.64,1)] [--gradient-border-width:1.5px] [--gradient-border:linear-gradient(315deg,#e5e5e5_0%,#fafafa_50%,#c4c4c4_100%)] hover:from-white hover:to-neutral-50 hover:brightness-105 active:scale-95 dark:from-neutral-900 dark:via-neutral-800 dark:to-neutral-800/80 dark:text-neutral-100 dark:[--gradient-border:linear-gradient(315deg,#404040_0%,#262626_50%,#525252_100%)] dark:hover:from-neutral-800 dark:hover:via-neutral-800 dark:hover:to-neutral-900/90 motion-reduce:transition-none"
:style="{
boxShadow:
'rgba(0, 0, 0, 0.02) 0px 1px 6px, rgba(0, 0, 0, 0.02) 0px 3px 12px, rgba(0, 0, 0, 0.01) 0px 8px 24px, rgba(0, 0, 0, 0.02) 0px 18px 40px, rgba(0, 0, 0, 0.02) 0px 40px 80px',
}"
>
升级
</Button>
</template>
<style scoped>
.gradient-border::before {
content: "";
position: absolute;
inset: 0;
z-index: 0;
border-radius: inherit;
padding: var(--gradient-border-width, 1px);
background: var(--gradient-border);
pointer-events: none;
-webkit-mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
mask-composite: exclude;
}
</style>
@@ -0,0 +1,58 @@
<script setup lang="ts">
import { defineComponent, h, type PropType } from "vue";
import { Button, buttonVariants, tv } from "@heroui-vue/components";
const myButtonVariants = tv({
extend: buttonVariants,
base: "text-base font-semibold shadow-md text-shadow-lg data-[pending=true]:opacity-40",
variants: {
variant: {
primary:
"text-white dark:bg-white/10 dark:text-white dark:hover:bg-white/15",
},
radius: {
full: "rounded-full",
lg: "rounded-lg",
md: "rounded-md",
sm: "rounded-sm",
},
size: {
sm: "h-10 px-4",
md: "h-11 px-6",
lg: "h-12 px-8",
xl: "h-13 px-10",
},
},
defaultVariants: { radius: "full", size: "md", variant: "primary" },
});
const CustomButton = defineComponent({
inheritAttrs: false,
props: {
radius: {
type: String as PropType<"full" | "lg" | "md" | "sm">,
default: "full",
},
size: {
type: String as PropType<"sm" | "md" | "lg" | "xl">,
default: "md",
},
},
setup(props, { attrs, slots }) {
return () =>
h(
Button,
{
...attrs,
class: myButtonVariants({
radius: props.radius,
size: props.size,
class: attrs.class as string,
}),
},
slots,
);
},
});
</script>
<template>
<CustomButton>自定义按钮</CustomButton>
</template>
+13
View File
@@ -0,0 +1,13 @@
<script setup lang="ts">
import { Button } from "@heroui-vue/components";
</script>
<template>
<div class="demo-row">
<Button is-disabled variant="primary">主要</Button>
<Button is-disabled variant="secondary">次要</Button>
<Button is-disabled variant="tertiary">第三</Button>
<Button is-disabled variant="outline">线框</Button>
<Button is-disabled variant="ghost">幽灵</Button>
<Button is-disabled variant="danger">危险</Button>
</div>
</template>
+22
View File
@@ -0,0 +1,22 @@
<script setup lang="ts">
import { IconPlus } from "@tabler/icons-vue";
import { Button } from "@heroui-vue/components";
</script>
<template>
<div class="full-width-demo">
<Button full-width>主要按钮</Button>
<Button full-width>
<IconPlus aria-hidden="true" />
带图标
</Button>
</div>
</template>
<style scoped>
.full-width-demo {
display: flex;
flex-direction: column;
gap: 12px;
width: 400px;
max-width: 100%;
}
</style>
+17
View File
@@ -0,0 +1,17 @@
<script setup lang="ts">
import { IconDots, IconSettings, IconTrash } from "@tabler/icons-vue";
import { Button } from "@heroui-vue/components";
</script>
<template>
<div class="demo-row">
<Button is-icon-only variant="tertiary" aria-label="更多选项">
<IconDots aria-hidden="true" />
</Button>
<Button is-icon-only variant="secondary" aria-label="设置">
<IconSettings aria-hidden="true" />
</Button>
<Button is-icon-only variant="danger" aria-label="删除">
<IconTrash aria-hidden="true" />
</Button>
</div>
</template>
+52
View File
@@ -0,0 +1,52 @@
<script setup lang="ts">
import { IconLoader2 } from "@tabler/icons-vue";
import { IconPaperclip } from "@tabler/icons-vue";
import { ref, onBeforeUnmount } from "vue";
import { Button } from "@heroui-vue/components";
const isLoading = ref(false),
message = ref("");
let timer: ReturnType<typeof setTimeout> | undefined;
function upload() {
if (isLoading.value) return;
isLoading.value = true;
message.value = "";
timer = setTimeout(() => {
isLoading.value = false;
message.value = "上传完成,可以再次上传。";
}, 2000);
}
onBeforeUnmount(() => clearTimeout(timer));
</script>
<template>
<div class="upload-demo">
<Button :is-pending="isLoading" @click="upload">
<span
v-if="isLoading"
data-slot="spinner"
class="inline-flex size-4 shrink-0"
aria-hidden="true"
>
<IconLoader2
class="size-full animate-spin motion-reduce:animate-none"
/>
</span>
<IconPaperclip v-else aria-hidden="true" />
{{ isLoading ? "上传中…" : "上传文件" }}
</Button>
<p class="upload-status" role="status">{{ message }}</p>
</div>
</template>
<style scoped>
.upload-demo {
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
}
.upload-status {
font-size: 12px;
color: var(--muted);
min-height: 20px;
margin: 0;
}
</style>
+17
View File
@@ -0,0 +1,17 @@
<script setup lang="ts">
import { IconLoader2 } from "@tabler/icons-vue";
import { Button } from "@heroui-vue/components";
</script>
<template>
<Button is-pending v-slot="{ isPending }">
<span
v-if="isPending"
data-slot="spinner"
class="inline-flex size-4 shrink-0"
aria-hidden="true"
>
<IconLoader2 class="size-full animate-spin motion-reduce:animate-none" />
</span>
上传中…
</Button>
</template>
@@ -0,0 +1,8 @@
<script setup lang="ts">
import { Button } from "@heroui-vue/components";
</script>
<template>
<Button as-child v-slot="{ isPressed }">
<button :data-custom="isPressed ? 'pressed' : 'bar'">点按</button>
</Button>
</template>
+74
View File
@@ -0,0 +1,74 @@
<script setup lang="ts">
import { ref } from "vue";
import { Button } from "@heroui-vue/components";
const waves = ref<{ id: number; x: number; y: number; size: number }[]>([]);
let id = 0;
function add(target: HTMLElement, x: number, y: number) {
const size = Math.max(target.offsetWidth, target.offsetHeight) * 2;
waves.value.push({ id: ++id, x: x - size / 2, y: y - size / 2, size });
}
function ripple(event: PointerEvent) {
const target = event.currentTarget as HTMLElement;
const rect = target.getBoundingClientRect();
add(target, event.clientX - rect.left, event.clientY - rect.top);
}
function keyboardRipple(event: KeyboardEvent) {
if (event.repeat || !["Enter", " "].includes(event.key)) return;
const target = event.currentTarget as HTMLElement;
add(target, target.offsetWidth / 2, target.offsetHeight / 2);
}
function remove(id: number) {
waves.value = waves.value.filter((wave) => wave.id !== id);
}
</script>
<template>
<Button
variant="secondary"
class="ripple-button"
@pointerdown="ripple"
@keydown="keyboardRipple"
>
点我
<span
v-for="wave in waves"
:key="wave.id"
class="ripple-wave"
:style="{
left: wave.x + 'px',
top: wave.y + 'px',
width: wave.size + 'px',
height: wave.size + 'px',
}"
aria-hidden="true"
@animationend="remove(wave.id)"
/>
</Button>
</template>
<style scoped>
.ripple-button {
overflow: hidden;
}
.ripple-wave {
position: absolute;
pointer-events: none;
border-radius: 50%;
background: currentColor;
opacity: 0.18;
transform: scale(0);
animation: button-ripple 0.6s ease-out forwards;
}
@keyframes button-ripple {
to {
transform: scale(1);
opacity: 0;
}
}
@media (prefers-reduced-motion: reduce) {
.ripple-wave {
animation-duration: 1ms;
}
}
:global([data-reduce-motion="true"]) .ripple-wave {
animation-duration: 1ms;
}
</style>
+10
View File
@@ -0,0 +1,10 @@
<script setup lang="ts">
import { Button } from "@heroui-vue/components";
</script>
<template>
<div class="demo-row">
<Button size="sm">小</Button>
<Button size="md">中</Button>
<Button size="lg">大</Button>
</div>
</template>
+33
View File
@@ -0,0 +1,33 @@
<script setup lang="ts">
import {
IconBrandGoogle,
IconBrandGithubFilled,
IconBrandAppleFilled,
} from "@tabler/icons-vue";
import { Button } from "@heroui-vue/components";
</script>
<template>
<div class="social-demo">
<Button full-width variant="tertiary">
<IconBrandGoogle aria-hidden="true" />
使用 Google 登录
</Button>
<Button full-width variant="tertiary">
<IconBrandGithubFilled aria-hidden="true" />
使用 GitHub 登录
</Button>
<Button full-width variant="tertiary">
<IconBrandAppleFilled aria-hidden="true" />
使用 Apple 登录
</Button>
</div>
</template>
<style scoped>
.social-demo {
display: flex;
flex-direction: column;
gap: 12px;
width: 320px;
max-width: 100%;
}
</style>
+14
View File
@@ -0,0 +1,14 @@
<script setup lang="ts">
import { Button } from "@heroui-vue/components";
</script>
<template>
<div class="demo-row">
<Button variant="primary">主要</Button>
<Button variant="secondary">次要</Button>
<Button variant="tertiary">第三</Button>
<Button variant="outline">线框</Button>
<Button variant="ghost">幽灵</Button>
<Button variant="danger">危险</Button>
<Button variant="danger-soft">柔和危险</Button>
</div>
</template>
+29
View File
@@ -0,0 +1,29 @@
<script setup lang="ts">
import {
IconSearch,
IconUserPlus,
IconMail,
IconTrash,
} from "@tabler/icons-vue";
import { Button } from "@heroui-vue/components";
</script>
<template>
<div class="demo-row">
<Button variant="primary">
<IconSearch aria-hidden="true" />
搜索
</Button>
<Button variant="secondary">
<IconUserPlus aria-hidden="true" />
添加成员
</Button>
<Button variant="tertiary">
<IconMail aria-hidden="true" />
邮件
</Button>
<Button variant="danger">
<IconTrash aria-hidden="true" />
删除
</Button>
</div>
</template>
+70
View File
@@ -0,0 +1,70 @@
<script setup lang="ts">
import { IconStar, IconCheck } from "@tabler/icons-vue";
import {
Card,
CardHeader,
CardTitle,
CardDescription,
CardContent,
CardFooter,
Button,
} from "@heroui-vue/components";
const features = [
"无限项目与协作者",
"优先支持,24 小时响应",
"高级分析与导出",
];
</script>
<template>
<Card
class="relative w-full max-w-md overflow-hidden border border-accent/20 bg-linear-to-br from-accent/12 via-surface to-surface-secondary shadow-lg shadow-accent/10 dark:border-accent/30 dark:from-accent/20 dark:via-surface dark:to-accent/8 dark:shadow-accent/5"
>
<div
aria-hidden="true"
class="pointer-events-none absolute -top-12 -right-12 size-40 rounded-full bg-accent/20 blur-3xl dark:bg-accent/30"
/>
<div
aria-hidden="true"
class="pointer-events-none absolute -bottom-8 -left-8 size-28 rounded-full bg-accent/10 blur-2xl dark:bg-accent/20"
/>
<CardHeader class="relative gap-3">
<span
class="w-fit rounded-full bg-accent/15 px-2.5 py-0.5 text-xs font-medium tracking-wide text-accent dark:bg-accent/25 dark:text-accent-soft-foreground"
>
推荐
</span>
<div class="flex items-start gap-3">
<div
class="flex size-10 shrink-0 items-center justify-center rounded-xl bg-accent/15 text-accent dark:bg-accent/20 dark:text-accent-soft-foreground"
>
<IconStar aria-hidden="true" class="size-5" />
</div>
<div class="flex flex-col gap-1">
<CardTitle>升级到 Pro</CardTitle>
<CardDescription>
解锁面向成长型产品的团队工作流与洞察。
</CardDescription>
</div>
</div>
</CardHeader>
<CardContent class="relative">
<ul class="flex flex-col gap-2">
<li
v-for="feature in features"
:key="feature"
class="flex items-center gap-2 text-sm text-muted"
>
<IconCheck aria-hidden="true" class="size-4 shrink-0 text-accent" />
{{ feature }}
</li>
</ul>
</CardContent>
<CardFooter class="relative flex-col gap-2 sm:flex-row">
<Button class="w-full shadow-md shadow-accent/20">立即升级</Button>
<Button class="w-full" variant="secondary">对比方案</Button>
</CardFooter>
</Card>
</template>
+34
View File
@@ -0,0 +1,34 @@
<script setup lang="ts">
import { IconArrowUpRight } from "@tabler/icons-vue";
import { IconCoin } from "@tabler/icons-vue";
import {
Card,
CardHeader,
CardTitle,
CardDescription,
CardFooter,
} from "@heroui-vue/components";
</script>
<template>
<Card class="w-[400px]">
<IconCoin role="img" aria-label="美元图标" class="size-6" />
<CardHeader>
<CardTitle>成为 Acme 创作者!</CardTitle>
<CardDescription>
前往 Acme 创作者中心立即注册,开始从粉丝与支持者处获得积分奖励。
</CardDescription>
</CardHeader>
<CardFooter>
<a
class="demo-link inline-flex items-center gap-1"
aria-label="前往 Acme 创作者中心(在新标签页打开)"
href="https://heroui.com"
rel="noopener noreferrer"
target="_blank"
>
创作者中心
<IconArrowUpRight aria-hidden="true" class="size-3" />
</a>
</CardFooter>
</Card>
</template>
+53
View File
@@ -0,0 +1,53 @@
<script setup lang="ts">
import { closeButtonVariants } from "@heroui-vue/styles";
import { IconX } from "@tabler/icons-vue";
import {
Card,
CardHeader,
CardTitle,
CardDescription,
CardFooter,
Button,
} from "@heroui-vue/components";
</script>
<template>
<Card class="w-full items-stretch md:flex-row">
<div
class="relative h-[140px] w-full shrink-0 overflow-hidden rounded-2xl sm:h-[120px] sm:w-[120px]"
>
<img
alt="樱桃"
class="pointer-events-none absolute inset-0 h-full w-full scale-125 object-cover select-none"
loading="lazy"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/cherries.jpeg"
/>
</div>
<div class="flex flex-1 flex-col gap-3">
<CardHeader class="gap-1">
<CardTitle class="pe-8">成为 ACME 创作者!</CardTitle>
<CardDescription>
这是一段占位说明文字,用于展示横向卡片布局、配图与右上角关闭按钮的排版效果。
</CardDescription>
<button
type="button"
:class="closeButtonVariants()"
aria-label="关闭横幅"
class="absolute end-3 top-3"
>
<IconX aria-hidden="true" />
</button>
</CardHeader>
<CardFooter
class="mt-auto flex w-full flex-col items-start gap-3 sm:flex-row sm:items-center sm:justify-between"
>
<div class="flex flex-col">
<span class="text-sm font-medium text-foreground">
仅剩 10 个名额
</span>
<span class="text-xs text-muted">报名截止:10 月 10 日</span>
</div>
<Button class="w-full sm:w-auto">立即申请</Button>
</CardFooter>
</div>
</Card>
</template>
+52
View File
@@ -0,0 +1,52 @@
<script setup lang="ts">
import {
Card,
CardHeader,
CardTitle,
CardDescription,
CardContent,
} from "@heroui-vue/components";
</script>
<template>
<div class="flex flex-col gap-4">
<Card class="w-[320px]" variant="transparent">
<CardHeader>
<CardTitle>透明</CardTitle>
<CardDescription>背景透明,视觉层级较低(transparent)</CardDescription>
</CardHeader>
<CardContent>
<p>适合次要内容或嵌套在其它容器中的卡片</p>
</CardContent>
</Card>
<Card class="w-[320px]" variant="default">
<CardHeader>
<CardTitle>默认</CardTitle>
<CardDescription>标准外观(bg-surface)</CardDescription>
</CardHeader>
<CardContent>
<p>大多数场景的默认卡片变体</p>
</CardContent>
</Card>
<Card class="w-[320px]" variant="secondary">
<CardHeader>
<CardTitle>次要</CardTitle>
<CardDescription>中等强调(bg-surface-secondary)</CardDescription>
</CardHeader>
<CardContent>
<p>用于需要适度吸引注意力的内容</p>
</CardContent>
</Card>
<Card class="w-[320px]" variant="tertiary">
<CardHeader>
<CardTitle>第三</CardTitle>
<CardDescription>更高强调(bg-surface-tertiary)</CardDescription>
</CardHeader>
<CardContent>
<p>适合主要内容或需要突出的展示位</p>
</CardContent>
</Card>
</div>
</template>
+75
View File
@@ -0,0 +1,75 @@
<script setup lang="ts">
import {
Card,
CardHeader,
CardTitle,
CardDescription,
CardFooter,
} from "@heroui-vue/components";
import { AvatarRoot, AvatarImage, AvatarFallback } from "reka-ui";
</script>
<template>
<div class="flex flex-wrap gap-4">
<Card class="w-[200px] gap-2">
<img
alt="独立创客社区"
class="pointer-events-none aspect-square w-14 rounded-2xl object-cover select-none"
loading="lazy"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/demo1.jpg"
/>
<CardHeader>
<CardTitle>Indie Hackers</CardTitle>
<CardDescription>148 位成员</CardDescription>
</CardHeader>
<CardFooter class="flex gap-2">
<AvatarRoot
aria-label="玛莎的头像"
class="inline-flex shrink-0 overflow-hidden rounded-full size-5"
>
<AvatarImage
class="size-full object-cover"
alt="玛莎的头像"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg"
/>
<AvatarFallback
class="flex size-full items-center justify-center bg-default text-xs"
>
IH
</AvatarFallback>
</AvatarRoot>
<span class="text-xs">创建者:玛莎</span>
</CardFooter>
</Card>
<Card class="w-[200px] gap-2">
<img
alt="AI 开发者社区"
class="pointer-events-none aspect-square w-14 rounded-2xl object-cover select-none"
loading="lazy"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/demo2.jpg"
/>
<CardHeader>
<CardTitle>AI Builders</CardTitle>
<CardDescription>362 位成员</CardDescription>
</CardHeader>
<CardFooter class="flex gap-2">
<AvatarRoot
aria-label="约翰的头像"
class="inline-flex shrink-0 overflow-hidden rounded-full size-5"
>
<AvatarImage
class="size-full object-cover"
alt="约翰的头像"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg"
/>
<AvatarFallback
class="flex size-full items-center justify-center bg-default text-xs"
>
B
</AvatarFallback>
</AvatarRoot>
<span class="text-xs">创建者:约翰</span>
</CardFooter>
</Card>
</div>
</template>
+71
View File
@@ -0,0 +1,71 @@
<script setup lang="ts">
import {
Card,
CardHeader,
CardTitle,
CardDescription,
CardContent,
CardFooter,
Button,
} from "@heroui-vue/components";
import { Input, Label } from "@heroui-vue/components";
import { ref, useId } from "vue";
const id = useId();
const submitted = ref(false);
const message = ref("");
</script>
<template>
<Card class="w-full max-w-md">
<CardHeader>
<CardTitle>登录</CardTitle>
<CardDescription>输入账号信息以访问您的账户</CardDescription>
</CardHeader>
<form class="flex flex-col" @submit.prevent="submitted = true">
<CardContent>
<div class="flex flex-col gap-4">
<div class="flex flex-col gap-1">
<Label :for="id + '-email'">邮箱</Label>
<Input
:id="id + '-email'"
name="email"
type="email"
autocomplete="email"
placeholder="email@example.com"
variant="secondary"
required
/>
</div>
<div class="flex flex-col gap-1">
<Label :for="id + '-password'">密码</Label>
<Input
:id="id + '-password'"
name="password"
type="password"
autocomplete="current-password"
placeholder="••••••••"
variant="secondary"
required
/>
</div>
</div>
</CardContent>
<CardFooter class="mt-4 flex flex-col gap-2">
<Button class="w-full" type="submit">登录</Button>
<a
class="demo-link text-center text-sm"
href="#"
@click.prevent="message = '请联系账户管理员重置密码。'"
>
忘记密码?
</a>
</CardFooter>
<p
v-if="submitted || message"
role="status"
class="mt-2 text-sm text-muted"
>
{{ message || "表单提交成功!此示例不会发送账号信息。" }}
</p>
</form>
</Card>
</template>
+289
View File
@@ -0,0 +1,289 @@
<script setup lang="ts">
import { closeButtonVariants } from "@heroui-vue/styles";
import { IconArrowUpRight, IconX } from "@tabler/icons-vue";
import { IconCoin } from "@tabler/icons-vue";
import {
Card,
CardHeader,
CardTitle,
CardDescription,
CardContent,
CardFooter,
Button,
} from "@heroui-vue/components";
import { AvatarRoot, AvatarImage, AvatarFallback } from "reka-ui";
</script>
<template>
<div class="flex w-full items-center justify-center">
<div class="grid w-full max-w-2xl grid-cols-12 gap-4 p-4">
<Card class="col-span-12 flex h-auto min-h-[152px] flex-col sm:flex-row">
<div
class="relative h-[140px] w-full shrink-0 overflow-hidden rounded-2xl sm:h-[120px] sm:w-[120px]"
>
<img
alt="樱桃"
class="pointer-events-none absolute inset-0 h-full w-full scale-125 object-cover select-none"
loading="lazy"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/cherries.jpeg"
/>
</div>
<div class="flex flex-1 flex-col gap-3">
<CardHeader class="gap-1">
<CardTitle class="pe-8">成为 ACME 创作者!</CardTitle>
<CardDescription>
这是一段占位说明文字,用于展示横向卡片布局、配图与右上角关闭按钮的排版效果。
</CardDescription>
<button
type="button"
:class="closeButtonVariants()"
aria-label="关闭横幅"
class="absolute end-3 top-3"
>
<IconX aria-hidden="true" />
</button>
</CardHeader>
<CardFooter
class="mt-auto flex w-full flex-col items-start gap-3 sm:flex-row sm:items-center sm:justify-between"
>
<div class="flex flex-col">
<span class="text-sm font-medium text-foreground">
仅剩 10 个名额
</span>
<span class="text-xs text-muted">报名截止:10 月 10 日</span>
</div>
<Button class="w-full sm:w-auto">立即申请</Button>
</CardFooter>
</div>
</Card>
<div class="col-span-12 grid grid-cols-12 gap-4">
<div class="col-span-12 grid grid-cols-12 gap-4 lg:col-span-6">
<Card class="col-span-12">
<div class="absolute end-3 top-3 z-10">
<button
type="button"
:class="closeButtonVariants()"
aria-label="关闭通知"
>
<IconX aria-hidden="true" />
</button>
</div>
<CardHeader class="gap-3">
<IconCoin
role="img"
aria-label="美元图标"
class="size-8 shrink-0"
/>
<div class="flex flex-col gap-1">
<span class="text-xs font-medium text-muted uppercase">
支付
</span>
<CardTitle class="pe-8 text-sm sm:text-base">
现已支持加密货币提现
</CardTitle>
<CardDescription class="text-xs sm:text-sm">
在设置中添加钱包即可提现
</CardDescription>
</div>
</CardHeader>
<CardFooter>
<a
class="demo-link inline-flex items-center gap-1"
aria-label="前往设置"
href="#"
rel="noopener noreferrer"
>
前往设置
<IconArrowUpRight aria-hidden="true" class="size-3" />
</a>
</CardFooter>
</Card>
<div class="col-span-12 grid grid-cols-12 gap-4">
<Card class="col-span-12 gap-2 sm:col-span-6">
<CardHeader>
<AvatarRoot
class="inline-flex shrink-0 overflow-hidden rounded-full size-[56px] rounded-xl"
>
<AvatarImage
class="size-full object-cover"
alt="演示图片 1"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/demo1.jpg"
/>
<AvatarFallback
class="flex size-full items-center justify-center bg-default"
>
JK
</AvatarFallback>
</AvatarRoot>
</CardHeader>
<CardContent class="mt-1">
<p class="text-sm leading-4 font-medium">Indie Hackers</p>
<p class="text-xs text-muted">148 位成员</p>
</CardContent>
<CardFooter class="flex items-center gap-2">
<AvatarRoot
class="inline-flex shrink-0 overflow-hidden rounded-full size-4"
>
<AvatarImage
class="size-full object-cover"
alt="约翰"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg"
/>
<AvatarFallback
class="flex size-full items-center justify-center bg-default"
>
JK
</AvatarFallback>
</AvatarRoot>
<p class="text-xs text-muted">创建者:约翰</p>
</CardFooter>
</Card>
<Card class="col-span-12 gap-2 sm:col-span-6">
<CardHeader>
<AvatarRoot
class="inline-flex shrink-0 overflow-hidden rounded-full size-[56px] rounded-xl"
>
<AvatarImage
class="size-full object-cover"
alt="演示图片 2"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/demo2.jpg"
/>
<AvatarFallback
class="flex size-full items-center justify-center bg-default"
>
AB
</AvatarFallback>
</AvatarRoot>
</CardHeader>
<CardContent class="mt-1">
<p class="text-sm leading-4 font-medium">AI Builders</p>
<p class="text-xs text-muted">362 位成员</p>
</CardContent>
<CardFooter class="flex items-center gap-2">
<AvatarRoot
class="inline-flex shrink-0 overflow-hidden rounded-full size-4"
>
<AvatarImage
class="size-full object-cover"
alt="玛莎"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg"
/>
<AvatarFallback
class="flex size-full items-center justify-center bg-default"
>
M
</AvatarFallback>
</AvatarRoot>
<p class="text-xs text-muted">创建者:玛莎</p>
</CardFooter>
</Card>
</div>
</div>
<Card
class="col-span-12 min-h-[200px] overflow-hidden rounded-3xl lg:col-span-6"
>
<img
alt="NEO 家用机器人"
aria-hidden="true"
class="absolute inset-0 h-full w-full object-cover"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/neo2.jpeg"
/>
<CardHeader class="z-10 text-white">
<CardTitle
class="text-xs font-semibold tracking-wide text-black/70"
>
NEO
</CardTitle>
<CardDescription
class="text-sm leading-5 font-medium text-black/50"
>
家用机器人
</CardDescription>
</CardHeader>
<CardFooter class="z-10 mt-auto flex items-center justify-between">
<div>
<div class="text-sm font-medium text-black">即将推出</div>
<div class="text-xs text-black/60">接收上架通知</div>
</div>
<Button class="bg-white text-black" size="sm" variant="tertiary">
通知我
</Button>
</CardFooter>
</Card>
</div>
<div class="col-span-12 grid grid-cols-12 gap-4">
<Card
class="relative col-span-12 h-[250px] sm:h-[300px] md:col-span-8 md:h-[350px]"
>
<img
alt="NEO 家用机器人"
aria-hidden="true"
class="absolute inset-0 h-full w-full object-cover"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/neo1.jpeg"
/>
<CardFooter class="z-10 mt-auto flex items-end justify-between">
<div>
<div class="text-base font-medium text-black sm:text-lg">NEO</div>
<div class="text-xs font-medium text-black/50 sm:text-sm">
$499/月
</div>
</div>
<Button class="bg-white text-black" size="sm" variant="tertiary">
立即购买
</Button>
</CardFooter>
</Card>
<div
class="col-span-12 flex flex-col gap-2 md:col-span-4 md:justify-between md:gap-0 md:py-2"
>
<Card class="flex flex-row gap-3 p-1" variant="transparent">
<img
alt="未来感机器人"
class="aspect-square h-16 w-16 shrink-0 rounded-xl object-cover select-none sm:h-20 sm:w-20"
loading="lazy"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/robot1.jpeg"
/>
<div class="flex flex-1 flex-col justify-center gap-1">
<CardTitle class="text-sm">连接未来</CardTitle>
<CardDescription class="text-xs">今天 18:30</CardDescription>
</div>
</Card>
<Card class="flex flex-row gap-3 p-1" variant="transparent">
<img
alt="牛油果"
class="aspect-square h-16 w-16 shrink-0 rounded-xl object-cover select-none sm:h-20 sm:w-20"
loading="lazy"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/avocado.jpeg"
/>
<div class="flex flex-1 flex-col justify-center gap-1">
<CardTitle class="text-sm">牛油果黑客松</CardTitle>
<CardDescription class="text-xs">周三 16:30</CardDescription>
</div>
</Card>
<Card class="flex flex-row gap-3 p-1" variant="transparent">
<img
alt="Sound Electro 活动"
class="aspect-square h-16 w-16 shrink-0 rounded-xl object-cover select-none sm:h-20 sm:w-20"
loading="lazy"
src="https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/oranges.jpeg"
/>
<div class="flex flex-1 flex-col justify-center gap-1">
<CardTitle class="text-sm">Sound Electro|超越艺术</CardTitle>
<CardDescription class="text-xs">周五 20:00</CardDescription>
</div>
</Card>
</div>
</div>
</div>
</div>
</template>
+6
View File
@@ -0,0 +1,6 @@
<script setup lang="ts">
import { Input } from "@heroui-vue/components";
</script>
<template>
<Input aria-label="姓名" class="w-64" placeholder="输入你的姓名" />
</template>
+13
View File
@@ -0,0 +1,13 @@
<script setup lang="ts">
import { Input } from "@heroui-vue/components";
import { ref } from "vue";
const value = ref("heroui.com");
</script>
<template>
<div class="flex w-80 flex-col gap-2">
<Input v-model="value" aria-label="域名" placeholder="域名" />
<span class="px-1 text-sm text-muted">
https://{{ value || "你的域名" }}
</span>
</div>
</template>
+10
View File
@@ -0,0 +1,10 @@
<script setup lang="ts">
import { Input } from "@heroui-vue/components";
</script>
<template>
<Input
aria-label="搜索项目"
class="w-64 rounded-xl border border-border/80 bg-default text-foreground placeholder:text-muted"
placeholder="搜索项目…"
/>
</template>
+8
View File
@@ -0,0 +1,8 @@
<script setup lang="ts">
import { Input } from "@heroui-vue/components";
</script>
<template>
<div class="w-[400px] space-y-3">
<Input full-width aria-label="全宽输入框" placeholder="全宽输入框" />
</div>
</template>
+15
View File
@@ -0,0 +1,15 @@
<script setup lang="ts">
import { Input } from "@heroui-vue/components";
</script>
<template>
<div
class="flex h-[180px] w-[280px] items-center justify-center rounded-3xl bg-surface p-4"
>
<Input
class="w-full"
aria-label="你的姓名"
placeholder="你的姓名"
variant="secondary"
/>
</div>
</template>
+21
View File
@@ -0,0 +1,21 @@
<script setup lang="ts">
import { Input, Label } from "@heroui-vue/components";
import { useId } from "vue";
const id = useId();
</script>
<template>
<div class="flex w-80 flex-col gap-4">
<div class="flex flex-col gap-1">
<Label :for="id + '-email'">邮箱</Label>
<Input :id="id + '-email'" placeholder="jane@example.com" type="email" />
</div>
<div class="flex flex-col gap-1">
<Label :for="id + '-number'">年龄</Label>
<Input :id="id + '-number'" :min="0" placeholder="30" type="number" />
</div>
<div class="flex flex-col gap-1">
<Label :for="id + '-password'">密码</Label>
<Input :id="id + '-password'" placeholder="••••••••" type="password" />
</div>
</div>
</template>
+19
View File
@@ -0,0 +1,19 @@
<script setup lang="ts">
import { Input } from "@heroui-vue/components";
</script>
<template>
<div class="flex w-[240px] flex-col gap-2">
<Input
full-width
aria-label="主要输入框"
placeholder="主要输入框"
variant="primary"
/>
<Input
full-width
aria-label="次要输入框"
placeholder="次要输入框"
variant="secondary"
/>
</div>
</template>
+18
View File
@@ -0,0 +1,18 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
} from "@heroui-vue/components";
</script>
<template>
<Switch>
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
启用通知
</SwitchContent>
</Switch>
</template>
+21
View File
@@ -0,0 +1,21 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
} from "@heroui-vue/components";
import { ref } from "vue";
const selected = ref(false);
</script>
<template>
<div class="flex flex-col gap-4">
<Switch v-model:checked="selected">
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
启用通知
</SwitchContent>
</Switch>
<p class="text-sm text-muted">开关{{ selected ? "已打开" : "已关闭" }}</p>
</div>
</template>
+25
View File
@@ -0,0 +1,25 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
Label,
Description,
} from "@heroui-vue/components";
</script>
<template>
<Switch>
<SwitchContent>
<SwitchControl
class="[--switch-control-bg-checked-hover:var(--success)] [--switch-control-bg-checked:var(--success)]"
>
<SwitchThumb />
</SwitchControl>
<div class="flex flex-col gap-0.5">
<Label>自动保存草稿</Label>
<Description>输入时会自动保存更改。</Description>
</div>
</SwitchContent>
</Switch>
</template>
@@ -0,0 +1,18 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
} from "@heroui-vue/components";
</script>
<template>
<Switch default-selected>
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
启用通知
</SwitchContent>
</Switch>
</template>
+18
View File
@@ -0,0 +1,18 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
} from "@heroui-vue/components";
</script>
<template>
<Switch is-disabled>
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
启用通知
</SwitchContent>
</Switch>
</template>
+57
View File
@@ -0,0 +1,57 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
SwitchGroup,
Button,
} from "@heroui-vue/components";
import { ref } from "vue";
const result = ref("");
function submit(event: Event) {
const values = [...new FormData(event.target as HTMLFormElement).entries()];
result.value = values.length
? "表单提交内容:" + values.map(([k, v]) => `${k}: ${v}`).join(",")
: "未选择任何选项";
}
</script>
<template>
<form class="flex flex-col gap-4" @submit.prevent="submit">
<SwitchGroup>
<Switch name="notifications" value="on">
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
启用通知
</SwitchContent>
</Switch>
<Switch default-selected name="newsletter" value="on">
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
订阅新闻简报
</SwitchContent>
</Switch>
<Switch name="marketing" value="on">
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
接收营销更新
</SwitchContent>
</Switch>
</SwitchGroup>
<div class="flex gap-2">
<Button class="mt-4" size="sm" type="submit">Submit</Button>
<Button
class="mt-4"
size="sm"
type="reset"
variant="secondary"
@click="result = ''"
>
重置
</Button>
</div>
<output v-if="result" class="text-sm text-muted" aria-live="polite">
{{ result }}
</output>
</form>
</template>
@@ -0,0 +1,37 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
SwitchGroup,
} from "@heroui-vue/components";
</script>
<template>
<SwitchGroup class="overflow-x-auto" orientation="horizontal">
<Switch name="notifications">
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
通知
</SwitchContent>
</Switch>
<Switch name="marketing">
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
营销
</SwitchContent>
</Switch>
<Switch name="social">
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
社交
</SwitchContent>
</Switch>
</SwitchGroup>
</template>
+37
View File
@@ -0,0 +1,37 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
SwitchGroup,
} from "@heroui-vue/components";
</script>
<template>
<SwitchGroup>
<Switch name="notifications">
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
允许通知
</SwitchContent>
</Switch>
<Switch name="marketing">
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
营销邮件
</SwitchContent>
</Switch>
<Switch name="social">
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
社交媒体更新
</SwitchContent>
</Switch>
</SwitchGroup>
</template>
+28
View File
@@ -0,0 +1,28 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
} from "@heroui-vue/components";
</script>
<template>
<div class="flex flex-col gap-4">
<Switch>
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
标签在后
</SwitchContent>
</Switch>
<Switch>
<SwitchContent>
标签在前
<SwitchControl>
<SwitchThumb />
</SwitchControl>
</SwitchContent>
</Switch>
</div>
</template>
@@ -0,0 +1,18 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
} from "@heroui-vue/components";
</script>
<template>
<Switch as-child>
<div data-custom="foo">
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
启用通知
</SwitchContent>
</div>
</Switch>
</template>
+16
View File
@@ -0,0 +1,16 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
} from "@heroui-vue/components";
</script>
<template>
<Switch v-slot="{ isSelected }">
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
{{ isSelected ? "已开启" : "已关闭" }}
</SwitchContent>
</Switch>
</template>
+36
View File
@@ -0,0 +1,36 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
} from "@heroui-vue/components";
</script>
<template>
<div class="flex gap-6">
<Switch size="sm">
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
小
</SwitchContent>
</Switch>
<Switch size="md">
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
中
</SwitchContent>
</Switch>
<Switch size="lg">
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
大
</SwitchContent>
</Switch>
</div>
</template>
@@ -0,0 +1,22 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
Description,
} from "@heroui-vue/components";
</script>
<template>
<div class="max-w-sm">
<Switch>
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
公开资料
</SwitchContent>
<Description>允许他人查看你的资料信息</Description>
</Switch>
</div>
</template>
+79
View File
@@ -0,0 +1,79 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
SwitchIcon,
} from "@heroui-vue/components";
import {
IconCheck,
IconPower,
IconSun,
IconMoon,
IconMicrophone,
IconMicrophoneOff,
IconBellFilled,
IconBellOff,
IconVolume,
IconVolumeOff,
} from "@tabler/icons-vue";
const icons = [
{
key: "check",
label: "电源",
color: "bg-green-500/80",
on: IconCheck,
off: IconPower,
},
{ key: "darkMode", label: "深色模式", color: "", on: IconSun, off: IconMoon },
{
key: "microphone",
label: "静音麦克风",
color: "bg-red-500/80",
on: IconMicrophoneOff,
off: IconMicrophone,
},
{
key: "notification",
label: "通知",
color: "bg-purple-500/80",
on: IconBellFilled,
off: IconBellOff,
},
{
key: "volume",
label: "静音音量",
color: "bg-blue-500/80",
on: IconVolumeOff,
off: IconVolume,
},
];
</script>
<template>
<div class="flex flex-wrap gap-3">
<Switch
v-for="item in icons"
:key="item.key"
default-selected
size="lg"
:aria-label="item.label"
v-slot="{ isSelected }"
>
<SwitchContent>
<SwitchControl :class="isSelected ? item.color : ''">
<SwitchThumb>
<SwitchIcon>
<component
:is="isSelected ? item.on : item.off"
class="size-3 text-inherit"
:class="isSelected ? 'opacity-100' : 'opacity-70'"
aria-hidden="true"
/>
</SwitchIcon>
</SwitchThumb>
</SwitchControl>
</SwitchContent>
</Switch>
</div>
</template>
+17
View File
@@ -0,0 +1,17 @@
<script setup lang="ts">
import {
Switch,
SwitchContent,
SwitchControl,
SwitchThumb,
} from "@heroui-vue/components";
</script>
<template>
<Switch aria-label="启用通知">
<SwitchContent>
<SwitchControl>
<SwitchThumb />
</SwitchControl>
</SwitchContent>
</Switch>
</template>
+65
View File
@@ -0,0 +1,65 @@
---
title: 安装
description: 在 Vue 项目中开始使用 HeroUI Vue
---
## 本地开发
包尚未发布,目前通过独立工作区开发和使用。
```sh
pnpm install
pnpm build
pnpm dev:docs
```
## 使用组件
```vue
<script setup lang="ts">
import { Button } from "@heroui-vue/components";
import "@heroui-vue/styles/css";
</script>
<template>
<Button>点我</Button>
</template>
```
## 图标
文档示例统一使用 [Tabler Icons 官方 Vue 包](https://github.com/tabler/tabler-icons/tree/main/packages/icons-vue),按需导入,不需要在线请求图标。
```sh
pnpm add @tabler/icons-vue
```
```vue
<script setup lang="ts">
import { IconSearch } from "@tabler/icons-vue";
import { Button } from "@heroui-vue/components";
</script>
<template>
<Button>
<IconSearch aria-hidden="true" />
搜索
</Button>
</template>
```
纯图标按钮必须提供 `aria-label`。图标库是演示应用依赖,组件库通过插槽接受任意图标,不强制消费者安装 Tabler。
## 样式入口
样式包使用 Tailwind CSS 4 编译基线 CSS,向消费者提供预编译 CSS。消费者不需要安装 Tailwind;自定义工具类需要在自己的应用中配置 Tailwind。
## 开发命令
| 命令 | 功能 |
| -------------- | --------------- |
| pnpm dev | 组件实验页 |
| pnpm dev:docs | 组件文档 |
| pnpm build | 库与样式构建 |
| pnpm typecheck | Vue 类型检查 |
| pnpm test | 行为与 SSR 测试 |
+142
View File
@@ -0,0 +1,142 @@
---
title: Button 按钮
description: 可点击的按钮组件,支持多种变体与状态
component: button
group: 组件
---
## 用法
```vue
<script setup lang="ts">
import { Button } from "@heroui-vue/components";
</script>
```
<ComponentPreview name="button-basic" />
## 示例
### 变体
<ComponentPreview name="button-variants" />
### 尺寸
<ComponentPreview name="button-sizes" />
### 带图标
<ComponentPreview name="button-with-icons" />
### 仅图标
<ComponentPreview name="button-icon-only" />
### 加载中
此例固定展示上传中的外观;加载期间阻止重复提交,但保留键盘焦点。要体验开始、完成和再次上传,请使用下一例。
<ComponentPreview name="button-loading" />
### 加载中(点击触发)
点击“上传文件”后进入加载状态,2 秒后恢复,可重复操作。
<ComponentPreview name="button-loading-state" />
### 宽度充满
<ComponentPreview name="button-full-width" />
### 禁用状态
<ComponentPreview name="button-disabled" />
### 社交媒体按钮
<ComponentPreview name="button-social" />
### 渲染函数
Vue 使用 `asChild` 将按钮属性与交互合并到一个自定义原生 button,作用域插槽提供状态。对应上游 render 函数示例,不将 render prop 原样搬入 Vue。
<ComponentPreview name="button-render-function" />
### 添加自定义变体
可通过包装组件并添加自定义变体来扩展组件。下面使用与上游相同的 `tv` 扩展方式,提供额外的圆角与尺寸配置。
<ComponentPreview name="button-custom-variants" />
### 添加涟漪效果
通过组合添加涟漪。本示例使用 Vue 和 CSS 实现,支持指针、Enter 和空格触发;不直接依赖上游 React 的 m3-ripple,减少动态效果时缩短动画。
<ComponentPreview name="button-ripple-effect" />
## 自定义样式
### Tailwind CSS
<ComponentPreview name="button-custom-styles" />
使用标准 `class` 属性添加工具类。组件保持上游的尺寸、间距、BEM 结构与状态钩子;类名前缀改为 `hv-`。
```vue
<Button class="rounded-lg">自定义圆角</Button>
```
### 全局 CSS
```css
@layer components {
.hv-button--primary {
--button-bg: oklch(0.6 0.2 300);
}
}
```
## 样式参考
基础类为 `.hv-button`,变体为 `.hv-button--primary` 等;尺寸为 `.hv-button--sm` / `md` / `lg`。支持 `.hv-button--icon-only` 和 `.hv-button--full-width`。
### 交互状态
保留 `data-hovered`、`data-pressed`、`data-focused`、`data-focus-visible`、`data-pending` 状态;键盘焦点样式与鼠标焦点区分。加载期间保留焦点并阻止重复点击,通过 aria-disabled 呈现半透明的原变体颜色。
## API 参考
### Button
| Prop | 类型 | 默认值 | 描述 |
| ------------ | --------------------------------------------------------------------------------------------- | ----------- | --------------------------------------------- |
| `variant` | `'primary' \| 'secondary' \| 'tertiary' \| 'outline' \| 'ghost' \| 'danger' \| 'danger-soft'` | `'primary'` | 视觉样式变体 |
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | 按钮尺寸 |
| `fullWidth` | `boolean` | `false` | 是否占满容器宽度 |
| `isDisabled` | `boolean` | `false` | 是否禁用 |
| `isPending` | `boolean` | `false` | 是否处于加载状态 |
| `isIconOnly` | `boolean` | `false` | 是否仅包含图标 |
| `asChild` | `boolean` | `false` | 将属性与交互合并到默认插槽中唯一的原生 button |
| `type` | `'button' \| 'submit' \| 'reset'` | `'button'` | 原生按钮类型 |
### 事件与插槽
Vue 使用 `@click` 和默认作用域插槽。插槽提供 `isPending`、`isPressed`、`isHovered`、`isFocused`、`isFocusVisible`、`isDisabled`。原生属性、class、style、事件透传至 button。
`onPress` / PressEvent 与 `@click` 的事件模型不同,不宣称完全等价。初版 `disabled` / `loading` 继续作为兼容别名;新代码使用 `isDisabled` / `isPending`。`isPending` 不自动插入加载图标,采用上游的组合方式。`loading` 是相同加载语义的兼容别名,额外自动显示旋转图标;不会设置原生 disabled。`asChild` 下内容由调用者完整组合,默认插槽必须只包含一个原生 button。
### 作用域插槽状态
| 参数 | 类型 | 描述 |
| ---------------- | --------- | -------------------------------- |
| `isPending` | `boolean` | 是否处于加载状态 |
| `isPressed` | `boolean` | 是否正在按下 |
| `isHovered` | `boolean` | 是否悬停 |
| `isFocused` | `boolean` | 是否聚焦 |
| `isFocusVisible` | `boolean` | 是否显示键盘焦点指示器 |
| `isDisabled` | `boolean` | 是否由禁用属性禁用,不与加载混用 |
## 相关组件
[Card 卡片](/components/card) · [Input 输入框](/components/input) · [Switch 开关](/components/switch)
+22
View File
@@ -0,0 +1,22 @@
---
title: 介绍
description: 美观、现代的 Vue UI 组件库
---
## 设计原则
以固定提交的 HeroUI v3.2.6 为设计基线,保持组件的样式、布局、文案、变体、参数语义和主题高度一致。仅在框架机制要求时转换事件、插槽、响应式状态与部件导出方式。
## 当前范围
已迁移 Button、Card、Input、Switch 的主要视觉和组合结构,仍需完整视觉与交互验收。左侧导航只列出实际存在的组件,未迁移的组件不以占位演示代替。
## Vue 差异
- `className` → `class`。
- 函数 children → 作用域插槽。
- `Card.Header` → `CardHeader` 等独立导出。
- Input 使用 `v-model`;Switch 使用 `v-model:checked`,保留 isSelected 等上游语义属性。
- 框架专属的 PressEvent 与原生 click 不声明等价。
具体未覆盖能力在各组件 API 页说明。此项目为独立社区实现,不是官方 Vue 发行版。
+21
View File
@@ -0,0 +1,21 @@
{
"name": "@heroui-vue/docs",
"private": true,
"type": "module",
"scripts": {
"dev": "vitepress dev",
"build": "vitepress build"
},
"devDependencies": {
"@tailwindcss/vite": "^4.1.0",
"tailwindcss": "^4.1.0",
"vitepress": "^1.6.4"
},
"dependencies": {
"@heroui-vue/components": "workspace:*",
"@heroui-vue/styles": "workspace:*",
"@tabler/icons-vue": "^3.49.0",
"reka-ui": "^2.11.0",
"vue": "^3.5.44"
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
+53
View File
@@ -0,0 +1,53 @@
---
title: 主题
description: 使用与 HeroUI 相同的语义变量定制组件外观
---
## 默认主题
浅色和深色变量移植自固定基线的 default/variables.css,采用相同的 OKLCH 颜色与派生公式。按钮、表面、输入框和开关共同使用这些变量。
## 浅色与深色
文档右上角切换主题,页面与组件同步更新。应用支持 `.light`、`.dark`、`data-theme="light"` 与 `data-theme="dark"`。
```html
<html class="dark"></html>
```
## 语义颜色
| 变量 | 用途 |
| ------------------------------------------------------------- | ------------------ |
| --background / --foreground | 页面背景与正文 |
| --surface / --surface-secondary / --surface-tertiary | 分层表面 |
| --accent / --accent-foreground | 主要操作与选中状态 |
| --default / --default-foreground | 默认控件背景与文字 |
| --muted | 次要文本 |
| --danger / --danger-foreground | 危险操作与无效状态 |
| --field-background / --field-foreground / --field-placeholder | 表单输入 |
| --border / --separator / --focus | 边界、分隔和焦点 |
## 自定义主题
```css
[data-theme="brand"] {
--accent: oklch(0.62 0.2 300);
--accent-foreground: oklch(0.99 0 0);
--radius: 0.75rem;
}
```
```html
<section class="light" data-theme="brand">...</section>
```
将上述样式放在库样式之后,覆盖容器变量。嵌套容器加上 light 或 dark,使派生颜色在该容器重新计算。浅深自定义主题应分别声明值;应用继承基线的派生颜色与阴影公式。
## 圆角与阴影
默认 `--radius: 0.5rem`,`--field-radius: calc(var(--radius) * 1.5)`。Card 使用 `min(32px, var(--radius-3xl))`,Button 使用 3xl 圆角。不要为不同页面独立设置近似圆角或品牌蓝。
## 动效
支持 prefers-reduced-motion 和 data-reduce-motion 状态。保留基线的 hover、press、focus 与过渡时间。
+12
View File
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>HeroUI Vue · 组件实验室</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
+18
View File
@@ -0,0 +1,18 @@
{
"name": "@heroui-vue/playground",
"private": true,
"type": "module",
"scripts": {
"dev": "vite --host 127.0.0.1",
"build": "vite build"
},
"dependencies": {
"@heroui-vue/components": "workspace:*",
"@heroui-vue/styles": "workspace:*",
"vue": "^3.5.44"
},
"devDependencies": {
"@tailwindcss/vite": "^4.1.0",
"tailwindcss": "^4.1.0"
}
}
+143
View File
@@ -0,0 +1,143 @@
<script setup lang="ts">
import { ref } from "vue";
import { Button, Card, Input, Switch } from "@heroui-vue/components";
const dark = ref(false),
notifications = ref(true),
name = ref("设计团队"),
saved = ref(false),
count = ref(0);
function save() {
saved.value = true;
}
</script>
<template>
<div class="lab" :data-theme="dark ? 'dark' : 'light'">
<header>
<a class="wordmark" href="#">
hero
<span>ui</span>
<small>Vue</small>
</a>
<nav>
<a href="#components">组件预览</a>
<a href="#start">开始使用</a>
</nav>
<label class="theme">
深色模式
<Switch v-model:checked="dark" aria-label="深色模式" />
</label>
</header>
<main>
<section class="intro">
<p class="release">Vue 3 组件库 · 开发预览</p>
<h1>
熟悉的设计,
<br />
自然的 Vue 体验。
</h1>
<p class="lead">
从一颗按钮开始,让每一个细节都有章可循。
<br />
在这里试试第一批组件。
</p>
<a class="text-link" href="#components">探索组件 ↓</a>
</section>
<section id="components" class="workbench">
<div class="section-title">
<h2>组件实验室</h2>
<span>4 个组件 · 起步阶段</span>
</div>
<div class="grid">
<Card class="button-demo">
<div class="demo-title">
<h3>Button</h3>
<span>动作与反馈</span>
</div>
<div class="samples">
<Button @click="count++">
点击试试
<span aria-live="polite">{{ count }}</span>
</Button>
<Button variant="secondary">次要操作</Button>
<Button variant="outline">描边按钮</Button>
<Button variant="ghost">轻量操作</Button>
<Button variant="danger">危险操作</Button>
<Button disabled>不可用</Button>
</div>
<p class="caption">圆角、尺寸、状态,保持一致的触感。</p>
</Card>
<Card>
<div class="demo-title">
<h3>工作区设置</h3>
<span>Input + Switch</span>
</div>
<form @submit.prevent="save">
<label class="field">
工作区名称
<Input
v-model="name"
name="workspace"
required
@input="saved = false"
/>
</label>
<div class="setting">
<div>
<label for="notifications">活动通知</label>
<p>接收工作区的重要更新</p>
</div>
<Switch
id="notifications"
v-model:checked="notifications"
name="notifications"
/>
</div>
<Button type="submit" full-width>保存设置</Button>
<p class="feedback" role="status">
{{
saved
? `已保存「${name}」的设置`
: "修改后点击保存,试试双向绑定。"
}}
</p>
</form>
</Card>
<Card variant="secondary" class="card-demo">
<div class="demo-title">
<h3>Card</h3>
<span>内容的容器</span>
</div>
<div class="swatches">
<i />
<i />
<i />
<i />
</div>
<h4>
为你的下一次创作
<br />
留一块画布。
</h4>
<p>主题变量与组件样式独立维护,让定制从容一点。</p>
<Button variant="outline" @click="dark = !dark">切换主题</Button>
</Card>
</div>
</section>
<section id="start" class="start">
<div>
<h2>从这里开始</h2>
<p>本地开发预览,组件仍在持续完善。</p>
</div>
<code>
pnpm install
<br />
pnpm dev
</code>
</section>
<footer>
<span>HeroUI Vue · 独立社区实现</span>
<span>以 HeroUI v3 为设计参考</span>
</footer>
</main>
</div>
</template>
+4
View File
@@ -0,0 +1,4 @@
import { createApp } from "vue";
import App from "./App.vue";
import "./style.css";
createApp(App).mount("#app");
+295
View File
@@ -0,0 +1,295 @@
@import "tailwindcss";
@import "../../../packages/styles/dist/styles.css";
* {
box-sizing: border-box;
}
html {
scroll-behavior: smooth;
}
body {
margin: 0;
font-family: "Avenir Next", "Segoe UI", "PingFang SC", sans-serif;
}
button,
input {
font: inherit;
}
a {
color: inherit;
text-decoration: none;
}
.lab {
min-height: 100vh;
background: var(--background);
color: var(--foreground);
transition:
background 0.2s,
color 0.2s;
}
header {
max-width: 1240px;
margin: auto;
padding: 28px 48px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
border-bottom: 1px solid var(--border);
}
.wordmark {
font-weight: 800;
font-size: 26px;
letter-spacing: -1.4px;
}
.wordmark span {
color: var(--accent);
}
.wordmark small {
font-size: 12px;
letter-spacing: 0;
font-weight: 600;
padding: 4px 8px;
border-radius: 6px;
background: var(--default);
margin-left: 8px;
}
nav {
display: flex;
gap: 30px;
font-size: 14px;
}
.theme {
display: flex;
gap: 12px;
align-items: center;
font-size: 13px;
color: var(--muted);
}
main {
max-width: 1240px;
margin: auto;
padding: 0 48px;
}
.intro {
padding: 70px 0 64px;
}
.release {
font-size: 14px;
color: var(--muted);
margin: 0 0 22px;
}
h1 {
font-size: clamp(40px, 5.4vw, 68px);
font-weight: 650;
line-height: 1.18;
letter-spacing: -2.5px;
margin: 0 0 22px;
}
.lead {
font-size: 17px;
line-height: 1.9;
color: var(--muted);
}
.text-link {
display: inline-block;
color: var(--accent);
font-weight: 600;
font-size: 14px;
margin-top: 16px;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 22px;
}
.section-title h2,
.start h2 {
font-size: 22px;
font-weight: 600;
letter-spacing: -0.6px;
}
.section-title span,
.demo-title span {
font-size: 12px;
color: var(--muted);
}
.grid {
display: grid;
grid-template-columns: 1.1fr 1fr 0.9fr;
gap: 18px;
}
.demo-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 28px;
}
.demo-title h3 {
font-size: 15px;
font-weight: 650;
margin: 0;
}
.samples {
display: flex;
flex-wrap: wrap;
gap: 12px;
padding-top: 10px;
}
.caption {
font-size: 12px;
line-height: 1.8;
color: var(--muted);
margin: 30px 0 0;
}
.field {
display: grid;
gap: 10px;
font-size: 13px;
}
.setting {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 24px 0;
}
.setting label {
font-size: 14px;
}
.setting p {
font-size: 12px;
color: var(--muted);
margin: 6px 0 0;
}
.feedback {
font-size: 12px;
color: var(--muted);
min-height: 32px;
line-height: 1.6;
margin-bottom: 0;
}
.swatches {
display: flex;
margin: 8px 0 26px;
}
.swatches i {
display: block;
width: 45px;
height: 45px;
border-radius: 50%;
border: 3px solid var(--default);
margin-right: -9px;
background: #006fee;
}
.swatches i:nth-child(2) {
background: #86b8ff;
}
.swatches i:nth-child(3) {
background: #bba7f7;
}
.swatches i:nth-child(4) {
background: #f4b0c7;
}
.card-demo h4 {
font-size: 24px;
line-height: 1.4;
font-weight: 600;
letter-spacing: -0.7px;
margin: 0 0 14px;
}
.card-demo p {
font-size: 13px;
line-height: 1.8;
color: var(--muted);
margin-bottom: 22px;
}
.start {
margin-top: 56px;
padding: 30px 0;
display: flex;
justify-content: space-between;
align-items: center;
border-top: 1px solid var(--border);
gap: 24px;
}
.start h2 {
margin: 0 0 10px;
}
.start p {
font-size: 14px;
color: var(--muted);
}
.start code {
min-width: 280px;
background: var(--default);
border-radius: 12px;
padding: 20px 26px;
font-size: 13px;
line-height: 2;
}
footer {
display: flex;
justify-content: space-between;
gap: 20px;
padding: 24px 0 30px;
font-size: 12px;
color: var(--muted);
}
@media (max-width: 1000px) {
.grid {
grid-template-columns: 1fr 1fr;
}
.card-demo {
grid-column: 1/-1;
}
.card-demo h4 br {
display: none;
}
}
@media (max-width: 640px) {
header {
padding: 20px 22px;
}
nav {
display: none;
}
.theme {
font-size: 12px;
}
main {
padding: 0 22px;
}
.intro {
padding: 50px 0;
}
h1 {
letter-spacing: -1.5px;
}
.grid {
grid-template-columns: 1fr;
}
.section-title span {
font-size: 11px;
}
.start {
align-items: stretch;
flex-direction: column;
}
.start code {
min-width: 0;
}
footer {
flex-direction: column;
gap: 8px;
}
}
@media (prefers-reduced-motion: reduce) {
html {
scroll-behavior: auto;
}
.lab {
transition: none;
}
}
+17
View File
@@ -0,0 +1,17 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import tailwindcss from "@tailwindcss/vite";
import { fileURLToPath, URL } from "node:url";
export default defineConfig({
plugins: [vue(), tailwindcss()],
resolve: {
alias: {
"@heroui-vue/components": fileURLToPath(
new URL("../../packages/vue/src/index.ts", import.meta.url),
),
"@heroui-vue/styles": fileURLToPath(
new URL("../../packages/styles/src/index.ts", import.meta.url),
),
},
},
});