網站導覽

v2.1.0
表單

膠囊標籤

用於切換篩選條件或顯示可移除值的小型膠囊標籤。

本頁內容

膠囊標籤(Chip)用來呈現選項或值,兩端呈半圓,便於和徽章區分。徽章用來描述資訊,膠囊標籤則可以操作。用於篩選時,膠囊標籤以 <label> 包住原生核取方塊或單選按鈕,未選取時呈凸起狀,選取後會像核取方塊一樣填上墨色。

膠囊標籤

<fieldset class="flex flex-wrap gap-xs m(0) p(0) b(0)">  <legend class="mb-xs text-sm fg-text-strong">Topics</legend>  <label class="chip">    <input type="checkbox" class="chip-input" name="topic" value="design" checked>Design  </label>  <label class="chip">    <input type="checkbox" class="chip-input" name="topic" value="engineering">Engineering  </label>  <label class="chip">    <input type="checkbox" class="chip-input" name="topic" value="research" checked>Research  </label>  <label class="chip">    <input type="checkbox" class="chip-input" name="topic" value="legal" disabled>Legal  </label></fieldset>
<fieldset className="flex flex-wrap gap-xs m(0) p(0) b(0)">  <legend className="mb-xs text-sm fg-text-strong">Topics</legend>  <label className="chip">    <input type="checkbox" className="chip-input" name="topic" value="design" defaultChecked />Design  </label>  <label className="chip">    <input type="checkbox" className="chip-input" name="topic" value="engineering" />Engineering  </label>  <label className="chip">    <input type="checkbox" className="chip-input" name="topic" value="research" defaultChecked />Research  </label>  <label className="chip">    <input type="checkbox" className="chip-input" name="topic" value="legal" disabled />Legal  </label></fieldset>
<fieldset class="flex flex-wrap gap-xs m(0) p(0) b(0)">  <legend class="mb-xs text-sm fg-text-strong">Topics</legend>  <label class="chip">    <input type="checkbox" class="chip-input" name="topic" value="design" checked>Design  </label>  <label class="chip">    <input type="checkbox" class="chip-input" name="topic" value="engineering">Engineering  </label>  <label class="chip">    <input type="checkbox" class="chip-input" name="topic" value="research" checked>Research  </label>  <label class="chip">    <input type="checkbox" class="chip-input" name="topic" value="legal" disabled>Legal  </label></fieldset>
<template>  <fieldset class="flex flex-wrap gap-xs m(0) p(0) b(0)">    <legend class="mb-xs text-sm fg-text-strong">Topics</legend>    <label class="chip">      <input type="checkbox" class="chip-input" name="topic" value="design" checked>Design    </label>    <label class="chip">      <input type="checkbox" class="chip-input" name="topic" value="engineering">Engineering    </label>    <label class="chip">      <input type="checkbox" class="chip-input" name="topic" value="research" checked>Research    </label>    <label class="chip">      <input type="checkbox" class="chip-input" name="topic" value="legal" disabled>Legal    </label>  </fieldset></template>

#單選

當單選按鈕共用同一個 name 時,這組膠囊標籤只能選一個,也可以用方向鍵切換。適合用於選項不多、選取後就會立即更新檢視內容的情況。若要在表單裡選擇一個值,可用分段控制項呈現為單一控制項。

單選

<div class="flex flex-wrap gap-xs" role="radiogroup" aria-label="Period">  <label class="chip"><input type="radio" class="chip-input" name="period" checked>Today</label>  <label class="chip"><input type="radio" class="chip-input" name="period">7 days</label>  <label class="chip"><input type="radio" class="chip-input" name="period">30 days</label>  <label class="chip"><input type="radio" class="chip-input" name="period">All time</label></div>
<div className="flex flex-wrap gap-xs" role="radiogroup" aria-label="Period">  <label className="chip">    <input type="radio" className="chip-input" name="period" defaultChecked />Today  </label>  <label className="chip"><input type="radio" className="chip-input" name="period" />7 days</label>  <label className="chip"><input type="radio" className="chip-input" name="period" />30 days</label>  <label className="chip">    <input type="radio" className="chip-input" name="period" />All time  </label></div>
<div class="flex flex-wrap gap-xs" role="radiogroup" aria-label="Period">  <label class="chip"><input type="radio" class="chip-input" name="period" checked>Today</label>  <label class="chip"><input type="radio" class="chip-input" name="period">7 days</label>  <label class="chip"><input type="radio" class="chip-input" name="period">30 days</label>  <label class="chip"><input type="radio" class="chip-input" name="period">All time</label></div>
<template>  <div class="flex flex-wrap gap-xs" role="radiogroup" aria-label="Period">    <label class="chip"><input type="radio" class="chip-input" name="period" checked>Today</label>    <label class="chip"><input type="radio" class="chip-input" name="period">7 days</label>    <label class="chip"><input type="radio" class="chip-input" name="period">30 days</label>    <label class="chip"><input type="radio" class="chip-input" name="period">All time</label>  </div></template>

#值

不含輸入元件的膠囊標籤用來呈現值,例如收件者、標籤或已套用的篩選條件。預設使用膠囊標籤的底色,並加上一道細外框。chip-remove 是末端的圓形移除按鈕,請在按鈕名稱中包含該值。若開頭有圖示,請在該圖示上加上 icon。

值

<span class="chip">  ada@example.com<button type="button" class="chip-remove" aria-label="Remove ada@example.com">    <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="M4 4L12 12" /><path d="M4 12L12 4" />    </svg>  </button></span><span class="chip">  alan@example.com<button type="button" class="chip-remove" aria-label="Remove alan@example.com">    <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="M4 4L12 12" /><path d="M4 12L12 4" />    </svg>  </button></span><span class="chip">  <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="M4.5365 3L11.4635 3A1 1 0 0 1 12.2548 4.6114L9.4587 8.2299A1 1 0 0 0 9.25 8.8413L9.25 11.323A1 1 0 0 1 8.6214 12.2514L7.875 12.55A0.8203 0.8203 0 0 1 6.75 11.7883L6.75 8.8413A1 1 0 0 0 6.5413 8.2299L3.7452 4.6114A1 1 0 0 1 4.5365 3Z" />  </svg> Status: Ready</span>
import XIcon from '@master/icons-react/native/16/soft/x'import FilterIcon from '@master/icons-react/native/16/soft/filter'<>  <span className="chip">    ada@example.com<button type="button" className="chip-remove" aria-label="Remove ada@example.com">      <XIcon className="icon" />    </button>  </span>  <span className="chip">    alan@example.com<button type="button" className="chip-remove" aria-label="Remove alan@example.com">      <XIcon className="icon" />    </button>  </span>  <span className="chip"><FilterIcon className="icon" /> Status: Ready</span></>
<script>  import XIcon from '@master/icons-svelte/native/16/soft/x'  import FilterIcon from '@master/icons-svelte/native/16/soft/filter'</script><span class="chip">  ada@example.com<button type="button" class="chip-remove" aria-label="Remove ada@example.com">    <XIcon class="icon" />  </button></span><span class="chip">  alan@example.com<button type="button" class="chip-remove" aria-label="Remove alan@example.com">    <XIcon class="icon" />  </button></span><span class="chip"><FilterIcon class="icon" /> Status: Ready</span>
<script setup>import XIcon from '@master/icons-vue/native/16/soft/x'import FilterIcon from '@master/icons-vue/native/16/soft/filter'</script><template>  <span class="chip">    ada@example.com<button type="button" class="chip-remove" aria-label="Remove ada@example.com">      <XIcon class="icon" />    </button>  </span>  <span class="chip">    alan@example.com<button type="button" class="chip-remove" aria-label="Remove alan@example.com">      <XIcon class="icon" />    </button>  </span>  <span class="chip"><FilterIcon class="icon" /> Status: Ready</span></template>

#圖片、圓點與數量

膠囊標籤可依序包含:圖片(chip-media,可放頭像或圖示,由它決定大小並裁成圓形)、分類圓點(chip-dot)、文字(chip-label)、數量(加上 chip-count 的徽章)和移除按鈕(chip-remove,內含其圖示)。空間不足時文字會先縮短並以省略號結尾;圖片、數量和按鈕則維持原本大小。開頭的圖片和末端的數量與膠囊標籤端點的距離,等於它們與上下緣的距離,因此弧線是同心的。

圖片、圓點與數量

<span class="chip">  <span class="chip-media">    <span class="avatar"><img class="avatar-image" src="/demo/portrait-1.svg" alt></span>  </span><span class="chip-label">Ada Lovelace</span><button type="button" class="chip-remove" aria-label="Remove Ada Lovelace">    <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="M4 4L12 12" /><path d="M4 12L12 4" />    </svg>  </button></span><span class="chip">  <span class="chip-media"><span class="avatar" aria-hidden="true">GH</span></span><span class="chip-label">Grace Hopper</span><button type="button" class="chip-remove" aria-label="Remove Grace Hopper">    <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="M4 4L12 12" /><path d="M4 12L12 4" />    </svg>  </button></span><span class="chip max-w(176)" title="Accessibility review for the checkout">  <span class="chip-dot"></span><span class="chip-label">Accessibility review for the checkout</span><span class="badge chip-count">12</span></span>
import XIcon from '@master/icons-react/native/16/soft/x'<>  <span className="chip">    <span className="chip-media">      <span className="avatar">        <img className="avatar-image" src="/demo/portrait-1.svg" alt="" />      </span>    </span><span className="chip-label">Ada Lovelace</span><button type="button" className="chip-remove" aria-label="Remove Ada Lovelace">      <XIcon className="icon" />    </button>  </span>  <span className="chip">    <span className="chip-media"><span className="avatar" aria-hidden="true">GH</span></span><span className="chip-label">Grace Hopper</span><button type="button" className="chip-remove" aria-label="Remove Grace Hopper">      <XIcon className="icon" />    </button>  </span>  <span className="chip max-w(176)" title="Accessibility review for the checkout">    <span className="chip-dot"></span><span className="chip-label">Accessibility review for the checkout</span><span className="badge chip-count">12</span>  </span></>
<script>  import XIcon from '@master/icons-svelte/native/16/soft/x'</script><span class="chip">  <span class="chip-media">    <span class="avatar"><img class="avatar-image" src="/demo/portrait-1.svg" alt></span>  </span><span class="chip-label">Ada Lovelace</span><button type="button" class="chip-remove" aria-label="Remove Ada Lovelace">    <XIcon class="icon" />  </button></span><span class="chip">  <span class="chip-media"><span class="avatar" aria-hidden="true">GH</span></span><span class="chip-label">Grace Hopper</span><button type="button" class="chip-remove" aria-label="Remove Grace Hopper">    <XIcon class="icon" />  </button></span><span class="chip max-w(176)" title="Accessibility review for the checkout">  <span class="chip-dot"></span><span class="chip-label">Accessibility review for the checkout</span><span class="badge chip-count">12</span></span>
<script setup>import XIcon from '@master/icons-vue/native/16/soft/x'</script><template>  <span class="chip">    <span class="chip-media">      <span class="avatar"><img class="avatar-image" src="/demo/portrait-1.svg" alt></span>    </span><span class="chip-label">Ada Lovelace</span><button type="button" class="chip-remove" aria-label="Remove Ada Lovelace">      <XIcon class="icon" />    </button>  </span>  <span class="chip">    <span class="chip-media"><span class="avatar" aria-hidden="true">GH</span></span><span class="chip-label">Grace Hopper</span><button type="button" class="chip-remove" aria-label="Remove Grace Hopper">      <XIcon class="icon" />    </button>  </span>  <span class="chip max-w(176)" title="Accessibility review for the checkout">    <span class="chip-dot"></span><span class="chip-label">Accessibility review for the checkout</span><span class="badge chip-count">12</span>  </span></template>

數量是一個徽章,因此保有徽章的質感;在已選取的篩選標籤上,它會改用墨色的色調。

篩選標籤上的數量

<div class="flex flex-wrap gap-xs" role="group" aria-label="Status">  <label class="chip">    <input type="checkbox" class="chip-input" checked>Open <span class="badge chip-count">24</span>  </label>  <label class="chip">    <input type="checkbox" class="chip-input">In review <span class="badge chip-count">7</span>  </label>  <label class="chip">    <input type="checkbox" class="chip-input">Closed <span class="badge chip-count">132</span>  </label></div>
<div className="flex flex-wrap gap-xs" role="group" aria-label="Status">  <label className="chip">    <input type="checkbox" className="chip-input" defaultChecked />Open <span className="badge chip-count">24</span>  </label>  <label className="chip">    <input type="checkbox" className="chip-input" />In review <span className="badge chip-count">7</span>  </label>  <label className="chip">    <input type="checkbox" className="chip-input" />Closed <span className="badge chip-count">132</span>  </label></div>
<div class="flex flex-wrap gap-xs" role="group" aria-label="Status">  <label class="chip">    <input type="checkbox" class="chip-input" checked>Open <span class="badge chip-count">24</span>  </label>  <label class="chip">    <input type="checkbox" class="chip-input">In review <span class="badge chip-count">7</span>  </label>  <label class="chip">    <input type="checkbox" class="chip-input">Closed <span class="badge chip-count">132</span>  </label></div>
<template>  <div class="flex flex-wrap gap-xs" role="group" aria-label="Status">    <label class="chip">      <input type="checkbox" class="chip-input" checked>Open <span class="badge chip-count">24</span>    </label>    <label class="chip">      <input type="checkbox" class="chip-input">In review <span class="badge chip-count">7</span>    </label>    <label class="chip">      <input type="checkbox" class="chip-input">Closed <span class="badge chip-count">132</span>    </label>  </div></template>

篩選標籤是包住輸入元件的標籤,整個膠囊標籤都是點按目標,因此不要在其中放移除按鈕。可移除的值應使用帶有 chip-remove 的一般膠囊標籤。

#分類色

chip-category 會讀取膠囊標籤本身或其外層所設定的分類色。值會套用該分類的底面、文字與線條。篩選標籤則保留凸起的外觀,選取時仍填上墨色,讓各分類的選取狀態看起來都一樣;分類由它的 chip-dot 表示。

分類色

<div class="flex flex-col items-center gap-sm">  <div class="flex flex-wrap justify-center gap-xs">    <span class="chip chip-category category-violet">      <span class="chip-dot"></span>Research<button type="button" class="chip-remove" aria-label="Remove Research">        <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="M4 4L12 12" /><path d="M4 12L12 4" />        </svg>      </button>    </span>    <span class="chip chip-category category-teal">      <span class="chip-dot"></span>Design system<button type="button" class="chip-remove" aria-label="Remove Design system">        <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="M4 4L12 12" /><path d="M4 12L12 4" />        </svg>      </button>    </span>  </div>  <div class="flex flex-wrap justify-center gap-xs" role="group" aria-label="Projects">    <label class="chip chip-category category-violet">      <input type="checkbox" class="chip-input" checked><span class="chip-dot"></span>Research    </label>    <label class="chip chip-category category-teal">      <input type="checkbox" class="chip-input"><span class="chip-dot"></span>Design system    </label>    <label class="chip chip-category category-orange">      <input type="checkbox" class="chip-input"><span class="chip-dot"></span>Launch    </label>  </div></div>
import XIcon from '@master/icons-react/native/16/soft/x'<div className="flex flex-col items-center gap-sm">  <div className="flex flex-wrap justify-center gap-xs">    <span className="chip chip-category category-violet">      <span className="chip-dot"></span>Research<button type="button" className="chip-remove" aria-label="Remove Research">        <XIcon className="icon" />      </button>    </span>    <span className="chip chip-category category-teal">      <span className="chip-dot"></span>Design system<button type="button" className="chip-remove" aria-label="Remove Design system">        <XIcon className="icon" />      </button>    </span>  </div>  <div className="flex flex-wrap justify-center gap-xs" role="group" aria-label="Projects">    <label className="chip chip-category category-violet">      <input type="checkbox" className="chip-input" defaultChecked /><span className="chip-dot"></span>Research    </label>    <label className="chip chip-category category-teal">      <input type="checkbox" className="chip-input" /><span className="chip-dot"></span>Design system    </label>    <label className="chip chip-category category-orange">      <input type="checkbox" className="chip-input" /><span className="chip-dot"></span>Launch    </label>  </div></div>
<script>  import XIcon from '@master/icons-svelte/native/16/soft/x'</script><div class="flex flex-col items-center gap-sm">  <div class="flex flex-wrap justify-center gap-xs">    <span class="chip chip-category category-violet">      <span class="chip-dot"></span>Research<button type="button" class="chip-remove" aria-label="Remove Research">        <XIcon class="icon" />      </button>    </span>    <span class="chip chip-category category-teal">      <span class="chip-dot"></span>Design system<button type="button" class="chip-remove" aria-label="Remove Design system">        <XIcon class="icon" />      </button>    </span>  </div>  <div class="flex flex-wrap justify-center gap-xs" role="group" aria-label="Projects">    <label class="chip chip-category category-violet">      <input type="checkbox" class="chip-input" checked><span class="chip-dot"></span>Research    </label>    <label class="chip chip-category category-teal">      <input type="checkbox" class="chip-input"><span class="chip-dot"></span>Design system    </label>    <label class="chip chip-category category-orange">      <input type="checkbox" class="chip-input"><span class="chip-dot"></span>Launch    </label>  </div></div>
<script setup>import XIcon from '@master/icons-vue/native/16/soft/x'</script><template>  <div class="flex flex-col items-center gap-sm">    <div class="flex flex-wrap justify-center gap-xs">      <span class="chip chip-category category-violet">        <span class="chip-dot"></span>Research<button type="button" class="chip-remove" aria-label="Remove Research">          <XIcon class="icon" />        </button>      </span>      <span class="chip chip-category category-teal">        <span class="chip-dot"></span>Design system<button type="button" class="chip-remove" aria-label="Remove Design system">          <XIcon class="icon" />        </button>      </span>    </div>    <div class="flex flex-wrap justify-center gap-xs" role="group" aria-label="Projects">      <label class="chip chip-category category-violet">        <input type="checkbox" class="chip-input" checked><span class="chip-dot"></span>Research      </label>      <label class="chip chip-category category-teal">        <input type="checkbox" class="chip-input"><span class="chip-dot"></span>Design system      </label>      <label class="chip chip-category category-orange">        <input type="checkbox" class="chip-input"><span class="chip-dot"></span>Launch      </label>    </div>  </div></template>

#尺寸

chip-sm 為 24px,chip-lg 為 32px,預設為 28px。移除按鈕、圖片和數量會隨之縮放。在觸控螢幕上,膠囊標籤維持原本的高度:篩選標籤的點按範圍會向膠囊外側延伸,高度達 44px;移除按鈕的點按範圍也會增至 44px 高,且不超過該值所屬膠囊標籤的末端。容納多個值的欄位(例如標籤輸入)會自行設定這些值的高度。

尺寸

<span class="chip chip-sm">  <span class="chip-dot"></span>Small<button type="button" class="chip-remove" aria-label="Remove Small">    <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="M4 4L12 12" /><path d="M4 12L12 4" />    </svg>  </button></span><span class="chip">  <span class="chip-dot"></span>Medium<button type="button" class="chip-remove" aria-label="Remove Medium">    <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="M4 4L12 12" /><path d="M4 12L12 4" />    </svg>  </button></span><span class="chip chip-lg">  <span class="chip-dot"></span>Large<button type="button" class="chip-remove" aria-label="Remove Large">    <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="M4 4L12 12" /><path d="M4 12L12 4" />    </svg>  </button></span>
import XIcon from '@master/icons-react/native/16/soft/x'<>  <span className="chip chip-sm">    <span className="chip-dot"></span>Small<button type="button" className="chip-remove" aria-label="Remove Small">      <XIcon className="icon" />    </button>  </span>  <span className="chip">    <span className="chip-dot"></span>Medium<button type="button" className="chip-remove" aria-label="Remove Medium">      <XIcon className="icon" />    </button>  </span>  <span className="chip chip-lg">    <span className="chip-dot"></span>Large<button type="button" className="chip-remove" aria-label="Remove Large">      <XIcon className="icon" />    </button>  </span></>
<script>  import XIcon from '@master/icons-svelte/native/16/soft/x'</script><span class="chip chip-sm">  <span class="chip-dot"></span>Small<button type="button" class="chip-remove" aria-label="Remove Small">    <XIcon class="icon" />  </button></span><span class="chip">  <span class="chip-dot"></span>Medium<button type="button" class="chip-remove" aria-label="Remove Medium">    <XIcon class="icon" />  </button></span><span class="chip chip-lg">  <span class="chip-dot"></span>Large<button type="button" class="chip-remove" aria-label="Remove Large">    <XIcon class="icon" />  </button></span>
<script setup>import XIcon from '@master/icons-vue/native/16/soft/x'</script><template>  <span class="chip chip-sm">    <span class="chip-dot"></span>Small<button type="button" class="chip-remove" aria-label="Remove Small">      <XIcon class="icon" />    </button>  </span>  <span class="chip">    <span class="chip-dot"></span>Medium<button type="button" class="chip-remove" aria-label="Remove Medium">      <XIcon class="icon" />    </button>  </span>  <span class="chip chip-lg">    <span class="chip-dot"></span>Large<button type="button" class="chip-remove" aria-label="Remove Large">      <XIcon class="icon" />    </button>  </span></template>

#無障礙

  • 篩選標籤裡的輸入元件會以不可見的方式覆蓋整個膠囊標籤,因此整個標籤都能點按,輸入元件則負責狀態、鍵盤操作和表單值。用帶有 <legend> 的 <fieldset>,或帶有標籤的 role="radiogroup" 為篩選標籤分組。
  • 移除按鈕的點按範圍會超出圖示,圖示位置維持固定。點按範圍一般為 28px,在觸控螢幕上高 44px,且絕不會超出它所屬的值的末端。
  • 分類圓點只是裝飾:分類由膠囊標籤的文字說明。
  • 選取的膠囊標籤在 moonstone 主題中呈墨色,在 obsidian 主題中呈珍珠色。兩者皆為中性色,無須靠辨識色相來判斷狀態。

#類別

類別說明
chip膠囊本體,高 28px:包住 chip-input 的標籤,或容納值的一般元素。在觸控螢幕上,篩選標籤和移除按鈕的觸控區高度擴至 44px,膠囊本身維持原有高度
chip-sm高 24px;預設為 28px搭配 chip 使用
chip-lg高 32px;預設為 28px搭配 chip 使用
chip-category值會套用其本身或外層 category-<name> 類別所設定分類的底面、文字與線條;篩選標籤則保留原本的外觀,並在其 chip-dot 中顯示分類搭配 chip 使用
chip-input篩選標籤內的核取方塊或單選按鈕。輸入控制項以透明方式覆蓋整個膠囊標籤,因此整個 label 都可操作,並由輸入控制項保存狀態。
chip-remove值末端的圓形移除按鈕,內含其圖示,無障礙名稱須包含該值。
chip-label文字:空間不足時會先縮短並以省略號結尾,讓圖片、數量和移除按鈕維持原本大小
chip-media開頭的圓形圖片,大小為膠囊標籤高度減去兩倍內距:可容納頭像或圖示,並決定其大小
chip-dot8px 的圓點,使用分類的標記色,沒有分類時則使用淡墨色;它只是裝飾,因此由標籤寫出分類名稱
chip-count加在膠囊標籤內的徽章上:讓它成為與膠囊標籤同心的膠囊形狀,並在已選取的篩選標籤上改用墨色的色調

#自訂屬性

屬性預設值說明
--chip-height1.75rem高度;容納值的欄位會為其凹槽中的膠囊標籤設定此值
--chip-inset.25remchip-media 或 chip-count 與膠囊標籤端點之間的距離

#原始碼

@master/ui/components/chip.css
/* * Chip: a small pill that is a choice or a value. * As a label around a checkbox or a radio it is a filter: raised at rest, filled with ink when chosen, * the way a checkbox fills. As a plain element it is a value that can carry a remove button. * A chip is 28px tall (24px small, 32px large); its ends are true half circles, which tells it apart from a badge. * * Inside, a chip may hold a picture at its start (chip-media), a category dot (chip-dot), its words (chip-label, * which shrinks and ends in an ellipsis), a count (a badge with chip-count) and a remove button. The words give * way first; the picture, the count and the button keep their size. With chip-category a value takes its * category's surface, text and line, and a filter keeps its raised face and shows the category in its dot. */@layer components.ui {  .chip {    --chip-height: 1.75rem;    --chip-padding-x: .625rem;    --chip-font-size: .78125rem;    --chip-inset: .25rem;    --chip-remove-size: 1.25rem;    --icon-size: .875rem;    --icon-offset: -.0625rem;    position: relative;    display: inline-flex;    flex-shrink: 0;    align-items: center;    gap: .375rem;    min-height: var(--chip-height);    margin: 0;    padding: 0 var(--chip-padding-x);    border: 0;    border-radius: 999px;    corner-shape: round;    background: var(--color-surface-chip);    color: var(--color-text-strong);    box-shadow: inset 0 0 0 .5px var(--color-line-contour);    font: var(--font-weight-control) var(--chip-font-size)/1 var(--font-family-sans);    font-feature-settings: inherit;    white-space: nowrap;    vertical-align: middle;    -webkit-tap-highlight-color: transparent;    &.chip-sm {      --chip-height: 1.5rem;      --chip-padding-x: .5rem;      --chip-font-size: .71875rem;      --chip-inset: .1875rem;      --chip-remove-size: 1rem;      --icon-size: .75rem;      gap: .3125rem;    }    &.chip-lg {      --chip-height: 2rem;      --chip-padding-x: .75rem;      --chip-font-size: .84375rem;      --chip-remove-size: 1.5rem;      --icon-size: 1rem;      gap: .4375rem;    }    /* A value of a category: its tinted surface, its text and its line. */    &.chip-category {      --chip-dot: var(--category-mark, var(--color-text-muted));      &:not(:has(.chip-input)) {        background: var(--category-surface, var(--color-surface-chip));        color: var(--category-text, var(--color-text-strong));        box-shadow: inset 0 0 0 .5px var(--category-line, var(--color-line-contour));      }    }    /* Long words stop at the container's edge and end in an ellipsis. */    &:has(.chip-label) {      max-width: 100%;    }    /* A picture at the start stands as far from the end as from the top and bottom, so the curves are concentric. */    &:has(.chip-media:first-child) {      padding-inline-start: var(--chip-inset);    }    /* A count at the end, likewise: it is 2px shorter than two insets leave, so it stands 1px further in. */    &:has(.chip-count:last-child) {      padding-inline-end: calc(var(--chip-inset) + .0625rem);    }    /* A chip that holds a .chip-input is a control: a small raised sheet that lifts under the pointer. */    &:has(.chip-input) {      --chip-lift: var(--lift);      @apply --surface-sheet;      box-shadow: var(--shadow-raised);      user-select: none;      -webkit-user-select: none;      cursor: pointer;      touch-action: manipulation;      transition-property: box-shadow, translate, color;      transition-duration: var(--duration-quick);      transition-timing-function: var(--easing-glide);      /*       * A chosen filter is kept out of forced colors; the depth of hover and press, more specific than the       * system colors below, would show through there, so it is drawn only where colors are the theme's.       */      @media (hover: hover) and (forced-colors: none) {        &:hover:not(:has(.chip-input:disabled)) {          translate: 0 calc(-1 * var(--chip-lift));          box-shadow: var(--shadow-raised-hover);        }      }      /* Pressed: a filter sinks into the well, as a button does; a chosen one into the ink's own pressed face. */      &:active:not(:has(.chip-input:disabled)) {        translate: 0 var(--chip-lift);        transition-duration: var(--duration-press);        @media (forced-colors: none) {          background: var(--color-surface-inset);          box-shadow: var(--shadow-pressed);          &:has(.chip-input:checked) {            @apply --control-ink-pressed;          }        }      }    }    /* Chosen: ink, with the same line of light a checked checkbox has. */    &:has(.chip-input:checked) {      background: var(--color-surface-inverse);      color: var(--color-text-inverse);      box-shadow:        inset 0 .5px 0 var(--color-ink-highlight),        0 0 0 .5px var(--color-ink-edge),        0 1px 2px -1px var(--color-shade-1), 0 2px 4px -2px var(--color-shade-2);      @media (hover: hover) and (forced-colors: none) {        &:hover:not(:has(.chip-input:disabled)) {          box-shadow:            inset 0 .5px 0 var(--color-ink-highlight),            0 0 0 .5px var(--color-ink-edge),            0 1px 2px -1px var(--color-shade-1), 0 3px 6px -3px var(--color-shade-2), 0 6px 12px -6px var(--color-shade-3);        }      }    }    &:has(.chip-input:focus-visible) {      @apply --focus-ring;    }    /*     * The keys are on a value's remove button: the whole value wears the ring, since Backspace or Delete there     * removes all of it, and the cross takes the pressed tone that says what the key will do.     */    &:has(.chip-remove:focus-visible) {      @apply --focus-ring;    }    &:has(.chip-input:disabled) {      background: var(--color-surface-inset);      color: var(--color-text-disabled);      box-shadow: var(--shadow-flat);      cursor: not-allowed;    }    /*     * Chosen and disabled: the fill stays, in the disabled ink, so a choice that cannot be changed still reads as     * made, as a scale's chosen cell and a checked checkbox do.     */    &:has(.chip-input:checked:disabled) {      background: var(--color-text-disabled);      color: var(--color-surface-raised);      box-shadow: none;    }    /* A remove button stands as far from the pill's end as from its top and bottom, so the two circles are concentric. */    &:has(.chip-remove) {      padding-inline-end: calc((var(--chip-height) - var(--chip-remove-size)) / 2);    }    /* On touch a filter's target reaches 44px around it; the pill keeps its height and its half circles. */    @media (pointer: coarse) {      &:has(.chip-input)::after {        @apply --touch-target;      }    }    @media (prefers-reduced-motion: reduce) {      &:has(.chip-input) {        --chip-lift: 0px;      }    }    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;      &:has(.chip-input:checked) {        background: Highlight;        color: HighlightText;        box-shadow: none;        forced-color-adjust: none;      }      &:has(.chip-input:disabled) {        outline-color: GrayText;        color: GrayText;      }      /* Chosen and disabled: the fill takes the disabled system color, as a checkbox's does. */      &:has(.chip-input:checked:disabled) {        background: GrayText;        color: Canvas;      }      /* A chosen filter is kept out of forced colors, so its ring is given the system's color here. */      &:has(.chip-input:focus-visible, .chip-remove:focus-visible) {        outline: 2px solid Highlight;        outline-offset: 2px;      }    }  }  /* The checkbox or radio inside a chip covers it invisibly: the label is the target, the input keeps the state. */  .chip-input {    position: absolute;    inset: 0;    width: 100%;    height: 100%;    margin: 0;    padding: 0;    border: 0;    border-radius: inherit;    corner-shape: inherit;    opacity: 0;    appearance: none;    cursor: inherit;  }  /* The words of a chip: they shrink first and end in an ellipsis. */  .chip-label {    min-width: 0;    overflow: hidden;    /* A line as tall as the letters would clip their descenders; the chip centers the taller line, so nothing moves. */    line-height: 1.25;    text-overflow: ellipsis;  }  /*   * A picture at the start of a chip: an avatar, a flag or a logo, the chip's height less two insets, round.   * Put an avatar or an icon inside; this part sizes them.   */  .chip-media {    --chip-media-size: calc(var(--chip-height) - 2 * var(--chip-inset));    --icon-size: calc(var(--chip-media-size) - .25rem);    display: inline-grid;    flex: none;    place-items: center;    width: var(--chip-media-size);    height: var(--chip-media-size);    border-radius: 999px;    corner-shape: round;    overflow: hidden;    .avatar {      --avatar-size: var(--chip-media-size);    }  }  /*   * A dot that marks the chip's category, in its mark color, or muted ink without one. A hairline of the chip's own   * text keeps it found on any face, an ink one included.   */  .chip-dot {    flex: none;    width: .5rem;    height: .5rem;    border-radius: 999px;    corner-shape: round;    background: var(--chip-dot, var(--color-text-muted));    box-shadow: inset 0 0 0 .5px color-mix(in oklab, currentColor 30%, transparent);    @media (forced-colors: active) {      background: CanvasText;      forced-color-adjust: none;    }  }  /*   * A count inside a chip: put it on a badge, which keeps its material, and this part fits it to the chip, as a   * pill concentric with the chip's end. On a chosen filter it takes a tone of the ink.   */  .chip .chip-count {    --badge-height: calc(var(--chip-height) - 2 * var(--chip-inset) - .125rem);    --badge-padding-x: .375rem;    --badge-font-size: .6875rem;    --badge-radius: 999px;    corner-shape: round;  }  .chip:has(.chip-input:checked) .chip-count {    background: color-mix(in oklab, currentColor 16%, transparent);    color: inherit;    box-shadow: none;  }  /* Removes the value; give it an accessible name that includes the value. */  .chip-remove {    position: relative;    display: inline-grid;    flex: none;    place-items: center;    width: var(--chip-remove-size);    height: var(--chip-remove-size);    margin: 0;    padding: 0;    border: 0;    border-radius: 999px;    corner-shape: round;    background: transparent;    color: var(--color-text-muted);    appearance: none;    -webkit-tap-highlight-color: transparent;    cursor: pointer;    touch-action: manipulation;    /* The glyph is the button's icon. It takes no pointer of its own, so a press is the button's. */    .icon {      pointer-events: none;      width: calc(var(--chip-remove-size) * .6);      margin: 0;      height: calc(var(--chip-remove-size) * .6);    }    /*     * The target reaches past the glyph without moving it: 28px, and on touch 44px tall, reaching back over the     * words but no further than the pill's own end, so it never lands on the next chip.     */    &::after {      content: '';      position: absolute;      inset: -.25rem;      @media (pointer: coarse) {        inset-block: calc((2.75rem - var(--chip-remove-size)) / -2);        inset-inline: calc((2.75rem - var(--chip-remove-size)) / -2) calc((var(--chip-height) - var(--chip-remove-size)) / -2);      }    }    @media (hover: hover) {      &:hover:not(:disabled) {        background: var(--color-line-contour);        color: var(--color-text-strong);      }    }    /* Pressed: a firmer tone than the pointer's, so a tap is answered where there is no pointer. */    &:active:not(:disabled) {      background: var(--color-line-strong);      color: var(--color-text-strong);    }    &:focus-visible {      outline: none;      background: var(--color-line-strong);      color: var(--color-text-strong);    }    /* A value that cannot be removed: the cross in disabled ink, answering neither pointer nor press. */    &:disabled {      color: var(--color-text-disabled);      cursor: not-allowed;    }    @media (forced-colors: active) {      .icon {        color: ButtonText;      }      &:disabled .icon {        color: GrayText;      }      &:focus-visible {        outline: 2px solid Highlight;        outline-offset: 0;      }    }  }}