导航

v2.1.0
反馈

空状态

视图暂无内容时呈现的状态。

本页内容

视图暂时没有内容时会显示空状态。它说明这里会显示什么,并提供添加内容的操作。空状态采用居中的单列布局,顶部是一个图标框,自身没有独立表面。可以把它放在卡片、凹槽中,也可以直接放在页面上。

空状态

<div class="well">  <div class="empty">    <div class="icon-frame icon-frame-raised empty-media" aria-hidden="true">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M9.4989 2.6265A0.625 0.625 0 0 0 9.375 3L9.3758 12.0307A0.625 0.625 0 0 0 10.6182 12.0917L10.625 12L10.623 2.95A0.6252 0.6252 0 0 0 10.5011 2.6265Q10.2855 2.4578 10 2.4578Q9.7145 2.4578 9.4989 2.6265Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><path d="M6.5 6.5L9.8586 3.1414A0.2 0.2 0 0 1 10.1414 3.1414L13.5 6.5" /><path d="M3 13.5L3 15.75A1.25 1.25 0 0 0 4.25 17L15.75 17A1.25 1.25 0 0 0 17 15.75L17 13.5" />      </svg>    </div>    <h3 class="empty-title">No deployments yet</h3>    <p class="empty-description">      Push to the main branch, or deploy from the dashboard, and the deployment appears here.    </p>    <div class="empty-actions">      <button type="button" class="btn btn-sm">Read the guide</button>      <button type="button" class="btn btn-sm btn-primary">Deploy now</button>    </div>  </div></div>
import UploadIcon from '@master/icons-react/native/20/soft/upload'<div className="well">  <div className="empty">    <div className="icon-frame icon-frame-raised empty-media" aria-hidden="true">      <UploadIcon className="icon" />    </div>    <h3 className="empty-title">No deployments yet</h3>    <p className="empty-description">      Push to the main branch, or deploy from the dashboard, and the deployment appears here.    </p>    <div className="empty-actions">      <button type="button" className="btn btn-sm">Read the guide</button>      <button type="button" className="btn btn-sm btn-primary">Deploy now</button>    </div>  </div></div>
<script>  import UploadIcon from '@master/icons-svelte/native/20/soft/upload'</script><div class="well">  <div class="empty">    <div class="icon-frame icon-frame-raised empty-media" aria-hidden="true">      <UploadIcon class="icon" />    </div>    <h3 class="empty-title">No deployments yet</h3>    <p class="empty-description">      Push to the main branch, or deploy from the dashboard, and the deployment appears here.    </p>    <div class="empty-actions">      <button type="button" class="btn btn-sm">Read the guide</button>      <button type="button" class="btn btn-sm btn-primary">Deploy now</button>    </div>  </div></div>
<script setup>import UploadIcon from '@master/icons-vue/native/20/soft/upload'</script><template>  <div class="well">    <div class="empty">      <div class="icon-frame icon-frame-raised empty-media" aria-hidden="true">        <UploadIcon class="icon" />      </div>      <h3 class="empty-title">No deployments yet</h3>      <p class="empty-description">        Push to the main branch, or deploy from the dashboard, and the deployment appears here.      </p>      <div class="empty-actions">        <button type="button" class="btn btn-sm">Read the guide</button>        <button type="button" class="btn btn-sm btn-primary">Deploy now</button>      </div>    </div>  </div></template>

筛选或搜索没有结果时,说明本次查找的内容,并提供返回方式。媒体和操作均为可选项。

搜索后无结果

<div class="empty">  <h3 class="empty-title">No projects match "atlsa"</h3>  <p class="empty-description">Check the spelling, or clear the search to see all 12 projects.</p>  <div class="empty-actions"><button type="button" class="btn btn-sm">Clear search</button></div></div>
<div className="empty">  <h3 className="empty-title">No projects match "atlsa"</h3>  <p className="empty-description">    Check the spelling, or clear the search to see all 12 projects.  </p>  <div className="empty-actions">    <button type="button" className="btn btn-sm">Clear search</button>  </div></div>
<div class="empty">  <h3 class="empty-title">No projects match "atlsa"</h3>  <p class="empty-description">Check the spelling, or clear the search to see all 12 projects.</p>  <div class="empty-actions"><button type="button" class="btn btn-sm">Clear search</button></div></div>
<template>  <div class="empty">    <h3 class="empty-title">No projects match "atlsa"</h3>    <p class="empty-description">Check the spelling, or clear the search to see all 12 projects.</p>    <div class="empty-actions"><button type="button" class="btn btn-sm">Clear search</button></div>  </div></template>

#图标

图标放在图标框中,由图标框提供材质:默认是压入页面的凹槽;如果空状态像上例那样位于凹槽中,就用凸起的面板 icon-frame-raised。在图标框上加 empty-media,可以让它在单列中占据合适的位置,它下方的间距比文字之间的间距稍大。图标框仅作装饰,缺少什么内容由标题说明。

#空状态文案

  • 标题用直白、具体的措辞说明当前状态,例如“暂无部署”。“这里什么都没有”过于笼统。
  • 用一两句话说明怎样让视图显示内容。描述文本在 24rem 的宽度内换行。
  • 提供一个主要操作。也可以加一个视觉上更低调的次要操作,引导用户查看文档。

#类名

类名说明
empty居中的列
empty-media用于顶部的 icon-frame:表明缺少的是哪类内容,下方留出空间
empty-title用直白的文字说明状态,例如“暂无部署”。
empty-description用一两句话说明如何让视图显示内容,文本按 24rem 的宽度换行
empty-actions居中排列的一行按钮

#源码

@master/ui/components/empty.css
/* * Empty: what a view shows when it has nothing to show yet: what belongs here, and the action that fills it. * A centered column, headed by an icon frame. It has no surface of its own; put it in a card, a sheet or a * well, or let it stand on the page. The frame's material is the icon frame's; empty-media only gives it its * place in the column. */@layer components.ui {  .empty {    display: flex;    flex-direction: column;    align-items: center;    gap: .375rem;    min-width: 0;    padding: 2.5rem 1.5rem;    color: var(--color-text-muted);    font-size: .875rem;    line-height: 1.55;    text-align: center;  }  /* The icon frame that names the kind of thing that is missing: a little more room under it than between the words. */  .empty-media {    margin-block-end: .625rem;  }  .empty-title {    margin: 0;    color: var(--color-text-strong);    font: var(--font-weight-control) .9375rem/1.4 var(--font-family-sans);    font-feature-settings: inherit;    text-wrap: balance;    overflow-wrap: anywhere;  }  .empty-description {    max-width: 24rem;    margin: 0;    text-wrap: pretty;    overflow-wrap: anywhere;  }  /* The actions stand 24px under the words: the column's 6px gap and 18px more. */  .empty-actions {    display: flex;    flex-wrap: wrap;    justify-content: center;    gap: .5rem;    margin-block-start: 1.125rem;  }}