feat: add Surface, Link and Spinner components

This commit is contained in:
maoyingjie
2026-10-21 13:04:06 +08:00
parent 9d40dc0ecb
commit 630963c652
52 changed files with 2683 additions and 162 deletions
+2 -12
View File
@@ -1,8 +1,7 @@
<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";
import { Button, Spinner } from "@heroui-vue/components";
const isLoading = ref(false),
message = ref("");
let timer: ReturnType<typeof setTimeout> | undefined;
@@ -20,16 +19,7 @@ onBeforeUnmount(() => clearTimeout(timer));
<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>
<Spinner v-if="isLoading" color="current" size="sm" />
<IconPaperclip v-else aria-hidden="true" />
{{ isLoading ? "上传中…" : "上传文件" }}
</Button>
+2 -10
View File
@@ -1,17 +1,9 @@
<script setup lang="ts">
import { IconLoader2 } from "@tabler/icons-vue";
import { Button } from "@heroui-vue/components";
import { Button, Spinner } 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>
<Spinner v-if="isPending" color="current" size="sm" />
上传中…
</Button>
</template>
+5 -5
View File
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { IconArrowUpRight } from "@tabler/icons-vue";
import { IconCoin } from "@tabler/icons-vue";
import {
Card,
@@ -7,6 +6,8 @@ import {
CardTitle,
CardDescription,
CardFooter,
Link,
LinkIcon,
} from "@heroui-vue/components";
</script>
<template>
@@ -19,16 +20,15 @@ import {
</CardDescription>
</CardHeader>
<CardFooter>
<a
class="demo-link inline-flex items-center gap-1"
<Link
aria-label="前往 Acme 创作者中心(在新标签页打开)"
href="https://heroui.com"
rel="noopener noreferrer"
target="_blank"
>
创作者中心
<IconArrowUpRight aria-hidden="true" class="size-3" />
</a>
<LinkIcon aria-hidden="true" />
</Link>
</CardFooter>
</Card>
</template>
+4 -3
View File
@@ -7,6 +7,7 @@ import {
CardContent,
CardFooter,
Button,
Link,
} from "@heroui-vue/components";
import { Input, Label } from "@heroui-vue/components";
import { ref, useId } from "vue";
@@ -51,13 +52,13 @@ const message = ref("");
</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"
<Link
class="text-center text-sm"
href="#"
@click.prevent="message = '请联系账户管理员重置密码。'"
>
忘记密码?
</a>
</Link>
</CardFooter>
<p
v-if="submitted || message"
+6 -9
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { closeButtonVariants } from "@heroui-vue/styles";
import { IconArrowUpRight, IconX } from "@tabler/icons-vue";
import { IconX } from "@tabler/icons-vue";
import { IconCoin } from "@tabler/icons-vue";
import {
Card,
@@ -10,6 +10,8 @@ import {
CardContent,
CardFooter,
Button,
Link,
LinkIcon,
} from "@heroui-vue/components";
import { AvatarRoot, AvatarImage, AvatarFallback } from "reka-ui";
</script>
@@ -87,15 +89,10 @@ import { AvatarRoot, AvatarImage, AvatarFallback } from "reka-ui";
</div>
</CardHeader>
<CardFooter>
<a
class="demo-link inline-flex items-center gap-1"
aria-label="前往设置"
href="#"
rel="noopener noreferrer"
>
<Link aria-label="前往设置" href="#" rel="noopener noreferrer">
前往设置
<IconArrowUpRight aria-hidden="true" class="size-3" />
</a>
<LinkIcon aria-hidden="true" />
</Link>
</CardFooter>
</Card>
+5 -4
View File
@@ -1,9 +1,10 @@
<script setup lang="ts">
import { Input } from "@heroui-vue/components";
import { Input, Surface } from "@heroui-vue/components";
</script>
<template>
<div
class="flex h-[180px] w-[280px] items-center justify-center rounded-3xl bg-surface p-4"
<Surface
class="flex h-[180px] w-[280px] items-center justify-center rounded-3xl p-4"
variant="default"
>
<Input
class="w-full"
@@ -11,5 +12,5 @@ import { Input } from "@heroui-vue/components";
placeholder="你的姓名"
variant="secondary"
/>
</div>
</Surface>
</template>
+9
View File
@@ -0,0 +1,9 @@
<script setup lang="ts">
import { Link, LinkIcon } from "@heroui-vue/components";
</script>
<template>
<Link href="#">
立即行动
<LinkIcon />
</Link>
</template>
+20
View File
@@ -0,0 +1,20 @@
<script setup lang="ts">
import { IconExternalLink, IconLink } from "@tabler/icons-vue";
import { Link, LinkIcon } from "@heroui-vue/components";
</script>
<template>
<div class="flex flex-col gap-3">
<Link href="#">
外部链接
<LinkIcon class="ms-1.5 size-3">
<IconExternalLink aria-hidden="true" class="size-full" />
</LinkIcon>
</Link>
<Link class="gap-1" href="#">
前往页面
<LinkIcon class="size-3">
<IconLink aria-hidden="true" class="size-full" />
</LinkIcon>
</Link>
</div>
</template>
+12
View File
@@ -0,0 +1,12 @@
<script setup lang="ts">
import { Link, LinkIcon } from "@heroui-vue/components";
</script>
<template>
<Link
class="font-medium text-neutral-700 underline decoration-neutral-300/80 underline-offset-4 transition-colors hover:text-neutral-900 dark:text-neutral-300 dark:decoration-neutral-600/80 dark:hover:text-neutral-100"
href="#"
>
立即行动
<LinkIcon />
</Link>
</template>
+15
View File
@@ -0,0 +1,15 @@
<script setup lang="ts">
import { Link, LinkIcon } from "@heroui-vue/components";
</script>
<template>
<div class="flex flex-col gap-3">
<Link href="#">
图标在末尾(默认)
<LinkIcon />
</Link>
<Link class="gap-1" href="#">
<LinkIcon />
图标在开头
</Link>
</div>
</template>
+11
View File
@@ -0,0 +1,11 @@
<script setup lang="ts">
import { Link, LinkIcon } from "@heroui-vue/components";
</script>
<template>
<Link href="#" as-child>
<span data-custom="foo">
立即行动
<LinkIcon />
</span>
</Link>
</template>
@@ -0,0 +1,52 @@
<script setup lang="ts">
import { Link, LinkIcon } from "@heroui-vue/components";
</script>
<template>
<div class="flex flex-col gap-6">
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">默认悬浮下划线</p>
<Link href="#">
悬浮以查看下划线
<LinkIcon />
</Link>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">始终显示下划线</p>
<Link class="underline" href="#">
下划线始终可见
<LinkIcon />
</Link>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">无下划线</p>
<Link class="no-underline" href="#">
不带任何下划线的链接
<LinkIcon />
</Link>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">调整下划线偏移</p>
<div class="flex flex-col gap-3">
<Link class="underline-offset-1" href="#">
偏移 1(1px 间距)
<LinkIcon />
</Link>
<Link class="underline-offset-2" href="#">
偏移 2(2px 间距)
<LinkIcon />
</Link>
<Link class="underline-offset-3" href="#">
偏移 3(3px 间距)
<LinkIcon />
</Link>
<Link class="underline-offset-4" href="#">
偏移 4(4px 间距)
<LinkIcon />
</Link>
</div>
</div>
</div>
</template>
+8
View File
@@ -0,0 +1,8 @@
<script setup lang="ts">
import { Spinner } from "@heroui-vue/components";
</script>
<template>
<div class="flex items-center gap-4">
<Spinner />
</div>
</template>
+25
View File
@@ -0,0 +1,25 @@
<script setup lang="ts">
import { Spinner } from "@heroui-vue/components";
const COLOR_LABELS = {
accent: "强调",
current: "当前",
danger: "危险",
success: "成功",
warning: "警告",
} as const;
const colors = ["current", "accent", "success", "warning", "danger"] as const;
</script>
<template>
<div class="flex items-center gap-8">
<div
v-for="color in colors"
:key="color"
class="flex flex-col items-center gap-2"
>
<Spinner :color="color" />
<span class="text-xs text-muted">{{ COLOR_LABELS[color] }}</span>
</div>
</div>
</template>
+12
View File
@@ -0,0 +1,12 @@
<script setup lang="ts">
import { Spinner } from "@heroui-vue/components";
</script>
<template>
<div
class="flex items-center gap-4 rounded-xl border border-border bg-surface px-5 py-4"
>
<Spinner class="text-accent" size="sm" />
<Spinner class="text-muted" size="md" />
<Spinner class="text-success" size="lg" />
</div>
</template>
+24
View File
@@ -0,0 +1,24 @@
<script setup lang="ts">
import { Spinner } from "@heroui-vue/components";
const SIZE_LABELS = {
lg: "大",
md: "中",
sm: "小",
xl: "特大",
} as const;
const sizes = ["sm", "md", "lg", "xl"] as const;
</script>
<template>
<div class="flex items-center gap-8">
<div
v-for="size in sizes"
:key="size"
class="flex flex-col items-center gap-2"
>
<Spinner :size="size" />
<span class="text-xs text-muted">{{ SIZE_LABELS[size] }}</span>
</div>
</div>
</template>
+23
View File
@@ -0,0 +1,23 @@
<script setup lang="ts">
import { Spinner } from "@heroui-vue/components";
</script>
<template>
<div class="flex items-center gap-8">
<div class="flex flex-col items-center gap-2">
<Spinner
class="animate-[spin_1.5s_linear_infinite] motion-reduce:animate-none"
/>
<span class="text-xs text-muted">慢速</span>
</div>
<div class="flex flex-col items-center gap-2">
<Spinner />
<span class="text-xs text-muted">默认</span>
</div>
<div class="flex flex-col items-center gap-2">
<Spinner
class="animate-[spin_0.4s_linear_infinite] motion-reduce:animate-none"
/>
<span class="text-xs text-muted">快速</span>
</div>
</div>
</template>
+12
View File
@@ -0,0 +1,12 @@
<script setup lang="ts">
import { Surface } from "@heroui-vue/components";
</script>
<template>
<Surface
class="flex min-w-[320px] flex-col gap-3 rounded-3xl p-6"
variant="default"
>
<h3 class="text-base font-semibold text-foreground">表面内容</h3>
<p class="text-sm text-muted">这是默认表面变体,使用 bg-surface 样式。</p>
</Surface>
</template>
+12
View File
@@ -0,0 +1,12 @@
<script setup lang="ts">
import { Surface } from "@heroui-vue/components";
</script>
<template>
<Surface
class="w-full max-w-sm rounded-xl border border-accent/15 bg-linear-to-br from-accent/8 via-surface to-surface-secondary p-4"
variant="default"
>
<h3 class="text-sm font-semibold text-foreground">账单概览</h3>
<p class="text-sm text-muted">在此查看发票和支付方式。</p>
</Surface>
</template>
+58
View File
@@ -0,0 +1,58 @@
<script setup lang="ts">
import { Surface } from "@heroui-vue/components";
</script>
<template>
<div class="flex flex-col gap-4">
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">默认</p>
<Surface
class="flex min-w-[320px] flex-col gap-3 rounded-3xl p-6"
variant="default"
>
<h3 class="text-base font-semibold text-foreground">表面内容</h3>
<p class="text-sm text-muted">
这是默认表面变体,使用 bg-surface 样式。
</p>
</Surface>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">次要</p>
<Surface
class="flex min-w-[320px] flex-col gap-3 rounded-3xl p-6"
variant="secondary"
>
<h3 class="text-base font-semibold text-foreground">表面内容</h3>
<p class="text-sm text-muted">
这是次要表面变体,使用 bg-surface-secondary 样式。
</p>
</Surface>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">第三</p>
<Surface
class="flex min-w-[320px] flex-col gap-3 rounded-3xl p-6"
variant="tertiary"
>
<h3 class="text-base font-semibold text-foreground">表面内容</h3>
<p class="text-sm text-muted">
这是第三表面变体,使用 bg-surface-tertiary 样式。
</p>
</Surface>
</div>
<div class="flex flex-col gap-2">
<p class="text-sm font-medium text-muted">透明</p>
<Surface
class="flex min-w-[320px] flex-col gap-3 rounded-3xl border p-6"
variant="transparent"
>
<h3 class="text-base font-semibold text-foreground">表面内容</h3>
<p class="text-sm text-muted">
这是透明表面变体,无背景,适用于遮罩层和自定义背景的卡片。
</p>
</Surface>
</div>
</div>
</template>
@@ -0,0 +1,12 @@
<script setup lang="ts">
import { Input, Surface, TextArea } from "@heroui-vue/components";
</script>
<template>
<Surface
class="flex min-w-[320px] flex-col gap-4 rounded-3xl p-6"
variant="default"
>
<Input placeholder="使用次要变体的输入框" variant="secondary" />
<TextArea placeholder="使用次要变体的文本域" variant="secondary" />
</Surface>
</template>