145a208687
HD-04 scope, against heroui ce90ea3 cn sources: - stale/fictional content: input.md no longer claims TextField is unmigrated; color-field.md no longer claims ColorPicker is private; header.md drops the fictional Header.Root subcomponent and the stale 'menus not migrated' wording (MenuSection label registration is now documented from HeaderRoot source); radio-group.md drops three copied CheckboxGroup wordings (variant override is Radio's, scalar emits, native single-value submit); input-otp.md drops the fictional data-complete state and lists the real missing upstream props - toggle-button disabled row now matches the real CSS hooks (:disabled / [aria-disabled], with data-disabled as a marker only) - part API / CSS classes / interactive states restored per pinned sources: button (full class lists + real variable-based global CSS), accordion (per-part tables + variant/state lists), card (per-part tables + variant list), switch (SwitchGroup snippet + Switch/ SwitchGroup class lists + states), color-field Group (class list + states), input-otp (variant notes, global CSS, class/state lists); input-group gains the two upstream usage chapters - RelatedComponents restored from the pinned componentRelationships (first-3, filtered against componentsMap): 64 pages rewritten, list-box/slider sections added, 7 empty-mapping pages' fabricated entries removed; RelatedShowcases left unmigrated with its real data inventory recorded (2 cases, showcase-site cards) - defaults unified on implementation evidence: granularity (inferred day/minute) and visibleYears (full min-max span, no "or 20" fallback); HD-03 hand-offs resolved (trigger focus-visible noted for HD-06, width guards kept) - new demos: header-collection-grouping (MenuSection/ListBoxSection label wiring), empty-state-collection (collection empty slot); empty-state page deduplicated with a boundary compatibility note - ComponentPreview minHeight/isBgSolid restored per the 30 upstream marks; tabs-overflow max-w-full kept after measuring internal scroll - tests: +3 header registration/demo cases, +1 empty-state collection case; full suite 110 files / 1630 tests, typecheck and build:docs pass
3.4 KiB
3.4 KiB
title, description, component, group
| title | description | component | group |
|---|---|---|---|
| EmptyState 空状态 | 在列表、搜索结果或集合为空时展示占位提示。 | empty-state | 组件 |
用法
<script setup lang="ts">
import { EmptyState } from "@heroui-vue/components";
</script>
<template>
<EmptyState />
</template>
基线说明:固定上游提交提供
EmptyState源码与样式,但没有独立中文组件页或官方演示。本页与以下示例由本项目依据真实源码(默认文案No results found)和现有空状态消费场景编写,不是上游官方文档内容。
组件结构
EmptyState 是单根展示组件,默认渲染 div,样式为基线 .empty-state 的 hv- 命名空间版本。
<template>
<EmptyState>
<span>没有找到匹配的搜索结果。</span>
</EmptyState>
</template>
默认插槽为空、仅包含注释或空白文本时,回退到源码默认文案 No results found。只要存在有效内容(文本、数字或元素),就渲染调用方内容,不额外包裹结构。
兼容说明:固定源的 React 实现用真值判断(
children || "No results found"),数字0会回退默认文案、纯空白字符串原样渲染;本库把0视为有效内容照常渲染、纯空白回退默认文案。这是有意的 Vue 适配边界,两处与上游不同。
示例
自定义文案
条件内容
插槽内容由 v-if 切换;内容为空时自动回退到默认文案。
集合为空
把 EmptyState 放进集合组件的空槽(如 ListBox 的 #empty),作为搜索无结果或数据为空时的占位。过滤输入改变集合内容即可看到回退效果。
自定义样式
class 与 $attrs 合并到根元素,可叠加边框、背景、间距与对齐工具类。
Tailwind CSS
全局 CSS
@layer components {
.hv-empty-state {
@apply py-8 text-center text-base;
}
}
样式参考
EmptyState 组件使用以下 CSS 类(查看源码样式):
.hv-empty-state- 基础空状态文本样式(p-2 text-sm text-muted)
基线没有尺寸、颜色、变体或图标插槽等额外 CSS 变体;需要更丰富的空状态布局时,由调用方组合内容与工具类。
API 参考
EmptyState
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
as |
string |
'div' |
自定义根元素标签;对应上游 render 的元素替换。 |
class |
string | Array | Object |
- | 附加 CSS 类(Vue class 绑定)。 |
| 默认插槽 | - | - | 空状态内容;无有效内容时回退默认文案。 |
$attrs(aria-*、data-*、id、style、事件等)透传至根元素。组件没有受控值、内部状态、事件或暴露方法。