Files
heroui-vue/apps/docs/components/surface.md
T
2026-10-21 13:04:06 +08:00

2.7 KiB
Raw Blame History

title, description, component, group
title description component group
Surface 表面 提供表面级样式与子组件上下文的容器组件 surface 组件

用法

<script setup lang="ts">
import { Surface } from "@heroui-vue/components";
</script>

示例

变体

Surface 提供描述 prominence 层级的语义变体:

  • default - 标准表面外观(bg-surface)
  • secondary - 中等 prominence(bg-surface-secondary)
  • tertiary - 较高 prominence(bg-surface-tertiary)
  • transparent - 透明背景,适用于遮罩层和自定义背景

搭配表单

在 Surface 内使用表单组件时,请使用 variant="secondary" 以应用适合表面背景的低强调变体。

自定义样式

Tailwind CSS

全局 CSS

若要自定义组件类,可使用 @layer components 指令。

@layer components {
  .hv-surface {
    @apply rounded-2xl border border-border;
  }

  .hv-surface--secondary {
    @apply bg-gradient-to-br from-blue-50 to-purple-50;
  }
}

样式参考

HeroUI 遵循 BEM 方法论,确保组件变体与状态可复用且易于自定义。

CSS 类

Surface 组件使用以下 CSS 类:

基础类 [!toc]

  • .hv-surface - Surface 根容器

变体类 [!toc]

  • .hv-surface--default - 默认 Surface 变体(bg-surface)
  • .hv-surface--secondary - Secondary Surface 变体(bg-surface-secondary)
  • .hv-surface--tertiary - Tertiary Surface 变体(bg-surface-tertiary)
  • .hv-surface--transparent - 透明 Surface 变体

API 参考

Surface

Prop 类型 默认值 描述
variant "transparent" | "default" | "secondary" | "tertiary" "default" Surface 的视觉变体。
class string - 额外的 CSS 类。

默认插槽渲染 Surface 内容。其他属性与 DOM 事件透传到根 div。

Context API

surfaceContextKey

子组件可通过 Surface 上下文读取当前变体:

<script setup lang="ts">
import { inject } from "vue";
import { surfaceContextKey } from "@heroui-vue/components";

const surface = inject(surfaceContextKey, undefined);
// surface.variant.value 为 "transparent" | "default" | "secondary" | "tertiary"
</script>

相关组件

Card 卡片 · Input 输入框 · Button 按钮