导航

v2.1.0
应用区块

空状态区块

视图暂无内容时显示什么,以及如何开始。

空状态是视图在尚无内容时显示的内容。它是最小的区块,由 empty 组件和恰当的文案组成。文案是空状态的核心。好的空状态会说明这里会显示什么、为什么是空的,以及接下来可以做什么。

空状态

<section class="sheet container-inline" aria-labelledby="es-title">  <div class="empty">    <div class="icon-frame 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="M2.5 15.25L2.5 5.25A1.25 1.25 0 0 1 3.75 4L7.9822 4A1.25 1.25 0 0 1 8.8661 4.3661L10.1339 5.6339A1.25 1.25 0 0 0 11.0178 6L16.25 6A1.25 1.25 0 0 1 17.5 7.25L17.5 15.25A1.25 1.25 0 0 1 16.25 16.5L3.75 16.5A1.25 1.25 0 0 1 2.5 15.25Z" />      </svg>    </div>    <h2 class="empty-title" id="es-title">No projects yet</h2>    <p class="empty-description">      A project connects a repository to an address. Create one, and every push becomes a deployment.    </p>    <div class="empty-actions">      <a class="btn btn-sm" href="#">Read the guide</a>      <button type="button" class="btn btn-sm btn-primary">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <path d="M3 8L13 8" /><path d="M8 3L8 13" />        </svg>New project      </button>    </div>  </div></section>
import FolderIcon from '@master/icons-react/native/20/soft/folder'import PlusIcon from '@master/icons-react/native/16/soft/plus'<section className="sheet container-inline" aria-labelledby="es-title">  <div className="empty">    <div className="icon-frame empty-media" aria-hidden="true"><FolderIcon className="icon" /></div>    <h2 className="empty-title" id="es-title">No projects yet</h2>    <p className="empty-description">      A project connects a repository to an address. Create one, and every push becomes a deployment.    </p>    <div className="empty-actions">      <a className="btn btn-sm" href="#">Read the guide</a>      <button type="button" className="btn btn-sm btn-primary">        <PlusIcon className="icon" />New project      </button>    </div>  </div></section>
<script>  import FolderIcon from '@master/icons-svelte/native/20/soft/folder'  import PlusIcon from '@master/icons-svelte/native/16/soft/plus'</script><section class="sheet container-inline" aria-labelledby="es-title">  <div class="empty">    <div class="icon-frame empty-media" aria-hidden="true"><FolderIcon class="icon" /></div>    <h2 class="empty-title" id="es-title">No projects yet</h2>    <p class="empty-description">      A project connects a repository to an address. Create one, and every push becomes a deployment.    </p>    <div class="empty-actions">      <a class="btn btn-sm" href="#">Read the guide</a>      <button type="button" class="btn btn-sm btn-primary">        <PlusIcon class="icon" />New project      </button>    </div>  </div></section>
<script setup>import FolderIcon from '@master/icons-vue/native/20/soft/folder'import PlusIcon from '@master/icons-vue/native/16/soft/plus'</script><template>  <section class="sheet container-inline" aria-labelledby="es-title">    <div class="empty">      <div class="icon-frame empty-media" aria-hidden="true"><FolderIcon class="icon" /></div>      <h2 class="empty-title" id="es-title">No projects yet</h2>      <p class="empty-description">        A project connects a repository to an address. Create one, and every push becomes a deployment.      </p>      <div class="empty-actions">        <a class="btn btn-sm" href="#">Read the guide</a>        <button type="button" class="btn btn-sm btn-primary">          <PlusIcon class="icon" />New project        </button>      </div>    </div>  </section></template>

区块提供可直接复制的标记,沿用页面的文字颜色和字号。预览在 body 上设置 fg-text-body text-sm。每个区块都是尺寸容器,会根据自身宽度重排,适应宽幅页面、侧边栏大小的空间或对话框。

#四种空白情形

视图可能因四种原因而为空,每种情况都需要相应的文案。

类型说明提供的操作
暂无内容这里会显示什么,这些内容有什么用途创建第一项的操作
首次使用获得第一个结果所需的几个步骤下一步操作
无结果搜索了什么,哪些筛选条件仍然生效扩大搜索范围的方法
操作失败用通俗的话说明发生了什么,以及问题出在哪一方在 alert 中提供重试操作

上方展示了第一种情况,下方依次展示其余三种。

#首次使用

用户刚打开产品时,用入门引导替代空白视图。纵向排列 steps,每个步骤用一句话说明,并将下一步操作设为主按钮。已完成的步骤标为完成,aria-current="step" 标记当前步骤。

首次使用

<section class="sheet container-inline flex flex-col gap-lg p-xl max-w(560) mx-auto" aria-labelledby="es-steps-title">  <header class="flex flex-col gap-xs">    <h2 class="heading heading-lg" id="es-steps-title">Deploy your first project</h2>    <p class="m(0) leading-md">Three steps, about two minutes. You can stop after any of them.</p>  </header>  <ol class="steps steps-vertical">    <li class="steps-item">      <div class="steps-body">        <span class="steps-title">Connect a repository</span>        <span class="steps-description">Signed in with GitHub as yiching.</span>      </div>    </li>    <li class="steps-item" aria-current="step">      <div class="steps-body">        <span class="steps-title">Choose what to build</span>        <span class="steps-description">          Pick a repository and a branch. We detect the framework.        </span>      </div>    </li>    <li class="steps-item">      <div class="steps-body">        <span class="steps-title">Go live</span>        <span class="steps-description">Your site gets an address in under a minute.</span>      </div>    </li>  </ol>  <div class="flex flex-wrap gap-xs">    <button type="button" class="btn btn-primary">Choose a repository</button>    <button type="button" class="btn btn-quiet">Deploy an example instead</button>  </div></section>
<section className="sheet container-inline flex flex-col gap-lg p-xl max-w(560) mx-auto" aria-labelledby="es-steps-title">  <header className="flex flex-col gap-xs">    <h2 className="heading heading-lg" id="es-steps-title">Deploy your first project</h2>    <p className="m(0) leading-md">      Three steps, about two minutes. You can stop after any of them.    </p>  </header>  <ol className="steps steps-vertical">    <li className="steps-item">      <div className="steps-body">        <span className="steps-title">Connect a repository</span>        <span className="steps-description">Signed in with GitHub as yiching.</span>      </div>    </li>    <li className="steps-item" aria-current="step">      <div className="steps-body">        <span className="steps-title">Choose what to build</span>        <span className="steps-description">          Pick a repository and a branch. We detect the framework.        </span>      </div>    </li>    <li className="steps-item">      <div className="steps-body">        <span className="steps-title">Go live</span>        <span className="steps-description">Your site gets an address in under a minute.</span>      </div>    </li>  </ol>  <div className="flex flex-wrap gap-xs">    <button type="button" className="btn btn-primary">Choose a repository</button>    <button type="button" className="btn btn-quiet">Deploy an example instead</button>  </div></section>
<section class="sheet container-inline flex flex-col gap-lg p-xl max-w(560) mx-auto" aria-labelledby="es-steps-title">  <header class="flex flex-col gap-xs">    <h2 class="heading heading-lg" id="es-steps-title">Deploy your first project</h2>    <p class="m(0) leading-md">Three steps, about two minutes. You can stop after any of them.</p>  </header>  <ol class="steps steps-vertical">    <li class="steps-item">      <div class="steps-body">        <span class="steps-title">Connect a repository</span>        <span class="steps-description">Signed in with GitHub as yiching.</span>      </div>    </li>    <li class="steps-item" aria-current="step">      <div class="steps-body">        <span class="steps-title">Choose what to build</span>        <span class="steps-description">          Pick a repository and a branch. We detect the framework.        </span>      </div>    </li>    <li class="steps-item">      <div class="steps-body">        <span class="steps-title">Go live</span>        <span class="steps-description">Your site gets an address in under a minute.</span>      </div>    </li>  </ol>  <div class="flex flex-wrap gap-xs">    <button type="button" class="btn btn-primary">Choose a repository</button>    <button type="button" class="btn btn-quiet">Deploy an example instead</button>  </div></section>
<template>  <section class="sheet container-inline flex flex-col gap-lg p-xl max-w(560) mx-auto" aria-labelledby="es-steps-title">    <header class="flex flex-col gap-xs">      <h2 class="heading heading-lg" id="es-steps-title">Deploy your first project</h2>      <p class="m(0) leading-md">Three steps, about two minutes. You can stop after any of them.</p>    </header>    <ol class="steps steps-vertical">      <li class="steps-item">        <div class="steps-body">          <span class="steps-title">Connect a repository</span>          <span class="steps-description">Signed in with GitHub as yiching.</span>        </div>      </li>      <li class="steps-item" aria-current="step">        <div class="steps-body">          <span class="steps-title">Choose what to build</span>          <span class="steps-description">            Pick a repository and a branch. We detect the framework.          </span>        </div>      </li>      <li class="steps-item">        <div class="steps-body">          <span class="steps-title">Go live</span>          <span class="steps-description">Your site gets an address in under a minute.</span>        </div>      </li>    </ol>    <div class="flex flex-wrap gap-xs">      <button type="button" class="btn btn-primary">Choose a repository</button>      <button type="button" class="btn btn-quiet">Deploy an example instead</button>    </div>  </section></template>

#无结果

搜索或筛选没有结果时,原样显示搜索词,包括其中的拼写错误,并说明哪些筛选条件仍然生效。用户如果看不出列表为何为空,就会以为数据丢失了。

无结果

<section class="sheet container-inline" aria-live="polite" aria-labelledby="es-none-title">  <div class="empty">    <div class="icon-frame 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">        <circle cx="8.75" cy="8.75" r="5.75" /><path d="M12.8159 12.8159L17.5 17.5" />      </svg>    </div>    <h2 class="empty-title" id="es-none-title">No projects match “drfit”</h2>    <p class="empty-description">      Check the spelling, or search all workspaces. Filters are still applied: Ready, Tokyo.    </p>    <div class="empty-actions">      <button type="button" class="btn btn-sm">Clear filters</button>      <button type="button" class="btn btn-sm">Search all workspaces</button>    </div>  </div></section>
import SearchIcon from '@master/icons-react/native/20/soft/search'<section className="sheet container-inline" aria-live="polite" aria-labelledby="es-none-title">  <div className="empty">    <div className="icon-frame empty-media" aria-hidden="true"><SearchIcon className="icon" /></div>    <h2 className="empty-title" id="es-none-title">No projects match “drfit”</h2>    <p className="empty-description">      Check the spelling, or search all workspaces. Filters are still applied: Ready, Tokyo.    </p>    <div className="empty-actions">      <button type="button" className="btn btn-sm">Clear filters</button>      <button type="button" className="btn btn-sm">Search all workspaces</button>    </div>  </div></section>
<script>  import SearchIcon from '@master/icons-svelte/native/20/soft/search'</script><section class="sheet container-inline" aria-live="polite" aria-labelledby="es-none-title">  <div class="empty">    <div class="icon-frame empty-media" aria-hidden="true"><SearchIcon class="icon" /></div>    <h2 class="empty-title" id="es-none-title">No projects match “drfit”</h2>    <p class="empty-description">      Check the spelling, or search all workspaces. Filters are still applied: Ready, Tokyo.    </p>    <div class="empty-actions">      <button type="button" class="btn btn-sm">Clear filters</button>      <button type="button" class="btn btn-sm">Search all workspaces</button>    </div>  </div></section>
<script setup>import SearchIcon from '@master/icons-vue/native/20/soft/search'</script><template>  <section class="sheet container-inline" aria-live="polite" aria-labelledby="es-none-title">    <div class="empty">      <div class="icon-frame empty-media" aria-hidden="true"><SearchIcon class="icon" /></div>      <h2 class="empty-title" id="es-none-title">No projects match “drfit”</h2>      <p class="empty-description">        Check the spelling, or search all workspaces. Filters are still applied: Ready, Tokyo.      </p>      <div class="empty-actions">        <button type="button" class="btn btn-sm">Clear filters</button>        <button type="button" class="btn btn-sm">Search all workspaces</button>      </div>    </div>  </section></template>

该区域设为 aria-live="polite",因此从有结果变为无结果时,会在用户停止输入后播报这一变化。

#操作失败

操作失败和空状态是两回事,但都在视图的同一位置呈现。发生故障时,在该位置显示 alert。状态色和图标表明出了问题,文案说明具体情况,一个按钮提供后续操作。如果用户的工作未受影响,就明确告知。该区段保留发生故障的视图名称,用户仍能找到对应的无障碍地标区域。

操作失败

<section class="container-inline" aria-label="Projects">  <div class="alert alert-danger" role="alert">    <svg class="icon alert-icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">      <circle cx="8" cy="8" r="6" /><circle cx="8" cy="5" r="0.5" fill="currentColor" stroke="none" /><path d="M8 8L8 11" />    </svg>    <div class="alert-body">      <p class="alert-title">We could not load your projects</p>      <p class="alert-description">        The request timed out. Your projects are safe; this is on our side. <a class="link" href="#">Check the status page</a>.      </p>    </div>    <button type="button" class="btn btn-sm">Try again</button>  </div></section>
import InfoCircleIcon from '@master/icons-react/native/16/soft/info-circle'<section className="container-inline" aria-label="Projects">  <div className="alert alert-danger" role="alert">    <InfoCircleIcon className="icon alert-icon" />    <div className="alert-body">      <p className="alert-title">We could not load your projects</p>      <p className="alert-description">        The request timed out. Your projects are safe; this is on our side. <a className="link" href="#">Check the status page</a>.      </p>    </div>    <button type="button" className="btn btn-sm">Try again</button>  </div></section>
<script>  import InfoCircleIcon from '@master/icons-svelte/native/16/soft/info-circle'</script><section class="container-inline" aria-label="Projects">  <div class="alert alert-danger" role="alert">    <InfoCircleIcon class="icon alert-icon" />    <div class="alert-body">      <p class="alert-title">We could not load your projects</p>      <p class="alert-description">        The request timed out. Your projects are safe; this is on our side. <a class="link" href="#">Check the status page</a>.      </p>    </div>    <button type="button" class="btn btn-sm">Try again</button>  </div></section>
<script setup>import InfoCircleIcon from '@master/icons-vue/native/16/soft/info-circle'</script><template>  <section class="container-inline" aria-label="Projects">    <div class="alert alert-danger" role="alert">      <InfoCircleIcon class="icon alert-icon" />      <div class="alert-body">        <p class="alert-title">We could not load your projects</p>        <p class="alert-description">          The request timed out. Your projects are safe; this is on our side. <a class="link" href="#">Check the status page</a>.        </p>      </div>      <button type="button" class="btn btn-sm">Try again</button>    </div>  </section></template>

#无障碍

  • 空状态的标题与被替代视图的标题使用同一标题级别。
  • 因用户操作而出现的空状态需要播报。无结果时使用 aria-live="polite",操作失败时使用 role="alert"。
  • 图标仅用于装饰。切勿依靠图标或其颜色来区分这些情况。
  • “阅读指南”会跳转到其他位置,因此使用呈现为按钮样式的链接。“新建项目”会执行操作,因此使用按钮。
  • 空状态的主要操作应与视图有内容时提供的主要操作一致,用户只需学会一次。