导航

v2.1.0
表单

核对清单

自动统计已完成项数的简短待办清单。

本页内容

核对清单是简短的待办列表,可用于列出设置步骤或审核要点。每一步都使用原生复选框,放在带有标题和一行提示的标签内。完成后,该步骤的视觉权重降低,标题上会出现一条细线,清单会自动统计完成数量。

核对清单

<div class="card max-w(400) mx-auto">  <div class="card-header">    <h3 class="card-title">Get Atlas ready</h3>  </div>  <ul class="checklist">    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox" checked>        <span class="checklist-body">          <span class="checklist-title">Create a project</span>          <span class="checklist-description">Atlas was created on 3 November.</span>        </span>      </label>    </li>    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox" checked>        <span class="checklist-body">          <span class="checklist-title">Connect a repository</span>          <span class="checklist-description">Deploy every push to the main branch.</span>        </span>      </label>    </li>    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox">        <span class="checklist-body">          <span class="checklist-title">Add a domain</span>          <span class="checklist-description">Point a domain you own at the project.</span>        </span>        <span class="checklist-end"><span class="badge badge-sm">2 min</span></span>      </label>    </li>    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox">        <span class="checklist-body">          <span class="checklist-title">Invite your team</span>          <span class="checklist-description">Members can deploy and read the logs.</span>        </span>      </label>    </li>    <li class="checklist-count">steps done</li>  </ul></div>
<div className="card max-w(400) mx-auto">  <div className="card-header">    <h3 className="card-title">Get Atlas ready</h3>  </div>  <ul className="checklist">    <li className="checklist-item">      <label className="checklist-label">        <input type="checkbox" className="checkbox" defaultChecked />        <span className="checklist-body">          <span className="checklist-title">Create a project</span>          <span className="checklist-description">Atlas was created on 3 November.</span>        </span>      </label>    </li>    <li className="checklist-item">      <label className="checklist-label">        <input type="checkbox" className="checkbox" defaultChecked />        <span className="checklist-body">          <span className="checklist-title">Connect a repository</span>          <span className="checklist-description">Deploy every push to the main branch.</span>        </span>      </label>    </li>    <li className="checklist-item">      <label className="checklist-label">        <input type="checkbox" className="checkbox" />        <span className="checklist-body">          <span className="checklist-title">Add a domain</span>          <span className="checklist-description">Point a domain you own at the project.</span>        </span>        <span className="checklist-end"><span className="badge badge-sm">2 min</span></span>      </label>    </li>    <li className="checklist-item">      <label className="checklist-label">        <input type="checkbox" className="checkbox" />        <span className="checklist-body">          <span className="checklist-title">Invite your team</span>          <span className="checklist-description">Members can deploy and read the logs.</span>        </span>      </label>    </li>    <li className="checklist-count">steps done</li>  </ul></div>
<div class="card max-w(400) mx-auto">  <div class="card-header">    <h3 class="card-title">Get Atlas ready</h3>  </div>  <ul class="checklist">    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox" checked>        <span class="checklist-body">          <span class="checklist-title">Create a project</span>          <span class="checklist-description">Atlas was created on 3 November.</span>        </span>      </label>    </li>    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox" checked>        <span class="checklist-body">          <span class="checklist-title">Connect a repository</span>          <span class="checklist-description">Deploy every push to the main branch.</span>        </span>      </label>    </li>    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox">        <span class="checklist-body">          <span class="checklist-title">Add a domain</span>          <span class="checklist-description">Point a domain you own at the project.</span>        </span>        <span class="checklist-end"><span class="badge badge-sm">2 min</span></span>      </label>    </li>    <li class="checklist-item">      <label class="checklist-label">        <input type="checkbox" class="checkbox">        <span class="checklist-body">          <span class="checklist-title">Invite your team</span>          <span class="checklist-description">Members can deploy and read the logs.</span>        </span>      </label>    </li>    <li class="checklist-count">steps done</li>  </ul></div>
<template>  <div class="card max-w(400) mx-auto">    <div class="card-header">      <h3 class="card-title">Get Atlas ready</h3>    </div>    <ul class="checklist">      <li class="checklist-item">        <label class="checklist-label">          <input type="checkbox" class="checkbox" checked>          <span class="checklist-body">            <span class="checklist-title">Create a project</span>            <span class="checklist-description">Atlas was created on 3 November.</span>          </span>        </label>      </li>      <li class="checklist-item">        <label class="checklist-label">          <input type="checkbox" class="checkbox" checked>          <span class="checklist-body">            <span class="checklist-title">Connect a repository</span>            <span class="checklist-description">Deploy every push to the main branch.</span>          </span>        </label>      </li>      <li class="checklist-item">        <label class="checklist-label">          <input type="checkbox" class="checkbox">          <span class="checklist-body">            <span class="checklist-title">Add a domain</span>            <span class="checklist-description">Point a domain you own at the project.</span>          </span>          <span class="checklist-end"><span class="badge badge-sm">2 min</span></span>        </label>      </li>      <li class="checklist-item">        <label class="checklist-label">          <input type="checkbox" class="checkbox">          <span class="checklist-body">            <span class="checklist-title">Invite your team</span>            <span class="checklist-description">Members can deploy and read the logs.</span>          </span>        </label>      </li>      <li class="checklist-count">steps done</li>    </ul>  </div></template>
勾选一个步骤,清单下方的计数随即更新,无需脚本。

#自动计数

两个 CSS 计数器分别统计总数和完成数。每个 checklist-item 都让总数加一,通过 :has() 匹配到复选框已选中的条目让完成数加一。checklist-count 显示这两个数字。

计数器按文档顺序计数,因此要把计数放在标记中的所有步骤之后,此时两个数字都已统计完毕。说明文字放在数字之后,可自行翻译。--checklist-of 指定两个数字之间的内容,默认值为 ' / '。要显示“2 of 4”,请将它设为 ' of '。

计数属于 CSS 生成内容,数值始终准确,但变化不会自动播报。如果清单是否全部完成很重要,请自行提供状态消息。

#单个步骤

标签覆盖整行,点击文字的任意位置都能勾选复选框。checklist-title 特意采用行内元素,已完成标题上的删除线由沿文字延伸的背景绘制,标题无论如何换行,线条都保持为一条。checklist-end 用于在步骤末尾放置附加信息,例如所需时间。

与列表一样,各行之间用从文字处起始的细线分隔。核对清单本身没有独立的表面,请将它放入卡片中。

#无障碍

  • 使用 <ul>,如果步骤必须按顺序完成,则使用 <ol>。
  • 这里的复选框表示读者自行设置的状态。系统完成的步骤请用步骤组件展示,因为读者无法更改的复选框是禁用控件,不是完成记录。
  • 带删除线的标题仍使用较淡的文字颜色,并保持足够的对比度以便阅读。完成状态由复选框表达,而非删除线。

#类名

类名说明
checklist将列表类用于 ul,步骤需按顺序完成时使用 ol。列表会统计步骤总数和已勾选数。
checklist-item将此类用于步骤的 li。每项计入步骤总数,复选框勾选时也计入已完成数
checklist-label标签中先放复选框,再放文字。整行均可点击以切换勾选状态,触摸屏上整行高 44px。
checklist-body步骤文字,标题在上,说明在下。
checklist-title将步骤名称放在行内元素上。步骤完成时,名称会显示细删除线。
checklist-description标题下方的一行低对比度帮助文字
checklist-end步骤末尾的内容,例如链接、徽标或时间
checklist-count在自身文案前显示已完成的步骤数和总步骤数,并在标记中放在最后一步之后

#自定义属性

属性默认值说明
--checklist-of' / '两个计数数字之间的内容
--checklist-gap.75rem复选框与文字的间距

#源码

@master/ui/components/checklist.css
/* * Checklist: a short list of things to do, each a native checkbox with a title and a line of help. * A row is a label, so the whole of it checks the box. A step that is done steps back: its title turns to * the muted ink and a hairline is drawn through it from its start, the way a pen would. * The list counts itself. CSS counters add up the rows and, with :has(), the checked ones; checklist-count * writes the two numbers after the rows, so "2 / 5" is always true without a script. * Rows part on hairlines that start at the text, as a list's do. A checklist has no surface of its own. */@layer components.ui {  .checklist {    --checklist-gap: .75rem;    --checklist-padding-y: .6875rem;    /* What stands between the two numbers of the count. */    --checklist-of: ' / ';    display: flex;    flex-direction: column;    min-width: 0;    margin: 0;    padding: 0;    color: var(--color-text-body);    font-size: .875rem;    line-height: 1.45;    list-style: none;    counter-reset: checklist-total checklist-done;    /* On touch a row is 44px: the same line of words with a little more room over and under it. */    @media (pointer: coarse) {      --checklist-padding-y: .75rem;    }  }  /* A step. It counts itself, and counts itself done while its checkbox is checked. */  .checklist-item {    position: relative;    min-width: 0;    margin: 0;    padding: 0;    counter-increment: checklist-total;    &:has(.checkbox:checked) {      counter-increment: checklist-total checklist-done;    }    /* The hairline under a step that another follows; it starts where the words do, past the 18px checkbox. */    &:has(+ .checklist-item)::after {      content: '';      position: absolute;      inset-inline: calc(1.125rem + var(--checklist-gap)) 0;      inset-block-end: 0;      height: 1px;      background: var(--color-line-hair);      pointer-events: none;      /* Forced colors would turn the hairline's fill to the canvas: it keeps a system color. */      @media (forced-colors: active) {        background: GrayText;      }    }  }  /* The label: the checkbox, then the words. The box is level with the first line of the title. */  .checklist-label {    display: flex;    align-items: flex-start;    gap: var(--checklist-gap);    min-width: 0;    padding: var(--checklist-padding-y) 0;    cursor: pointer;    touch-action: manipulation;    -webkit-tap-highlight-color: transparent;    &:has(.checkbox:disabled) {      cursor: not-allowed;    }    .checkbox {      flex: none;      margin-block-start: calc((1lh - var(--check-size)) / 2);    }  }  /* A block, not a grid: an item of a grid is made a block, and the title has to stay inline. */  .checklist-body {    display: block;    flex: 1 1 0;    /* The words and the end share the title's baseline; the box stands on the first line, as the box does. */    align-self: baseline;    min-width: 0;  }  /*   * The title is inline, so the stroke through it is one line however the title wraps: it is a background   * that grows from nothing to the title's whole length.   */  .checklist-title {    background: linear-gradient(currentColor, currentColor) 0 calc(50% + .0625em) / 0 1px no-repeat;    color: var(--color-text-strong);    font-weight: var(--font-weight-control);    /* A long word or an address breaks inside the column, as the line of help under it does. */    overflow-wrap: anywhere;    transition-property: background-size, color;    transition-duration: var(--duration-base), var(--duration-quick);    transition-timing-function: var(--easing-glide);    /* Right to left the pen starts at the right. */    &:dir(rtl) {      background-position-x: 100%;    }    @media (prefers-reduced-motion: reduce) {      transition: none;    }  }  .checklist-item:has(.checkbox:checked) .checklist-title {    background-size: 100% 1px;    color: var(--color-text-muted);  }  .checklist-item:has(.checkbox:disabled) .checklist-title {    color: var(--color-text-disabled);    /* Forced colors would give it the page's text color back: a step that cannot be ticked keeps the system's disabled ink. */    @media (forced-colors: active) {      color: GrayText;    }  }  .checklist-description {    display: block;    margin: .125rem 0 0;    color: var(--color-text-muted);    font-size: .8125rem;    text-wrap: pretty;    overflow-wrap: anywhere;  }  /*   * Something at the end of a step: a link to where it is done, a badge, a time. It belongs to the title, so it   * stands on the title's first line, as the box at the start does, not in the middle of the title and the line of   * help under it.   */  .checklist-end {    display: inline-flex;    flex: none;    align-items: center;    align-self: baseline;    gap: .5rem;    color: var(--color-text-muted);    font-size: .8125rem;    /* A time or a count, in figures of one width, as at the end of a list's row. */    font-variant-numeric: tabular-nums;  }  /*   * The count: how many steps are done, of how many. It comes after the steps in the markup, where the   * counters have their final values; its own words follow the numbers.   */  .checklist-count {    margin: .625rem 0 0;    color: var(--color-text-muted);    font-size: .8125rem;    font-variant-numeric: tabular-nums;    &::before {      content: counter(checklist-done) var(--checklist-of) counter(checklist-total) ' ';      color: var(--color-text-strong);      font-weight: var(--font-weight-control);    }  }}