Empty
空状态、插图、创建第一篇文章和一般 renderEmpty。
何时使用
插图、描述和动作
图像选择嵌入的插图、URL 或片段。description 指定解释;如果没有显式值,则使用当前区域设置。children 包含附加内容,通常是操作按钮。
| 问题 | 机会 | 示例 |
|---|---|---|
| 显示缺失数据 | 默认值 | 基本选项 |
| 将财富融入一个小区域 | image="simple" |
紧凑的图片 |
| 添加您自己的图像和按钮 | image, description, children |
净值 |
| 删除签名 | description={false} |
无文字 |
| 替换通用空列表 | ConfigProvider.renderEmpty | 一般组成 |
使用 default/简单线条选择内置选项。另一个字符串 image 被视为 URL。使用 styles.image 设置插图的大小,而不是整个 Empty 的样式。对于复杂的描述,请使用包含短文本和相关链接的片段。
区域设置和常规设置
ConfigProvider.locale.empty 更改默认签名。明确的 description 优先; false 完全隐藏描述。 ConfigProvider.empty 指定继承的插图、class/style 和语义默认值。
RenderEmpty 是受支持组件的空内容的公共提供程序的单独片段:Select、TreeSelect、Cascader、Transfer 和 Table。它不会取代每个随机放置的空的描述。 一般示例 准确地显示了该上下文的消耗组件。
嵌套提供程序允许您独立更改不同区域的语言和设计。 Empty 设置和一般的 renderEmpty 函数解决不同的问题:第一个设计组件,第二个创建空结果的内容。
数据 的可用性和转换
该插图是装饰性的,不应提供单一的解释。通过描述来传达含义,通过带有清晰名称的本机按钮或链接来传达操作。
创建第一个条目后,Empty 及其按钮就会消失。预先将焦点设置到要保存的数据区域或新记录。在 应用实例 中,这是一个表区域;清除列表后,焦点返回到输入字段。
classNames/styles 支持 root、image、description 和 footer、对象或来自 props 的回调。 Svelte styles 包含 CSS 字符串。 bind:nativeElement 返回挂载后的根 div。 Empty 没有一套单独的组件设计令牌(design tokens);它使用共同的主题和语义风格。
prefixCls 指定完整的本地 CSS 前缀 Empty。空字符串和 undefined 继承ConfigProvider.prefixCls,带有 -empty 后缀,默认为 ant-empty。更改类会保留绘图、描述和语义 styles;命名空间 CSS 变量不会改变。 示例 ConfigProvider 显示共同继承。
示例
空状态
当前区域设置的内嵌插图和标题。
<script lang="ts">
import { Empty } from '@woodger/antd';
</script>
<Empty aria-label={("空默认状态")} />
紧凑的插图
image="simple" 适合空列表和小区域。
<script lang="ts">
import { Empty } from '@woodger/antd';
</script>
<Empty image="simple" description={("还没有任务")} />
该文档尚未创建。
图片、描述和动作
插图 URL、尺寸(通过 styles.image)、片段描述和创建按钮。
<script lang="ts">
import { Button, Empty } from '@woodger/antd';
const image = 'data:image/svg+xml,' + encodeURIComponent(
'<svg xmlns="http://www.w3.org/2000/svg" width="160" height="100" viewBox="0 0 160 100"><rect x="20" y="12" width="120" height="76" rx="12" fill="#f6ffed" stroke="#b7eb8f"/><path d="M56 50h48m-24-24v48" stroke="#389e0d" stroke-width="4"/></svg>'
);
let created = $state(false);
</script>
{#snippet description()}
<strong>{("该文件夹中还没有文档")}</strong>
<div>{("创建您的第一个文档以开始使用。")}</div>
{/snippet}
<Empty {image} description={(description)} styles={{ image: 'height:80px' }}>
<Button type="primary" disabled={created} onclick={() => { created = true; }}>
{("\n 创建文档\n ")}
</Button>
</Empty>
<p role="status" aria-label={("创建文档")}>
{(created ? "该文档已创建。" : "该文档尚未创建。")}
</p>
Select
TreeSelect
Cascader
Transfer
姓名 |
|---|
未找到数据 |
<script lang="ts">
import {
Cascader, Checkbox, ConfigProvider, Empty, Select, Table, Transfer, TreeSelect
} from '@woodger/antd';
let custom = $state(true);
</script>
<style>
.examples {
display: grid;
gap: 24px;
margin-top: 24px;
min-width: 0;
}
.field { max-width: 300px; }
h4 {
margin: 0 0 8px;
font-size: 14px;
font-weight: 600;
}
.transfer {
max-width: 100%;
overflow-x: auto;
}
</style>
{#snippet empty()}
<Empty image="simple" description={("未找到数据")} />
{/snippet}
<Checkbox bind:checked={custom}>{("一般空状态")}</Checkbox>
<ConfigProvider
renderEmpty={custom ? () => empty : undefined}
empty={{ styles: { description: 'color:var(--ant-color-text-secondary)' } }}
>
<div class="examples">
<div class="field">
<h4>Select</h4>
<Select
options={([])}
aria-label={("空选择")}
placeholder={("选择条目")}
/>
</div>
<div class="field">
<h4>TreeSelect</h4>
<TreeSelect
treeData={[]}
aria-label={("空树选择")}
placeholder={("选择节点")}
/>
</div>
<div class="field">
<h4>Cascader</h4>
<Cascader
options={([])}
aria-label={("空层叠器")}
placeholder={("选择一条路径")}
/>
</div>
<div class="transfer">
<h4>Transfer</h4>
<Transfer
dataSource={([])}
titles={(["可用的", "已选择"])}
/>
</div>
<Table
dataSource={([])}
columns={([{ key: 'name', title: "姓名", dataIndex: 'name' }])}
pagination={(false)}
caption={("一般空表状态")}
/>
</div>
</ConfigProvider>
Semantic DOM
styles/classNames 对象和函数样式 root、image、description 和页脚。
<script lang="ts">
import { Button, Checkbox, Empty } from '@woodger/antd';
let highlight = $state(false);
let actions = $state(0);
</script>
<style>
.examples {
display: grid;
gap: 24px;
margin-top: 24px;
}
.examples :global(.empty-slot) { outline: 1px dashed var(--ant-color-primary); }
output {
display: block;
margin-top: 16px;
}
</style>
<Checkbox bind:checked={highlight}>{("突出显示语义槽")}</Checkbox>
<div class="examples">
<Empty
description={("按对象划分的样式")}
classNames={highlight ? {
root: 'empty-slot', image: 'empty-slot', description: 'empty-slot', footer: 'empty-slot'
} : undefined}
styles={{
root: `
padding: 16px;
border-radius: 8px;
background: var(--ant-color-fill-quaternary);
`,
image: 'height:64px',
description: 'font-weight:600',
footer: 'margin-top:20px'
}}
>
<Button onclick={() => { actions++; }}>{("创建条目")}</Button>
</Empty>
<Empty
image="simple"
description={("按功能划分的款式")}
classNames={() => highlight ? { root: 'empty-slot', description: 'empty-slot' } : {}}
styles={({ props }) => ({
root: 'padding:16px',
description: props.image === 'simple' ? 'font-weight:600' : undefined
})}
/>
</div>
<output
aria-label={("动作语义 空")}
>{("创建的记录: ")}{actions}</output>
无描述
description={false} 使插图不带标题。
<script lang="ts">
import { Empty } from '@woodger/antd';
</script>
<Empty
description={(false)}
aria-label={("无签名的空状态")}
/>
俄语
English
区域设置和空设置
本地 ConfigProvider 彼此独立地更改语言和继承的艺术品。
<script lang="ts">
import { ConfigProvider, Empty, enUS, ruRU } from '@woodger/antd';
</script>
<style>
.examples {
display: grid;
gap: 24px;
}
h4 {
margin: 0;
font-size: 14px;
font-weight: 600;
}
</style>
<div class="examples">
<div lang="ru">
<h4>{("俄语")}</h4>
<ConfigProvider locale={ruRU} empty={{ image: 'simple' }}>
<Empty aria-label={("俄语语言环境")} />
</ConfigProvider>
</div>
<div lang="en">
<h4>English</h4>
<ConfigProvider locale={enUS} empty={{ image: 'simple' }}>
<Empty aria-label={("English locale")} />
</ConfigProvider>
</div>
</div>
姓名 | 角色 |
|---|---|
还没有参与者。 | |
会员和搜索
添加第一位成员,或查看搜索没有结果时团队看到的内容。
<script lang="ts">
import { Button, Checkbox, Empty, Input, Select, Table, type TableColumn } from '@woodger/antd';
interface Member {
key: number;
name: string;
role: string;
}
let image = $state<'default' | 'simple' | 'custom' | 'none'>('default');
let description = $state<'text' | 'rich' | 'none'>('text');
let text = $state<string | undefined>(("这里还什么都没有。"));
let actions = $state(true);
let actionCount = $state(0);
let members = $state<Member[]>([]);
let name = $state<string | undefined>(("安娜"));
let query = $state<string | undefined>('');
let tableHost = $state<HTMLDivElement>();
let nextKey = 0;
let visible = $derived(
members.filter(
member =>
member.name.toLowerCase().includes((query ?? '').trim().toLowerCase())
)
);
const columns: TableColumn<Member>[] = [
{ key: 'name', title: "姓名", dataIndex: 'name' },
{ key: 'role', title: "角色", dataIndex: 'role' }
];
function focusTable() {
const table = tableHost?.querySelector<HTMLElement>('.ant-table-content');
table?.focus({ preventScroll: true });
}
function addMember() {
const value = name?.trim();
if (!value) {
return;
}
focusTable();
query = '';
members = [...members, { key: nextKey++, name: value, role: "参加者" }];
}
function resetSearch() {
focusTable();
query = '';
}
function clearMembers() {
const input = document.getElementById('empty-example-name');
input?.focus({ preventScroll: true });
members = [];
query = '';
}
</script>
<style>
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
}
.fields { align-items: flex-end; }
.fields :global(.ant-btn) {
max-width: 100%;
height: auto;
min-height: var(--ant-control-height);
white-space: normal;
}
.fields :global(.ant-btn-sm) { min-height: var(--ant-control-height-sm); }
.fields :global(.ant-btn-lg) { min-height: var(--ant-control-height-lg); }
.field { width: 180px; }
.wide {
width: 260px;
max-width: 100%;
}
.wide label {
display: block;
margin-bottom: 8px;
}
.preview {
margin-block: 24px;
padding: 20px;
border: 1px solid var(--ant-color-border-secondary);
border-radius: var(--ant-border-radius-lg);
}
.table { margin-top: 20px; }
output {
display: block;
margin-top: 20px;
color: var(--ant-color-text-secondary);
}
</style>
{#snippet customImage()}<svg width="160" height="100" viewBox="0 0 160 100" aria-hidden="true"><rect
x="24"
y="20"
width="112"
height="64"
rx="12"
fill="var(--ant-color-primary-bg)"
stroke="var(--ant-color-primary-border)"
/><path
d="M56 52h48m-24-24v48"
fill="none"
stroke="var(--ant-color-primary)"
stroke-width="4"
/></svg>{/snippet}
{#snippet richDescription()}<strong>
{(text || ("没有条目"))}
</strong><br /><span>
{("添加您的第一个条目即可开始。")}
</span>{/snippet}
{#snippet previewActions()}
<Button type="primary" onclick={() => { actionCount++; }}>
{("尝试空操作")}
</Button>
{/snippet}
{#snippet emptyMembers()}<Empty
image="simple"
description={(members.length ? "没有找到符合您请求的结果。" : "还没有参与者。")}
>{#if members.length}<Button
onclick={resetSearch}
>{("重置会员搜索")}</Button>{:else}<Button
type="primary"
disabled={!name?.trim()}
onclick={addMember}
>{("创建您的第一个参与者")}</Button>{/if}</Empty>{/snippet}
<div class="controls"><div class="field"><Select
aria-label={("空图")}
bind:value={image}
options={([
{ value: 'default', label: 'default' },
{ value: 'simple', label: 'simple' },
{ value: 'custom', label: "你自己的片段" },
{ value: 'none', label: "没有图片" }
])}
/></div><div class="field"><Select
aria-label={("空的描述")}
bind:value={description}
options={([
{ value: 'text', label: "文本" },
{ value: 'rich', label: 'Snippet' },
{ value: 'none', label: "无描述" }
])}
/></div><div
class="wide"
><Input
aria-label={("文本为空")}
bind:value={text}
/></div><Checkbox
bind:checked={actions}
>{("动作空")}</Checkbox></div>
<div class="preview"><Empty
image={image === 'custom' ? customImage : image === 'none' ? false : image}
description={description === 'rich' ? richDescription : description === 'none' ? false : (text
?? '')}
children={actions ? previewActions : undefined}
aria-label={("可定制的空状态")}
/></div>
<div class="controls fields"><div class="wide"><label for="empty-example-name">
{("新会员名称")}
</label><Input
id="empty-example-name"
bind:value={name}
/></div><Button
disabled={!name?.trim()}
onclick={addMember}
>{("将成员添加到空示例")}</Button><Button
disabled={!members.length}
onclick={clearMembers}
>{("清除参与者列表")}</Button><div
class="wide"
><label
for="empty-example-search"
>{("在空示例中搜索")}</label><Input
id="empty-example-search"
aria-label={("在空示例中搜索")}
bind:value={query}
/></div></div>
<div class="table" bind:this={tableHost}><Table
dataSource={(visible)}
columns={(columns)}
pagination={(false)}
caption={("空示例参与者")}
empty={emptyMembers}
/></div>
<output
aria-label={("空示例结果")}
>{("参加者: ")}{(members.length)}{("。显示: ")}{(visible.length)}{("。行动: ")}{actionCount}.</output>
API
针对六个 ant.design 6.6.8 页面主题和 @woodger/antd 公共类型进行了验证。完整的 Props 定义属于包。
| 主题 | 例子 |
|---|---|
| Basic | 标准空状态。 |
| Choose image | 内置紧凑插图。 |
| Customize | URL、大小、片段和操作。 |
| ConfigProvider | 五种成分的总含量。 |
| Custom semantic dom styling | 样式对象和功能。 |
| No description | 明确禁用签名。 |
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
prefixCls | 空的根、图像和描述的完整本地 CSS 前缀。空字符串和 undefined 继承ConfigProvider.prefixCls;默认为 ant-empty。 | string | ConfigProvider + -empty |
image | default、简单、URL 或片段; false 隐藏插图。 | EmptyImage | 默认/上下文 |
description | 文本、数字或片段; false 隐藏签名。 | EmptyDescription | 从语言环境 |
children | 其他内容,例如创建按钮。 | EmptyContent | — |
styles | CSS 行按语义槽划分;对象或函数({ props })。 | EmptySemantic | — |
classNames | 按语义槽分类;对象或函数({ props })。 | EmptySemantic | — |
nativeElement | bind:nativeElement 提供对根 DOM 元素的访问。 | HTMLDivElement | 安装后 |
ref | bind:ref 提供 nativeElement;卸载时清除。 | EmptyRef | 安装后 |
嵌入图像
而不是 React 常量 Empty.PRESENTED_IMAGE_DEFAULT 和
Empty.PRESENTED_IMAGE_SIMPLE 传递它 image="default" 或者
image="simple"。其余行被视为 URL。片段允许您插入自己的插图, false 隐藏它。
ConfigProvider
empty 指定提供程序内空实例的图像和装饰。
renderEmpty(componentName) 返回其他组件空白区域的内容。组件本身的参数,例如 Table.empty 或者
Select.notFoundContent,优先于一般处理程序。
Semantic DOM
在语义 DOM 示例中打开突出显示以查看元素边界。
styles 接受 CSS 字符串, classNames - 类名;两个选项都支持对象和函数 props.
| Slot | 目的 |
|---|---|
root | 根:对齐和排版。 |
image | 装饰插图及其尺寸。 |
description | 空状态签名。 |
footer | 签名下的其他操作。 |
该插图是装饰性的,并且隐藏在辅助功能树中。在描述文本中传达状态的含义。对于动态操作结果,请使用单独的
role="status";空本身不会自动宣布更改。
注册令牌
Empty 没有自己的组件令牌。尺寸、填充和签名使用常见的主题标记。语义 styles 适合设计一个实例。
| 代币 | 意义 |
|---|---|
colorTextDescription | rgba(0,0,0,0.45) |
controlHeightLG | 40 |
fontSize | 14 |
lineHeight | 1.5714285714285714 |
margin | 16 |
marginXL | 32 |
marginXS | 8 |
opacityImage | 1 |
FAQ
空状态与错误有何不同?
空表示收到结果,但没有记录。加载和错误需要它们自己的消息和操作。
如何更改语言?
将 locale 传递给 ConfigProvider。明确的 description 将取代本地化的标题; false 将隐藏它。
为什么我创建帖子后失去焦点?
清空按钮及其状态将被删除。在删除之前将焦点置于要保存的区域或新对象上。