Demos
How to import
import { Empty } from '@fibrous/semi-ui-react';
Basic usage
By setting a placeholder image with image, you can manually import the corresponding illustration from @fibrous/semi-illustrations-react (the default width and height of the illustration is 200x200), or you can import a custom illustration.
A series of dark mode illustrations are added, and the illustrations that need to be used in dark mode can be passed in through darkModeImage to better adapt to the dark mode.
An empty string image counts as no image, and the title is laid out as if there were none.
Code
import { IllustrationConstruction, IllustrationConstructionDark } from '@fibrous/semi-illustrations-react';
import { Empty } from '@fibrous/semi-ui-react';
export default function EmptyDemo() {
return <Empty image={<IllustrationConstruction style={{ width: 150, height: 150 }} />} darkModeImage={<IllustrationConstructionDark style={{ width: 150, height: 150 }} />} title="功能建设中" description="当前功能暂未开放,敬请期待。" />;
}Custom content
Description content goes in the description prop, and children is the actions area below it.
Code
import { IllustrationNoContent, IllustrationNoContentDark } from '@fibrous/semi-illustrations-react';
import { Empty, Button } from '@fibrous/semi-ui-react';
export default function EmptyDemo() {
return (
<Empty image={<IllustrationNoContent style={{ width: 150, height: 150 }} />} darkModeImage={<IllustrationNoContentDark style={{ width: 150, height: 150 }} />} title="空状态标题" description="开始创建你的第一个仪表盘吧!">
<div>
<Button style={{ padding: '6px 24px', marginRight: 12 }} type="primary">
二级按钮
</Button>
<Button style={{ padding: '6px 24px' }} theme="solid" type="primary">
一级按钮
</Button>
</div>
</Empty>
);
}It is not necessary to use pictures.
Code
import { Empty, Typography } from '@fibrous/semi-ui-react';
export default function EmptyDemo() {
return (
<Empty
title="暂未找到匹配的筛选结果"
description={
<span>
<Typography.Text>试试 </Typography.Text>
<Typography.Text link>重置筛选条件</Typography.Text>
</span>
}
/>
);
}Different layout
Two types of layouts are supported: vertical, horizontal. The default is vertical.
Code
import { IllustrationSuccess, IllustrationSuccessDark } from '@fibrous/semi-illustrations-react';
import { Empty, Button } from '@fibrous/semi-ui-react';
export default function EmptyDemo() {
return (
<Empty
title="创建成功"
image={<IllustrationSuccess style={{ width: 150, height: 150 }} />}
darkModeImage={<IllustrationSuccessDark style={{ width: 150, height: 150 }} />}
layout="horizontal"
description="这是一段很长的描述文本,当文本过长的时候推荐使用这种布局形式。这是一段很长的描述文本,当文本过长的时候推荐使用这种布局形式。这是一段很长的描述文本,当文本过长的时候推荐使用这种布局形式。"
style={{ width: 800, margin: '0 auto' }}
>
<Button type="primary" theme="solid" style={{ padding: '6px 24px' }}>
开始操作
</Button>
</Empty>
);
}Placeholder illustration (under construction)
Currently the following illustrations are supported in @fibrous/semi-illustrations-react (@fibrous/semi-illustrations-vue for Vue).
Code
import {
IllustrationConstruction,
IllustrationSuccess,
IllustrationFailure,
IllustrationNoAccess,
IllustrationNoContent,
IllustrationNotFound,
IllustrationNoResult,
IllustrationIdle,
IllustrationIdleDark,
IllustrationConstructionDark,
IllustrationSuccessDark,
IllustrationFailureDark,
IllustrationNoAccessDark,
IllustrationNoContentDark,
IllustrationNotFoundDark,
IllustrationNoResultDark,
} from '@fibrous/semi-illustrations-react';
import { Empty } from '@fibrous/semi-ui-react';
export default function EmptyDemo() {
const emptyStyle = {
padding: 30,
};
return (
<div style={{ display: 'flex', flexWrap: 'wrap' }}>
<Empty image={<IllustrationSuccess style={{ width: 150, height: 150 }} />} darkModeImage={<IllustrationSuccessDark style={{ width: 150, height: 150 }} />} description="创建成功" style={emptyStyle} />
<Empty image={<IllustrationFailure style={{ width: 150, height: 150 }} />} darkModeImage={<IllustrationFailureDark style={{ width: 150, height: 150 }} />} description="加载失败" style={emptyStyle} />
<Empty image={<IllustrationNoAccess style={{ width: 150, height: 150 }} />} darkModeImage={<IllustrationNoAccessDark style={{ width: 150, height: 150 }} />} description="没有权限" style={emptyStyle} />
<Empty image={<IllustrationNoContent style={{ width: 150, height: 150 }} />} darkModeImage={<IllustrationNoContentDark style={{ width: 150, height: 150 }} />} description="暂无内容,请添加" style={emptyStyle} />
<Empty image={<IllustrationNotFound style={{ width: 150, height: 150 }} />} darkModeImage={<IllustrationNotFoundDark style={{ width: 150, height: 150 }} />} description="页面404" style={emptyStyle} />
<Empty image={<IllustrationNoResult style={{ width: 150, height: 150 }} />} darkModeImage={<IllustrationNoResultDark style={{ width: 150, height: 150 }} />} description="搜索无结果" style={emptyStyle} />
<Empty image={<IllustrationConstruction style={{ width: 150, height: 150 }} />} darkModeImage={<IllustrationConstructionDark style={{ width: 150, height: 150 }} />} description="建设中" style={emptyStyle} />
<Empty image={<IllustrationIdle style={{ width: 150, height: 150 }} />} darkModeImage={<IllustrationIdleDark style={{ width: 150, height: 150 }} />} description="神游四方" style={emptyStyle} />
</div>
);
}API reference
Props
| Property | Description | Type | Default |
|---|---|---|---|
| children | Actions below the description, such as buttons. | React.ReactNode | - |
| className | Class name of the root element. | string | - |
| darkModeImage | Placeholder image in dark mode, following the theme-mode attribute of document.body. Takes the same values as image. | React.ReactNode | SVGNode | - |
| description | Description content, shown below the title. | React.ReactNode | - |
| image | Placeholder image: a ReactNode such as an illustration component, an image URL string, or an in-page SVG sprite symbol as { id }. An empty string counts as no image. | React.ReactNode | SVGNode | - |
| imageStyle | Inline style of the placeholder image area, typed as CSSProperties. | React.CSSProperties | - |
| layout | Layout mode: vertical or horizontal. | 'vertical' | 'horizontal' | "vertical" |
| ref | Reference to the root div element. | TypeReact.Ref<HTMLDivElement> | - |
| style | Inline style of the root element. | React.CSSProperties | - |
| title | Title, rendered in the title style. Accepts any ReactNode. | React.ReactNode | - |
Other native attributes (such as id and aria-*) land on the root div element.
Accessibility
ARIA
- Empty illustrations are decorative: an SVG illustration has
aria-hidden="true", and animgrendered from an image URL has an emptyalt titleis styled as a heading but rendered as adivwithout heading semantics, so it does not disturb the page's heading levels
Content Guidelines
- Title
- The title should be concise and easy to understand
- Text
- The specific reasons for displaying the empty state can be displayed, and the subsequent operation behavior can also be displayed to help the user eliminate the empty state
- Don't repeat the content on the title
- Try to keep the body text within 1-2 sentences
- Action button
- Button copy needs to be clear and easy to understand
- Use the verb + noun format
Design Token
| Sass variable | Value | Usage |
|---|---|---|
| $spacing-empty_content_vertical-marginTop | 24px | 垂直布局内容顶部外边距 |
| $spacing-empty_content_horizontal-marginLeft | 32px | 水平布局内容左侧外边距 |
| $spacing-empty_title-marginTop | 16px | 标题内容顶部外边距 |
| $spacing-empty_footer-marginTop | 24px | 操作 footer 顶部外边距 |
| $font-empty_title-fontWeight | 600 | 标题字重 |
| $color-empty_description-text-default | var(--semi-color-text-1) | 描述文字颜色 |