ナビゲーション

v2.1.0
フィードバック

シマー

光が流れるテキストで処理中の状態を伝えます。

このページの内容

シマーは「思考中」「14件のファイルを検索中」「デプロイ中」など、進行中の処理を1行で伝えます。文字は通常、周囲の文字色の濃さを半分強に抑えて表示され、元の濃さの帯が文字の上を通過します。帯が通る部分だけが明るくなり、色相は変わりません。テキストを含む要素にshimmerを指定します。

シマー

<p class="shimmer text-sm" role="status">Thinking…</p><p class="shimmer text-sm" role="status">Searching 14 files for “corner-shape”</p>
<>  <p className="shimmer text-sm" role="status">Thinking…</p>  <p className="shimmer text-sm" role="status">Searching 14 files for “corner-shape”</p></>
<p class="shimmer text-sm" role="status">Thinking…</p><p class="shimmer text-sm" role="status">Searching 14 files for “corner-shape”</p>
<template>  <p class="shimmer text-sm" role="status">Thinking…</p>  <p class="shimmer text-sm" role="status">Searching 14 files for “corner-shape”</p></template>

#状態を伝えるテキスト

スケルトンは、形はわかっていても、実際に表示する文言がまだわからないコンテンツの代わりに表示します。スピナーは、処理中であることだけを示します。シマーは、どのような処理が進んでいるかをテキストで具体的に伝えられるときに使います。そのテキスト自体が状態を示します。

光の効果は、文字の形に切り抜いた背景で表現します。文字はテキストのままなので、選択、コピー、翻訳、読み上げが可能です。要素の幅はテキストに合わせて縮まり、光は横の余白を通らず文字の上だけを流れます。

#ほかの要素との組み合わせ

クラスでは文字サイズやウェイトを指定しないため、表示する場所の書式を引き継ぎます。会話で応答を待っている箇所、実行中のステップ、読み込み中のページタイトルなどに使えます。

会話とリストでの使用例

<div class="flex flex-col">  <div class="message message-sent">    <div class="message-bubble">What changed in the last release?</div>  </div>  <div class="message">    <div class="message-bubble">      <span class="shimmer" role="status">Reading the changelog…</span>    </div>  </div></div><ol class="steps steps-vertical">  <li class="steps-item">    <div class="steps-body">      <p class="steps-title">Install dependencies</p>    </div>  </li>  <li class="steps-item" aria-current="step">    <div class="steps-body">      <p class="steps-title shimmer">Building 212 pages</p>    </div>  </li>  <li class="steps-item">    <div class="steps-body">      <p class="steps-title">Deploy</p>    </div>  </li></ol>
<>  <div className="flex flex-col">    <div className="message message-sent">      <div className="message-bubble">What changed in the last release?</div>    </div>    <div className="message">      <div className="message-bubble">        <span className="shimmer" role="status">Reading the changelog…</span>      </div>    </div>  </div>  <ol className="steps steps-vertical">    <li className="steps-item">      <div className="steps-body">        <p className="steps-title">Install dependencies</p>      </div>    </li>    <li className="steps-item" aria-current="step">      <div className="steps-body">        <p className="steps-title shimmer">Building 212 pages</p>      </div>    </li>    <li className="steps-item">      <div className="steps-body">        <p className="steps-title">Deploy</p>      </div>    </li>  </ol></>
<div class="flex flex-col">  <div class="message message-sent">    <div class="message-bubble">What changed in the last release?</div>  </div>  <div class="message">    <div class="message-bubble">      <span class="shimmer" role="status">Reading the changelog…</span>    </div>  </div></div><ol class="steps steps-vertical">  <li class="steps-item">    <div class="steps-body">      <p class="steps-title">Install dependencies</p>    </div>  </li>  <li class="steps-item" aria-current="step">    <div class="steps-body">      <p class="steps-title shimmer">Building 212 pages</p>    </div>  </li>  <li class="steps-item">    <div class="steps-body">      <p class="steps-title">Deploy</p>    </div>  </li></ol>
<template>  <div class="flex flex-col">    <div class="message message-sent">      <div class="message-bubble">What changed in the last release?</div>    </div>    <div class="message">      <div class="message-bubble">        <span class="shimmer" role="status">Reading the changelog…</span>      </div>    </div>  </div>  <ol class="steps steps-vertical">    <li class="steps-item">      <div class="steps-body">        <p class="steps-title">Install dependencies</p>      </div>    </li>    <li class="steps-item" aria-current="step">      <div class="steps-body">        <p class="steps-title shimmer">Building 212 pages</p>      </div>    </li>    <li class="steps-item">      <div class="steps-body">        <p class="steps-title">Deploy</p>      </div>    </li>  </ol></template>

#表示の調整

--shimmer-durationは光が1回通過する時間で、既定は2秒です。長い文では3秒に延ばせます。--shimmer-colorは通常時の文字色、--shimmer-lightは帯の色です。どちらも現在の文字色をもとに混色するので、ページ上、カード内、送信済みメッセージ内のいずれでも読みやすく表示されます。

利用者が動きを抑える設定を有効にしている場合(prefers-reduced-motion: reduce)、帯が消え、テキストは控えめな色で静止します。処理内容は引き続きテキストで伝わります。

#アクセシビリティ

  • 利用者がページを開いている間にテキストが現れたり変わったりする場合は、読み上げられるようにrole="status"を指定します。ステータス領域は、処理ごとに1つで十分です。
  • 処理が完了したら、シマーを結果に置き換えます。表示済みのコンテンツの横でシマーを動かし続けないでください。
  • 光の効果は装飾です。状態を伝える情報はすべてテキストに含まれています。

#クラス

クラス説明
shimmer控えめな色で表示したテキストの上を光の帯が通過します。テキストを含む要素に適用します。

#カスタムプロパティ

プロパティ既定値説明
--shimmer-duration2s1回の通過にかかる時間
--shimmer-colorcolor-mix(in oklab, currentColor 56%, transparent)通常時のテキスト色
--shimmer-lightcurrentColor帯の前景色

#ソース

@master/ui/components/shimmer.css
/* * Shimmer: a line of words that says work is under way, with a band of light passing over the letters. * The words rest at a little over half the ink of the text around them and the band is that ink in full, so * the line brightens where the light is, never changes hue and reads on any surface it is put on. It is drawn * as a background clipped to the text, which leaves the words selectable and real. * With reduced motion the line rests in its quieter ink, --shimmer-color, without the band; in forced colors * it is plain text. */@layer components.ui {  .shimmer {    --shimmer-color: color-mix(in oklab, currentColor 56%, transparent);    --shimmer-light: currentColor;    --shimmer-duration: 2s;    /* The box is as wide as the words, so the light crosses the words and not the room beside them. */    width: fit-content;    max-width: 100%;    background:      linear-gradient(100deg, transparent 38%, var(--shimmer-light) 50%, transparent 62%) 150% 0 / 300% 100% no-repeat,      linear-gradient(var(--shimmer-color), var(--shimmer-color));    /* The prefixed clip first: an engine that knows only it would otherwise clear the fill and lose the words. */    -webkit-background-clip: text;    background-clip: text;    /* The fill is cleared, not the color: the ink above is still the color of the text around the line. */    -webkit-text-fill-color: transparent;    /* Linear: the light crosses at one speed and the loop has no seam to rest at. */    animation: shimmer-sweep var(--shimmer-duration) linear infinite;    /* The light crosses the words the way they are read: from the right where they run from the right. */    &:dir(rtl) {      animation-direction: reverse;    }    @media (prefers-reduced-motion: reduce) {      background: none;      -webkit-text-fill-color: var(--shimmer-color);      animation: none;    }    @media (forced-colors: active) {      background: none;      -webkit-text-fill-color: currentColor;      animation: none;    }  }}@keyframes shimmer-sweep {  to {    background-position: -50% 0, 0 0;  }}