ナビゲーション

v2.1.0
オーバーレイ

コーチマーク

操作ガイドの1ステップとして、説明対象のコントロールを指し示します。

このページの内容

コーチマークは操作ガイドの1ステップです。インク色の小さなカードがコントロールを指し、その機能を説明します。ポップオーバーなので、ブラウザーがトップレイヤーに表示し、フォーカスを内部に移します。CSSアンカー配置で、開くきっかけとなった要素のそばに配置し、矢印でその要素を指します。ビーコンは、時折リングが広がるインク色の点で、ページ上の対象を示すとともに、コーチマークを開くボタンとして機能します。ツアーでは、tourビヘイビアを使って複数のコーチマークを順に開きます。

コーチマーク

<div class="toolbar" role="toolbar" aria-label="Deployments">  <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Search">    <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">      <circle cx="7" cy="7" r="4.5" /><path d="M10.182 10.182L14 14" />    </svg>  </button>  <span class="relative inline-flex">    <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Filter">      <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>    </button>    <button type="button" class="coachmark-beacon absolute top(-3) right(-3)" popovertarget="tip-filter" aria-label="What is new in Filter"></button>    <div id="tip-filter" popover class="coachmark coachmark-top" role="dialog" aria-labelledby="tip-filter-title">      <p class="coachmark-count">New</p>      <h2 class="coachmark-title" id="tip-filter-title">Filter by author</h2>      <p class="coachmark-text">        Narrow the deployments to the ones you shipped, or to anyone on the team.      </p>      <div class="coachmark-actions">        <button type="button" class="btn btn-sm" popovertarget="tip-filter" popovertargetaction="hide" autofocus>          Got it        </button>      </div>    </div>  </span>  <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Share">    <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">      <circle cx="3.6667" cy="8" r="1.6667" /><circle cx="12" cy="3.3333" r="1.6667" /><circle cx="12" cy="12.6667" r="1.6667" /><path d="M5.12 7.1867L10.5467 4.1467" /><path d="M5.12 8.8133L10.5467 11.8533" />    </svg>  </button></div>
import SearchIcon from '@master/icons-react/native/16/soft/search'import FilterIcon from '@master/icons-react/native/16/soft/filter'import ShareIcon from '@master/icons-react/native/16/soft/share'<div className="toolbar" role="toolbar" aria-label="Deployments">  <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Search">    <SearchIcon className="icon" />  </button>  <span className="relative inline-flex">    <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Filter">      <FilterIcon className="icon" />    </button>    <button type="button" className="coachmark-beacon absolute top(-3) right(-3)" popoverTarget="tip-filter" aria-label="What is new in Filter"></button>    <div id="tip-filter" popover="" className="coachmark coachmark-top" role="dialog" aria-labelledby="tip-filter-title">      <p className="coachmark-count">New</p>      <h2 className="coachmark-title" id="tip-filter-title">Filter by author</h2>      <p className="coachmark-text">        Narrow the deployments to the ones you shipped, or to anyone on the team.      </p>      <div className="coachmark-actions">        <button type="button" className="btn btn-sm" popoverTarget="tip-filter" popoverTargetAction="hide" autoFocus>          Got it        </button>      </div>    </div>  </span>  <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Share">    <ShareIcon className="icon" />  </button></div>
<script>  import SearchIcon from '@master/icons-svelte/native/16/soft/search'  import FilterIcon from '@master/icons-svelte/native/16/soft/filter'  import ShareIcon from '@master/icons-svelte/native/16/soft/share'</script><div class="toolbar" role="toolbar" aria-label="Deployments">  <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Search">    <SearchIcon class="icon" />  </button>  <span class="relative inline-flex">    <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Filter">      <FilterIcon class="icon" />    </button>    <button type="button" class="coachmark-beacon absolute top(-3) right(-3)" popovertarget="tip-filter" aria-label="What is new in Filter"></button>    <div id="tip-filter" popover class="coachmark coachmark-top" role="dialog" aria-labelledby="tip-filter-title">      <p class="coachmark-count">New</p>      <h2 class="coachmark-title" id="tip-filter-title">Filter by author</h2>      <p class="coachmark-text">        Narrow the deployments to the ones you shipped, or to anyone on the team.      </p>      <div class="coachmark-actions">        <button type="button" class="btn btn-sm" popovertarget="tip-filter" popovertargetaction="hide" autofocus>          Got it        </button>      </div>    </div>  </span>  <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Share">    <ShareIcon class="icon" />  </button></div>
<script setup>import SearchIcon from '@master/icons-vue/native/16/soft/search'import FilterIcon from '@master/icons-vue/native/16/soft/filter'import ShareIcon from '@master/icons-vue/native/16/soft/share'</script><template>  <div class="toolbar" role="toolbar" aria-label="Deployments">    <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Search">      <SearchIcon class="icon" />    </button>    <span class="relative inline-flex">      <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Filter">        <FilterIcon class="icon" />      </button>      <button type="button" class="coachmark-beacon absolute top(-3) right(-3)" popovertarget="tip-filter" aria-label="What is new in Filter"></button>      <div id="tip-filter" popover class="coachmark coachmark-top" role="dialog" aria-labelledby="tip-filter-title">        <p class="coachmark-count">New</p>        <h2 class="coachmark-title" id="tip-filter-title">Filter by author</h2>        <p class="coachmark-text">          Narrow the deployments to the ones you shipped, or to anyone on the team.        </p>        <div class="coachmark-actions">          <button type="button" class="btn btn-sm" popovertarget="tip-filter" popovertargetaction="hide" autofocus>            Got it          </button>        </div>      </div>    </span>    <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Share">      <ShareIcon class="icon" />    </button>  </div></template>
フィルターボタン上の点を押します。

カードは反転シートと同じ反転色の面を平らに表示します。moonstoneの背景にはインク色、obsidianの背景にはパール色を前景に使うため、通常のポップオーバーや背後のページと見分けやすくなります。矢印は継ぎ目なくカードにつながります。既定のボタンはアクションとして目立ち、控えめなボタンはカード上の文字色を使い、ホバー時はその色を淡く背景に重ねます。

#構成

タイトル以外の各部は省略できます。

クラス内容
coachmark-count「全4ステップ中の2」のような進行状況や「新機能」などの短い語を、控えめな文字色で表示
coachmark-titleステップの見出し。IDを付け、コーチマークのラベルとして参照
coachmark-textコントロールの機能を説明する1〜2文
coachmark-actions下部に並ぶ小さなボタン。複数ある場合は「スキップ」など最初のボタンを列の始端に、「戻る」「次へ」など残りを終端に寄せて配置

アクションはカードの端から12px内側に配置します。小さなボタンとカードの角が同心円状になるように、カードの角丸半径はボタンの角丸半径にこの余白を足した値になります。

#配置

コーチマークは、開くきっかけとなった要素の真下に中央揃えで表示され、矢印の先端はその要素から6px離れます。下に十分な空間がなければ、上に切り替わります。coachmark-topは上側を優先します。画面下部のコントロールや、最初の例のようにコントロールの上隅にビーコンがある場合に使います。

矢印はマークアップ上でコーチマークの直前にある要素を指すため、コーチマークはビーコンか説明対象のコントロールの直後に置きます。ツアーでは、ステップの対象の上に重なるツアーのスポットライトを指します。表示中はその要素がアンカーとして指定され、矢印はその中央を追従します。カードがビューポートの端を避けてずれても対象を指し続け、カードの角丸を避け、カードの配置が反転すると反対側の辺に移ります。ツアーと同様、一度に開くコーチマークは1つです。

#ビーコン

coachmark-beaconはボタン上に表示する10pxの点で、配置先の面と同じ色の縁取りが付きます。操作領域は24px、タッチ画面では44pxです。popovertargetでコーチマークを開き、何が開くかを示すaria-labelが必要です。配置はページ側で指定します。relativeラッパー内でabsoluteユーティリティを使って対象のコントロールの上隅に置くか、同じ行で隣に並べます。

リングの動きでビーコンに注意を促します。ビーコンのホバー時やフォーカス時、コーチマークの表示中、動きを抑える設定が有効なときは、リングが静止した状態になります。読者がステップを確認したら、ビーコンを取り除きます。

#ツアー

ツアーでは、複数のコーチマークを、それぞれが説明するコントロールに合わせて順に開きます。ステップは進む順にcoachmark-tour内に置き、それぞれにpopover="manual"を指定します。これにより、説明対象のコントロールを試すなど、ページ内をクリックしてもツアーが終了しません。ステップの対象はdata-targetにセレクターで指定します。指定がなければ、マークアップ上でステップの直前にある要素を指します。ステップのボタンは、valueで役割を示します。next、back、skip、そして最後のステップではdoneを使います。

残りはtour ビヘイビアが担います。command="--start"を持ち、commandforでツアーを指定したボタンでツアーを開始します。ビヘイビアはshowPopover({ source })で各ステップを対象に合わせて開くため、ブラウザーがカードをそこにアンカーし、CSSが配置を決めます。さらに、フォーカスをステップ内の「次へ」または「完了」に移します。ツアー内にcoachmark-spotlightがある場合は、まずそれを対象の上に開きます。ステップがマークアップ上のどこにあっても、ステップの矢印はこのスポットライトを指します。

ツアー

<div class="coachmark-tour flex items-center gap-sm" id="deploys-tour">  <button type="button" class="btn btn-sm" commandfor="deploys-tour" command="--start">    Take the tour  </button>  <div class="toolbar" role="toolbar" aria-label="Deployments">    <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-search" aria-label="Search">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <circle cx="7" cy="7" r="4.5" /><path d="M10.182 10.182L14 14" />      </svg>    </button>    <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-filter" aria-label="Filter">      <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>    </button>    <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-share" aria-label="Share">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <circle cx="3.6667" cy="8" r="1.6667" /><circle cx="12" cy="3.3333" r="1.6667" /><circle cx="12" cy="12.6667" r="1.6667" /><path d="M5.12 7.1867L10.5467 4.1467" /><path d="M5.12 8.8133L10.5467 11.8533" />      </svg>    </button>  </div>  <div class="coachmark-spotlight" popover="manual"></div>  <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-search-title" data-target="#deploys-search">    <p class="coachmark-count">1 of 3</p>    <h2 class="coachmark-title" id="deploys-search-title">Search every deployment</h2>    <p class="coachmark-text">Find one by its branch, its commit or the person who shipped it.</p>    <div class="coachmark-actions">      <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button>      <button type="button" class="btn btn-sm" value="next">Next</button>    </div>  </div>  <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-filter-title" data-target="#deploys-filter">    <p class="coachmark-count">2 of 3</p>    <h2 class="coachmark-title" id="deploys-filter-title">Filter the list</h2>    <p class="coachmark-text">Keep only the deployments of one branch, one author or one status.</p>    <div class="coachmark-actions">      <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button>      <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button>      <button type="button" class="btn btn-sm" value="next">Next</button>    </div>  </div>  <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-share-title" data-target="#deploys-share">    <p class="coachmark-count">3 of 3</p>    <h2 class="coachmark-title" id="deploys-share-title">Share a deployment</h2>    <p class="coachmark-text">Copy a link to it, open for anyone on the team.</p>    <div class="coachmark-actions">      <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button>      <button type="button" class="btn btn-sm" value="done">Done</button>    </div>  </div></div><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import SearchIcon from '@master/icons-react/native/16/soft/search'import FilterIcon from '@master/icons-react/native/16/soft/filter'import ShareIcon from '@master/icons-react/native/16/soft/share'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => attach(root.current!), [])  return (    <div ref={root} className="coachmark-tour flex items-center gap-sm" id="deploys-tour">      <button type="button" className="btn btn-sm" {...{ commandfor: 'deploys-tour', command: '--start' }}>        Take the tour      </button>      <div className="toolbar" role="toolbar" aria-label="Deployments">        <button type="button" className="btn btn-quiet btn-sm btn-square" id="deploys-search" aria-label="Search">          <SearchIcon className="icon" />        </button>        <button type="button" className="btn btn-quiet btn-sm btn-square" id="deploys-filter" aria-label="Filter">          <FilterIcon className="icon" />        </button>        <button type="button" className="btn btn-quiet btn-sm btn-square" id="deploys-share" aria-label="Share">          <ShareIcon className="icon" />        </button>      </div>      <div className="coachmark-spotlight" popover="manual"></div>      <div className="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-search-title" data-target="#deploys-search">        <p className="coachmark-count">1 of 3</p>        <h2 className="coachmark-title" id="deploys-search-title">Search every deployment</h2>        <p className="coachmark-text">          Find one by its branch, its commit or the person who shipped it.        </p>        <div className="coachmark-actions">          <button type="button" className="btn btn-sm btn-quiet" value="skip">Skip</button>          <button type="button" className="btn btn-sm" value="next">Next</button>        </div>      </div>      <div className="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-filter-title" data-target="#deploys-filter">        <p className="coachmark-count">2 of 3</p>        <h2 className="coachmark-title" id="deploys-filter-title">Filter the list</h2>        <p className="coachmark-text">          Keep only the deployments of one branch, one author or one status.        </p>        <div className="coachmark-actions">          <button type="button" className="btn btn-sm btn-quiet" value="skip">Skip</button>          <button type="button" className="btn btn-sm btn-quiet" value="back">Back</button>          <button type="button" className="btn btn-sm" value="next">Next</button>        </div>      </div>      <div className="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-share-title" data-target="#deploys-share">        <p className="coachmark-count">3 of 3</p>        <h2 className="coachmark-title" id="deploys-share-title">Share a deployment</h2>        <p className="coachmark-text">Copy a link to it, open for anyone on the team.</p>        <div className="coachmark-actions">          <button type="button" className="btn btn-sm btn-quiet" value="back">Back</button>          <button type="button" className="btn btn-sm" value="done">Done</button>        </div>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'  import SearchIcon from '@master/icons-svelte/native/16/soft/search'  import FilterIcon from '@master/icons-svelte/native/16/soft/filter'  import ShareIcon from '@master/icons-svelte/native/16/soft/share'</script><div class="coachmark-tour flex items-center gap-sm" id="deploys-tour" {@attach attach}>  <button type="button" class="btn btn-sm" commandfor="deploys-tour" command="--start">    Take the tour  </button>  <div class="toolbar" role="toolbar" aria-label="Deployments">    <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-search" aria-label="Search">      <SearchIcon class="icon" />    </button>    <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-filter" aria-label="Filter">      <FilterIcon class="icon" />    </button>    <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-share" aria-label="Share">      <ShareIcon class="icon" />    </button>  </div>  <div class="coachmark-spotlight" popover="manual"></div>  <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-search-title" data-target="#deploys-search">    <p class="coachmark-count">1 of 3</p>    <h2 class="coachmark-title" id="deploys-search-title">Search every deployment</h2>    <p class="coachmark-text">Find one by its branch, its commit or the person who shipped it.</p>    <div class="coachmark-actions">      <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button>      <button type="button" class="btn btn-sm" value="next">Next</button>    </div>  </div>  <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-filter-title" data-target="#deploys-filter">    <p class="coachmark-count">2 of 3</p>    <h2 class="coachmark-title" id="deploys-filter-title">Filter the list</h2>    <p class="coachmark-text">Keep only the deployments of one branch, one author or one status.</p>    <div class="coachmark-actions">      <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button>      <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button>      <button type="button" class="btn btn-sm" value="next">Next</button>    </div>  </div>  <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-share-title" data-target="#deploys-share">    <p class="coachmark-count">3 of 3</p>    <h2 class="coachmark-title" id="deploys-share-title">Share a deployment</h2>    <p class="coachmark-text">Copy a link to it, open for anyone on the team.</p>    <div class="coachmark-actions">      <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button>      <button type="button" class="btn btn-sm" value="done">Done</button>    </div>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import SearchIcon from '@master/icons-vue/native/16/soft/search'import FilterIcon from '@master/icons-vue/native/16/soft/filter'import ShareIcon from '@master/icons-vue/native/16/soft/share'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <div ref="root" class="coachmark-tour flex items-center gap-sm" id="deploys-tour">    <button type="button" class="btn btn-sm" commandfor="deploys-tour" command="--start">      Take the tour    </button>    <div class="toolbar" role="toolbar" aria-label="Deployments">      <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-search" aria-label="Search">        <SearchIcon class="icon" />      </button>      <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-filter" aria-label="Filter">        <FilterIcon class="icon" />      </button>      <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-share" aria-label="Share">        <ShareIcon class="icon" />      </button>    </div>    <div class="coachmark-spotlight" popover="manual"></div>    <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-search-title" data-target="#deploys-search">      <p class="coachmark-count">1 of 3</p>      <h2 class="coachmark-title" id="deploys-search-title">Search every deployment</h2>      <p class="coachmark-text">Find one by its branch, its commit or the person who shipped it.</p>      <div class="coachmark-actions">        <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button>        <button type="button" class="btn btn-sm" value="next">Next</button>      </div>    </div>    <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-filter-title" data-target="#deploys-filter">      <p class="coachmark-count">2 of 3</p>      <h2 class="coachmark-title" id="deploys-filter-title">Filter the list</h2>      <p class="coachmark-text">        Keep only the deployments of one branch, one author or one status.      </p>      <div class="coachmark-actions">        <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button>        <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button>        <button type="button" class="btn btn-sm" value="next">Next</button>      </div>    </div>    <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-share-title" data-target="#deploys-share">      <p class="coachmark-count">3 of 3</p>      <h2 class="coachmark-title" id="deploys-share-title">Share a deployment</h2>      <p class="coachmark-text">Copy a link to it, open for anyone on the team.</p>      <div class="coachmark-actions">        <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button>        <button type="button" class="btn btn-sm" value="done">Done</button>      </div>    </div>  </div></template>
ツアーを開始し、「次へ」「戻る」とEscキーを試します。

ツアーには、この例のように説明対象の領域を含めることも、ステップとスポットライトだけを含めることもできます。ステップは文書内のどこにある対象でも見つけられます。閉じている間、ステップとスポットライトは場所を取らないため、ツアーの要素自体をそれが置かれた行として使えます。

ビーコンから開く単独のコーチマークには、これらはどれも必要ありません。popover="auto"なので、スクリプトなしで、外側のクリックやEscでブラウザーが閉じ、フォーカスをビーコンに戻します。

#待機するステップ

ステップは、読者の操作や対象の出現を待つことができます。

  • 操作。 data-advanceを持つステップは、ツアーを先に進める対象のイベント(clickなど)を指定します。このステップには「次へ」を置きません。読者自身に操作を促し、ページが応答した時点でツアーが進みます。「スキップ」やEscでは引き続き終了できます。
  • 後から現れる対象。ステップの対象がページ内にない場合や描画されていない場合、ステップは対象を待ち、現れるとすぐに開きます。ボタンで表示されるフィールドや、読み込み中の行などが該当します。3秒後(またはビヘイビアに渡したwaitの時間が経過した後)も現れない対象のステップは飛ばされ、最後のステップを過ぎるとツアーは完了します。何も指していないカードでツアーが止まることはありません。表示できない可能性のあるステップには、それがなくても読者が見つけられる内容だけを含めてください。

待機するステップ

<div class="coachmark-tour flex flex-col items-center gap-md" id="projects-tour">  <div class="flex items-center gap-sm">    <button type="button" class="btn btn-sm" commandfor="projects-tour" command="--start">      Take the tour    </button>    <button type="button" class="btn btn-sm btn-primary" id="projects-new">New project</button>  </div>  <input class="input w(240)" id="projects-name" placeholder="Project name" aria-label="Project name" hidden>  <div class="coachmark-spotlight" popover="manual"></div>  <div class="coachmark" popover="manual" role="dialog" aria-labelledby="projects-new-title" data-target="#projects-new" data-advance="click">    <p class="coachmark-count">1 of 2</p>    <h2 class="coachmark-title" id="projects-new-title">Start a project</h2>    <p class="coachmark-text">Press New project. The tour goes on once its form is open.</p>    <div class="coachmark-actions">      <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button>    </div>  </div>  <div class="coachmark" popover="manual" role="dialog" aria-labelledby="projects-name-title" data-target="#projects-name">    <p class="coachmark-count">2 of 2</p>    <h2 class="coachmark-title" id="projects-name-title">Name it</h2>    <p class="coachmark-text">      Use the name your team already calls it by. You can change it later.    </p>    <div class="coachmark-actions">      <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button>      <button type="button" class="btn btn-sm" value="done">Done</button>    </div>  </div></div><script>document.getElementById('projects-new').addEventListener('click', function () {  setTimeout(function () { document.getElementById('projects-name').hidden = false }, 400)})</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
ツアーを開始し、「New project」を押します。次のステップはフィールドが現れるのを待ちます。

#スポットライト

coachmark-spotlight-dimは、ダイアログと同じ背景幕でステップの対象の周囲を暗くし、対象とその周囲4pxを明るいまま残します。明るい部分の角は、コントロールの角丸にこの余白を足した値です。背景幕は画面全体に広がる影のリングで、アンカー配置で対象の上に重なるスポットライトが描画します。そのため、ページをスクロールしても対象に追従します。ツアーの開始時にフェードインし、終了時にフェードアウトします。ステップ間では、明るい部分が即座に移動します。

背景幕は見た目を塗るだけで、操作を遮る壁ではありません。下にあるページは引き続きポインターやキー操作に反応するため、読者はステップが指すものを試せますし、ツアーがほかの操作の妨げになることもありません。画面の最初のツアーなど、視線を導く必要がある場合に使い、新しいコントロール1つについてのヒントには使わないでください。

スポットライト

<div class="coachmark-tour flex flex-col items-center gap-md" id="release-tour">  <button type="button" class="btn btn-sm" commandfor="release-tour" command="--start">    Take the tour  </button>  <div class="card flex-row items-center gap-md p-md w(300)">    <div class="flex flex-col grow(1)">      <span class="text-sm fg-text-strong">atlas.dev</span>      <span class="text-xs fg-text-muted" id="release-status">Ready, 2 minutes ago</span>    </div>    <button type="button" class="btn btn-sm btn-primary" id="release-deploy">Deploy</button>  </div>  <div class="coachmark-spotlight coachmark-spotlight-dim" popover="manual"></div>  <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-status-title" data-target="#release-status">    <p class="coachmark-count">1 of 2</p>    <h2 class="coachmark-title" id="release-status-title">See where it stands</h2>    <p class="coachmark-text">Each project says whether its last build is ready and when it ran.</p>    <div class="coachmark-actions">      <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button>      <button type="button" class="btn btn-sm" value="next">Next</button>    </div>  </div>  <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-deploy-title" data-target="#release-deploy">    <p class="coachmark-count">2 of 2</p>    <h2 class="coachmark-title" id="release-deploy-title">Ship it</h2>    <p class="coachmark-text">Deploy sends the ready build to production.</p>    <div class="coachmark-actions">      <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button>      <button type="button" class="btn btn-sm" value="done">Done</button>    </div>  </div></div><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => attach(root.current!), [])  return (    <div ref={root} className="coachmark-tour flex flex-col items-center gap-md" id="release-tour">      <button type="button" className="btn btn-sm" {...{ commandfor: 'release-tour', command: '--start' }}>        Take the tour      </button>      <div className="card flex-row items-center gap-md p-md w(300)">        <div className="flex flex-col grow(1)">          <span className="text-sm fg-text-strong">atlas.dev</span>          <span className="text-xs fg-text-muted" id="release-status">Ready, 2 minutes ago</span>        </div>        <button type="button" className="btn btn-sm btn-primary" id="release-deploy">Deploy</button>      </div>      <div className="coachmark-spotlight coachmark-spotlight-dim" popover="manual"></div>      <div className="coachmark" popover="manual" role="dialog" aria-labelledby="release-status-title" data-target="#release-status">        <p className="coachmark-count">1 of 2</p>        <h2 className="coachmark-title" id="release-status-title">See where it stands</h2>        <p className="coachmark-text">          Each project says whether its last build is ready and when it ran.        </p>        <div className="coachmark-actions">          <button type="button" className="btn btn-sm btn-quiet" value="skip">Skip</button>          <button type="button" className="btn btn-sm" value="next">Next</button>        </div>      </div>      <div className="coachmark" popover="manual" role="dialog" aria-labelledby="release-deploy-title" data-target="#release-deploy">        <p className="coachmark-count">2 of 2</p>        <h2 className="coachmark-title" id="release-deploy-title">Ship it</h2>        <p className="coachmark-text">Deploy sends the ready build to production.</p>        <div className="coachmark-actions">          <button type="button" className="btn btn-sm btn-quiet" value="back">Back</button>          <button type="button" className="btn btn-sm" value="done">Done</button>        </div>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'</script><div class="coachmark-tour flex flex-col items-center gap-md" id="release-tour" {@attach attach}>  <button type="button" class="btn btn-sm" commandfor="release-tour" command="--start">    Take the tour  </button>  <div class="card flex-row items-center gap-md p-md w(300)">    <div class="flex flex-col grow(1)">      <span class="text-sm fg-text-strong">atlas.dev</span>      <span class="text-xs fg-text-muted" id="release-status">Ready, 2 minutes ago</span>    </div>    <button type="button" class="btn btn-sm btn-primary" id="release-deploy">Deploy</button>  </div>  <div class="coachmark-spotlight coachmark-spotlight-dim" popover="manual"></div>  <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-status-title" data-target="#release-status">    <p class="coachmark-count">1 of 2</p>    <h2 class="coachmark-title" id="release-status-title">See where it stands</h2>    <p class="coachmark-text">Each project says whether its last build is ready and when it ran.</p>    <div class="coachmark-actions">      <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button>      <button type="button" class="btn btn-sm" value="next">Next</button>    </div>  </div>  <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-deploy-title" data-target="#release-deploy">    <p class="coachmark-count">2 of 2</p>    <h2 class="coachmark-title" id="release-deploy-title">Ship it</h2>    <p class="coachmark-text">Deploy sends the ready build to production.</p>    <div class="coachmark-actions">      <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button>      <button type="button" class="btn btn-sm" value="done">Done</button>    </div>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <div ref="root" class="coachmark-tour flex flex-col items-center gap-md" id="release-tour">    <button type="button" class="btn btn-sm" commandfor="release-tour" command="--start">      Take the tour    </button>    <div class="card flex-row items-center gap-md p-md w(300)">      <div class="flex flex-col grow(1)">        <span class="text-sm fg-text-strong">atlas.dev</span>        <span class="text-xs fg-text-muted" id="release-status">Ready, 2 minutes ago</span>      </div>      <button type="button" class="btn btn-sm btn-primary" id="release-deploy">Deploy</button>    </div>    <div class="coachmark-spotlight coachmark-spotlight-dim" popover="manual"></div>    <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-status-title" data-target="#release-status">      <p class="coachmark-count">1 of 2</p>      <h2 class="coachmark-title" id="release-status-title">See where it stands</h2>      <p class="coachmark-text">        Each project says whether its last build is ready and when it ran.      </p>      <div class="coachmark-actions">        <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button>        <button type="button" class="btn btn-sm" value="next">Next</button>      </div>    </div>    <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-deploy-title" data-target="#release-deploy">      <p class="coachmark-count">2 of 2</p>      <h2 class="coachmark-title" id="release-deploy-title">Ship it</h2>      <p class="coachmark-text">Deploy sends the ready build to production.</p>      <div class="coachmark-actions">        <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button>        <button type="button" class="btn btn-sm" value="done">Done</button>      </div>    </div>  </div></template>
ツアーを開始します。各ステップの対象の周囲が暗くなります。

強制カラーモードでは影が描画されないため、代わりにシステムのハイライト色のアウトラインで対象を示します。

#ビヘイビア

tourは、coachmark-tourクラスを持つルート要素を受け取り、ビヘイビアを解除する関数を返します。@master/ui/behaviorsのattach()は、ページ内のすべてのツアーを見つけます。

app.js
import { tour } from '@master/ui/behaviors/tour.js'const root = document.querySelector('#deploys-tour')const deploys = tour(root)deploys.value = 0 // starts the tour, as the button doesroot.addEventListener('end', (event) => {  if (event.detail.completed) localStorage.setItem('deploys-tour', 'seen')})
  • 値は、ツアーが表示しているステップの0から始まるインデックスで、ツアーが実行されていない間はnullです。値を設定するとそのステップが開き、nullを設定するとツアーが終了します。このときイベントは発行されません。
  • イベント。ツアーが別のステップに移るたびに、ルートはバブリングするchangeを発行し、detail.valueにインデックスを入れます。読者がツアーを終えると、nullを値とするchangeを発行した後にendを発行します。endのdetail.completedは、読者が最後のステップまで進んだ場合はtrue、「スキップ」、Esc、その他ステップを閉じる操作でそれより前に離れた場合はfalseです。
  • フォーカスは、各ステップが開くとその内部に移ります。移動先はautofocusを持つアクション、なければ「次へ」または「完了」、それもなければステップ自体です。ツアーが終わると、読者がその後フォーカスをページ内に移していない限り、ツアー開始時の位置にフォーカスが戻ります。
  • オプション。 target(step, index)はステップの対象を見つける関数で、ページ側で対象を管理する場合に使います。waitはステップが対象を待つ時間で、単位はミリ秒、既定は3000です。
  • 呼び出しコマンド。ブラウザーがcommandとcommandforに対応していない場合は、ビヘイビアが開始ボタンのクリックを直接受け取ります。

ビヘイビアがなければツアーは開始されません。ステップは閉じたままで、ページはそれらがなくても完全に機能します。endイベントで読者がツアーを終えたことを記録し、同じツアーを自動で再び開始しないでください。後から見つけられるボタンから開始できるようにします。

#キーボード操作

キー操作
Enter, Spaceビーコン上では、対応するコーチマークを開閉します。ツアーのステップ上では、ボタンの value の指定に従って「次へ」「戻る」「スキップ」「完了」のいずれかを実行します。コーチマークが開くと、内部で autofocus が指定されたアクションにフォーカスが移ります。そのようなアクションがないステップでは、ステップ自体がフォーカスを受け取ります。
Tabコーチマーク内のアクション間でフォーカスを移動します。コーチマークを抜けると、ビーコンの次の位置にフォーカスが移ります。ステップはフォーカスを閉じ込めないため、開いている間もページを操作できます。
Escapepopover="auto" で開いたコーチマークを閉じ、ビーコンにフォーカスを戻します。ツアーでは、ステップ内にフォーカスがある状態で押すと、スキップとしてツアーを終了し、ツアー開始時の位置にフォーカスを戻します。

#アクセシビリティ

  • コーチマークにrole="dialog"を指定し、aria-labelledbyでタイトルをラベルとして参照します。コーチマークは非モーダルなので、表示中も周囲のページを操作できます。ツアーでは、スポットライトの下にあるページも操作できます。
  • ビーコンから開くコーチマークでは、主アクションにautofocusを指定すると、カードを開いたときにフォーカスが内部に移り、キーボードのEnterで先に進めます。ツアーのステップには、ビヘイビアがフォーカスを移します。
  • どのステップからでも、「スキップ」や「完了」などのアクション、またはEscで終了できます。単独のコーチマークは、外側をクリックしても閉じられます。
  • ツアーは、ボタンなど読者の操作をきっかけに開始し、ページの読み込み時には開始しないでください。ツアーは補助であり、読者が本来の目的としている作業からフォーカスを奪うべきではありません。
  • 読者がツアーをスキップしたり、途中のステップが飛ばされたりしても、説明内容をすべてツアー以外の場所で確認できるようにします。
  • コーチマークをマークアップ上でビーコンの直後に置くと、カードの表示位置にかかわらず、Tabキーの移動順でもビーコンの次になります。

#React、Svelte、Vue

tourコンポーネントは、データの各項目からステップを1つずつ生成し、それぞれにタイトル、テキスト、進行状況、必要なアクションを書き出します。開いているステップのインデックスを外部から受け取り、変更を外部に通知します。ツアーの終了はonEndで受け取ります。ステップの対象には、セレクター、要素、ref、または対象を見つける関数を指定できます。npx master-ui add tourでプロジェクトにコピーできます。コンポーネントの構成と使い方はReact、Svelte、Vueを参照してください。

ui/tour.tsx
'use client'import { useId, type ComponentProps, type ReactNode, type RefObject } from 'react'import { tour } from '@master/ui/behaviors/tour.js'import { useBehavior } from './use-behavior'export interface TourStep {  /**   * What the step points at: a selector, an element, a ref, or a function that finds it. Until it is in the   * page the step waits for it, and passes on when it does not come.   */  target: string | Element | RefObject<Element | null> | (() => Element | null | undefined)  title: string  text?: string  /**   * An event on the target that moves the tour on, such as `click`: the step asks the reader to do it, and   * has no Next.   */  advance?: string}export interface TourProps extends Omit<ComponentProps<'div'>, 'children' | 'defaultValue' | 'ref'> {  steps: TourStep[]  /** The index of the open step, or null while the tour is not running. */  value?: number | null  defaultValue?: number | null  onValueChange?: (value: number | null) => void  /** Called when the reader ends the tour: completed, or left before the last step. */  onEnd?: (completed: boolean) => void  /** The button that starts the tour: spread what it is given on a button of your own. */  trigger?: (attributes: { commandfor: string, command: '--start' }) => ReactNode  /** Dim the page around each step's target. */  spotlight?: boolean  /** How long a step waits for its target, in milliseconds. */  wait?: number  nextLabel?: string  backLabel?: string  skipLabel?: string  doneLabel?: string  /** Where a step stands: `2 of 4` by default. */  countLabel?: (step: number, steps: number) => string}/** The element a step points at, found as the page is now. */function find(target: TourStep['target'] | undefined): Element | null {  if (!target) return null  if (typeof target === 'string') return document.querySelector(target)  if (typeof target === 'function') return target() ?? null  if ('current' in target) return target.current  return target}/** * A tour: one coachmark for each step, written from data, opened in turn against its target. The behavior * opens and closes the steps, waits for a target, moves focus and hears the keys; this component writes the * steps, finds their targets and passes the index of the open step in and out. */export function Tour({ steps, value, defaultValue, onValueChange, onEnd, trigger, spotlight = false, wait, nextLabel = 'Next', backLabel = 'Back', skipLabel = 'Skip', doneLabel = 'Done', countLabel = (step, count) => `${step} of ${count}`, className, id, ...root }: TourProps) {  const generated = useId()  const name = id ?? generated  const ref = useBehavior(tour, { wait, target: (_step: HTMLElement, index: number) => find(steps[index]?.target) }, {    value,    defaultValue,    onValueChange,    on: { end: event => onEnd?.((event as CustomEvent<{ completed: boolean }>).detail.completed) },  })  return (    <>      {trigger?.({ commandfor: name, command: '--start' })}      <div id={name} className={className ? `coachmark-tour ${className}` : 'coachmark-tour'} ref={ref} {...root}>        <div className={spotlight ? 'coachmark-spotlight coachmark-spotlight-dim' : 'coachmark-spotlight'} popover="manual" />        {steps.map((step, index) => {          const last = index === steps.length - 1          return (            <div className="coachmark" popover="manual" role="dialog" aria-labelledby={`${name}-${index}-title`} data-advance={step.advance} key={index}>              <p className="coachmark-count">{countLabel(index + 1, steps.length)}</p>              <h2 className="coachmark-title" id={`${name}-${index}-title`}>{step.title}</h2>              {step.text ? <p className="coachmark-text">{step.text}</p> : null}              <div className="coachmark-actions">                {last ? null : <button type="button" className="btn btn-sm btn-quiet" value="skip">{skipLabel}</button>}                {index > 0 ? <button type="button" className="btn btn-sm btn-quiet" value="back">{backLabel}</button> : null}                {step.advance ? null : <button type="button" className="btn btn-sm" value={last ? 'done' : 'next'}>{last ? doneLabel : nextLabel}</button>}              </div>            </div>          )        })}      </div>    </>  )}
ui/Tour.svelte
<script lang="ts" module>  import type { Snippet } from 'svelte'  import type { HTMLAttributes } from 'svelte/elements'  export interface TourStep {    /**     * What the step points at: a selector, an element, or a function that finds it. Until it is in the page     * the step waits for it, and passes on when it does not come.     */    target: string | Element | (() => Element | null | undefined)    title: string    text?: string    /**     * An event on the target that moves the tour on, such as `click`: the step asks the reader to do it, and     * has no Next.     */    advance?: string  }  export interface TourProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {    steps: TourStep[]    /** The index of the open step, or null while the tour is not running. Bind it, or leave it out. */    value?: number | null    onValueChange?: (value: number | null) => void    /** Called when the reader ends the tour: completed, or left before the last step. */    onEnd?: (completed: boolean) => void    /** The button that starts the tour: spread what it is given on a button of your own. */    trigger?: Snippet<[{ commandfor: string, command: '--start' }]>    /** Dim the page around each step's target. */    spotlight?: boolean    /** How long a step waits for its target, in milliseconds. */    wait?: number    nextLabel?: string    backLabel?: string    skipLabel?: string    doneLabel?: string    /** Where a step stands: `2 of 4` by default. */    countLabel?: (step: number, steps: number) => string  }</script><script lang="ts">  import { tour } from '@master/ui/behaviors/tour.js'  import { behavior } from './behavior.svelte.js'  let { steps, value = $bindable(), onValueChange, onEnd, trigger, spotlight = false, wait, nextLabel = 'Next', backLabel = 'Back', skipLabel = 'Skip', doneLabel = 'Done', countLabel = (step: number, count: number) => `${step} of ${count}`, class: className, id, ...root }: TourProps = $props()  const generated = $props.id()  const name = $derived(id ?? generated)  /** The element a step points at, found as the page is now. */  const find = (target: TourStep['target'] | undefined) => {    if (!target) return null    if (typeof target === 'string') return document.querySelector(target)    if (typeof target === 'function') return target() ?? null    return target  }  const attach = behavior(tour, () => ({ wait, target: (_step: HTMLElement, index: number) => find(steps[index]?.target) }), {    value: () => value,    change: (next) => {      value = next      onValueChange?.(next)    },    on: { end: event => onEnd?.((event as CustomEvent<{ completed: boolean }>).detail.completed) },  })</script><!--  @component  A tour: one coachmark for each step, written from data, opened in turn against its target. The behavior  opens and closes the steps, waits for a target, moves focus and hears the keys; this component writes the  steps, finds their targets and passes the index of the open step in and out.-->{@render trigger?.({ commandfor: name, command: '--start' })}<div id={name} class={['coachmark-tour', className]} {@attach attach} {...root}>  <div class={spotlight ? 'coachmark-spotlight coachmark-spotlight-dim' : 'coachmark-spotlight'} popover="manual"></div>  {#each steps as step, index (index)}    {@const last = index === steps.length - 1}    <div class="coachmark" popover="manual" role="dialog" aria-labelledby="{name}-{index}-title" data-advance={step.advance}>      <p class="coachmark-count">{countLabel(index + 1, steps.length)}</p>      <h2 class="coachmark-title" id="{name}-{index}-title">{step.title}</h2>      {#if step.text}<p class="coachmark-text">{step.text}</p>{/if}      <div class="coachmark-actions">        {#if !last}<button type="button" class="btn btn-sm btn-quiet" value="skip">{skipLabel}</button>{/if}        {#if index > 0}<button type="button" class="btn btn-sm btn-quiet" value="back">{backLabel}</button>{/if}        {#if !step.advance}<button type="button" class="btn btn-sm" value={last ? 'done' : 'next'}>{last ? doneLabel : nextLabel}</button>{/if}      </div>    </div>  {/each}</div>
ui/Tour.vue
<script lang="ts">export interface TourStep {  /**   * What the step points at: a selector, an element, or a function that finds it. Until it is in the page the   * step waits for it, and passes on when it does not come.   */  target: string | Element | (() => Element | null | undefined)  title: string  text?: string  /**   * An event on the target that moves the tour on, such as `click`: the step asks the reader to do it, and has   * no Next.   */  advance?: string}</script><script setup lang="ts">import { computed, useId, useTemplateRef } from 'vue'import { tour } from '@master/ui/behaviors/tour.js'import { useBehavior } from './use-behavior'defineOptions({ inheritAttrs: false })const { steps, id, spotlight = false, wait, nextLabel = 'Next', backLabel = 'Back', skipLabel = 'Skip', doneLabel = 'Done', countLabel = (step: number, count: number) => `${step} of ${count}` } = defineProps<{  steps: TourStep[]  id?: string  /** Dim the page around each step's target. */  spotlight?: boolean  /** How long a step waits for its target, in milliseconds. */  wait?: number  nextLabel?: string  backLabel?: string  skipLabel?: string  doneLabel?: string  /** Where a step stands: `2 of 4` by default. */  countLabel?: (step: number, steps: number) => string}>()/** The index of the open step, or null while the tour is not running: `v-model`. */const model = defineModel<number | null>()const emit = defineEmits<{  /** The reader ended the tour: completed, or left before the last step. */  end: [completed: boolean]}>()defineSlots<{  /** The button that starts the tour: bind what it is given on a button of your own. */  trigger?: (attributes: { commandfor: string, command: '--start' }) => unknown}>()/* * A tour: one coachmark for each step, written from data, opened in turn against its target. The behavior * opens and closes the steps, waits for a target, moves focus and hears the keys; this component writes the * steps, finds their targets and passes the index of the open step in and out. */const generated = useId()const name = computed(() => id ?? generated)const root = useTemplateRef<HTMLDivElement>('root')/** The element a step points at, found as the page is now. */const find = (target: TourStep['target'] | undefined) => {  if (!target) return null  if (typeof target === 'string') return document.querySelector(target)  if (typeof target === 'function') return target() ?? null  return target}useBehavior(root, tour, () => ({ wait, target: (_step: HTMLElement, index: number) => find(steps[index]?.target) }), model, {  end: event => emit('end', (event as CustomEvent<{ completed: boolean }>).detail.completed),})</script><template>  <slot name="trigger" v-bind="{ commandfor: name, command: '--start' as const }" />  <div :id="name" class="coachmark-tour" ref="root" v-bind="$attrs">    <div :class="spotlight ? 'coachmark-spotlight coachmark-spotlight-dim' : 'coachmark-spotlight'" popover="manual" />    <div v-for="(step, index) in steps" :key="index" class="coachmark" popover="manual" role="dialog" :aria-labelledby="`${name}-${index}-title`" :data-advance="step.advance">      <p class="coachmark-count">{{ countLabel(index + 1, steps.length) }}</p>      <h2 :id="`${name}-${index}-title`" class="coachmark-title">{{ step.title }}</h2>      <p v-if="step.text" class="coachmark-text">{{ step.text }}</p>      <div class="coachmark-actions">        <button v-if="index < steps.length - 1" type="button" class="btn btn-sm btn-quiet" value="skip">{{ skipLabel }}</button>        <button v-if="index > 0" type="button" class="btn btn-sm btn-quiet" value="back">{{ backLabel }}</button>        <button v-if="!step.advance" type="button" class="btn btn-sm" :value="index === steps.length - 1 ? 'done' : 'next'">{{ index === steps.length - 1 ? doneLabel : nextLabel }}</button>      </div>    </div>  </div></template>

#ブラウザーの対応状況

コーチマークの配置にはCSSアンカー配置を使います。カードにはposition-areaとposition-try-fallbacksを使い、矢印とツアーのスポットライトにはカードと参照先の要素の間にanchor()を使います。アンカー配置に対応していないブラウザーでも開閉でき、通常のポップオーバーと同じくビューポート中央に表示されます。この場合、矢印は表示されません。スポットライトは対象を明るく残せないため、何も暗くしません。ツアーのステップには、showPopover()のsourceオプションでアンカーを指定します。このオプションがなければ、ステップはアンカーなしで開きます。開始ボタンは呼び出しコマンドを使い、未対応のブラウザーではビヘイビアが代わりを務めます。フェードと短いスライドには@starting-styleを使います。対応していない場合、カードと背景幕はアニメーションなしで表示・非表示が切り替わります。

カードはフェードインしながらアンカーに向かって4px移動し、閉じるときはより短いフェードアウトで消えます。ほかのポップオーバーと違い、拡大・縮小は行いません。拡大・縮小すると矢印がカードの内側に収まり、指し示す要素に届かなくなるためです。

#クラス

クラス説明
coachmarkpopover 属性と role="dialog" を持つ要素に適用するインク色のカードで、タイトルをラベルにします。popover 属性がなければ表示されません。幅は 18rem で、開くきっかけとなった要素の真下に中央揃えで開き、下にスペースがなければ上に開きます。矢印はマークアップ上で直前の要素を指すため、ビーコンか、説明対象のコントロールの直後に置きます。
coachmark-top上側の空間を優先。画面下部のコントロールや、コントロールの上隅にあるビーコン向けcoachmark と併用します
coachmark-countタイトルの上に控えめなインク色で表示する短い 1 行です。ツアーでの位置(全 4 ステップ中の 2 番目)や「新機能」などを示します。
coachmark-titleコーチマークのラベルとなるステップの見出し。
coachmark-textコントロールの働きを説明する1〜2文
coachmark-actions小さなボタンをカードの端から 12px 離して下部に並べます。複数ある場合は最初のボタン(スキップ)を始端側に、残り(戻る、次へ)を終端側に置きます。既定のボタンはインク色の背景上でアクションとして見え、控えめなボタンにはカードのインク色が適用されます。
coachmark-tourツアーの各ステップと、そのスポットライトを収めます。各ステップは popover="manual" を付けたコーチマークで、たどる順に並べます。ツアーのビヘイビアをこの要素に適用し、ツアーを開始するボタンのために id を付けます。この要素自体は何も描画せず、矢印が指す対象の名前を内部で管理します。
coachmark-spotlightツアーが各ステップの前に、そのステップの対象の上に開く空のポップオーバーです。対象とその周囲 4px を覆い、開いているステップの矢印は、マークアップ内のどこにステップがあってもこれを指します。単体では何も描画せず、ポインター操作を透過します。
coachmark-spotlight-dimダイアログと同じ背景幕で対象の周囲のページを暗くし、対象は明るいまま残します。背景幕の下のページは引き続き操作できます。強制カラーモードでは、代わりにシステムのハイライト色の輪郭線で対象を示します。coachmark-spotlight と併用します
coachmark-beaconステップの位置を示すインク色の10pxの点で、popovertargetで対応するコーチマークを開きます。ときどき輪が広がります。ポインターが重なっている間、フォーカス中、コーチマークが開いている間、または動きを抑える設定では、輪が静止して点を囲みます。操作領域は24pxで、タッチ画面では44pxです。配置はページ側で指定し、通常は対象のコントロールの上側の角に置きます。

#カスタムプロパティ

プロパティ既定値説明
--coachmark-width18remカードの幅。最大でもビューポートの幅から 1rem を引いた値
--coachmark-inset12pxアクションからカードの端までの余白。テキストの余白はこれより 4px 大きくなります。カードの角丸半径は、小サイズのボタンの角丸半径にこの余白を加えた値です。
--coachmark-arrow7px矢印の先端がカードから突き出す距離
--anchored-gapcalc(var(--coachmark-arrow) + 6px)カードと開くきっかけとなった要素の間隔。矢印の先端はその要素から 6px 離れます。
--coachmark-beacon-size.625remビーコンの点の直径指定先:coachmark-beacon
--coachmark-spotlight-inset4pxスポットライトが対象から各辺に広がる距離指定先:coachmark-spotlight
--coachmark-spotlight-radiusvar(--radius-control)照らす対象の角の丸みです。スポットライトの角の丸みはこの値に inset を加えたものになります。指定先:coachmark-spotlight

#ソース

@master/ui/components/coachmark.css
/* * Coachmark: one step of a tour, pointing at the control it explains. * It is a popover of ink: a small card of the inverse surface sheet-inverse is made of, laid flat so its arrow * joins it without a seam. It stands apart from the sheets of ordinary popovers and from the page under it. * Anchor positioning centers it under the element that opened it (popovertarget, commandfor, or the source a * script passes to showPopover) and flips it above at the viewport's edge. It enters with a fade and slides 4px * toward that element. * An arrow of the same ink points at the element right before the coachmark in the markup, which is its beacon * or the control it explains: while the coachmark is open that element is named as an anchor, and the arrow * follows its middle when an edge pushes the card aside and moves to the other edge when the card flips. * Geometry: 12px between the actions and the card's edge, so the card's corner is a small button's corner plus * that inset, and a 7px arrow whose two flanks carry the card's contour into its point. * A beacon marks where a step is and is the button that opens it: a 10px ink dot that sends out a ring now and * then. Under the pointer, with focus, while its step is open and with reduced motion, the ring rests as a halo. * Without anchor positioning the card opens where the browser places a popover, centered, with no arrow. * A tour holds its steps in coachmark-tour, which keeps the name of what its arrows point at to itself. Its * spotlight is an empty popover the tour opens over each step's target with that target as its anchor: it * covers the target and 4px around it, so the card's arrow points there wherever the step stands in the * markup. It draws nothing by itself; dimmed, a ring of scrim as wide as the screen leaves the target lit, * and in forced colors, where shadows are gone, a system-color outline marks the target instead. The scrim * is paint only: the page under it still answers the pointer and the keys. */@layer components.ui {  .coachmark {    --coachmark-inset: 12px;    --coachmark-width: 18rem;    --coachmark-arrow: 7px;    --anchored-gap: calc(var(--coachmark-arrow) + 6px);    --anchored-inline: span-all;    --surface-color: var(--color-surface-inverse);    /* Focus rings stand on ink, so they are drawn in the ink of the words. */    --color-focus: var(--color-text-inverse);    @apply --on-ink;    flex-direction: column;    gap: .25rem;    width: min(var(--coachmark-width), calc(100vw - 1rem));    padding: calc(var(--coachmark-inset) + 4px) calc(var(--coachmark-inset) + 4px) var(--coachmark-inset);    border: 0;    border-radius: calc(var(--radius-control-sm) * var(--corner-scale) + var(--coachmark-inset));    corner-shape: var(--corner-shape);    overflow: visible;    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 3px 6px -3px var(--color-shade-2), 0 6px 12px -6px var(--color-shade-3),      0 12px 24px -12px var(--color-shade-4), 0 24px 48px -24px var(--color-shade-5);    font: 400 .8125rem/1.5 var(--font-family-sans);    font-feature-settings: inherit;    overflow-wrap: anywhere;    overscroll-behavior: contain;    @apply --anchored;    /*     * In and out of the top layer. Not --pop: a scale would make the card the containing block of its arrow,     * which could then no longer reach the element it points at. Closed is where it leaves to.     */    opacity: 0;    transition-property: opacity, margin, overlay, display;    transition-duration: var(--duration-quick);    transition-timing-function: var(--easing-glide);    transition-behavior: allow-discrete;    &:popover-open {      display: flex;      opacity: 1;      transition-duration: var(--duration-base);      @starting-style {        opacity: 0;      }    }    /* Prefer the space above. */    &.coachmark-top {      --anchored-block: block-start;    }    /* A step with no action to focus is focused itself, as a dialog is, and reads as its title. */    &:focus-visible {      outline: none;    }    @media (forced-colors: active) {      &, &:focus-visible {        outline: 1px solid CanvasText;        outline-offset: -1px;      }    }  }  /*   * The spotlight: an empty popover, nothing of the browser's own box. Where anchor positioning is missing it   * stays a point, and dims nothing it could not leave a hole in.   */  .coachmark-spotlight {    --coachmark-spotlight-inset: 4px;    --coachmark-spotlight-radius: var(--radius-control);    width: 0;    height: 0;    margin: 0;    padding: 0;    border: 0;    overflow: visible;    background: none;    pointer-events: none;  }  /*   * Placed: a half-rem from the viewport's sides when an edge pushes it aside, and only a flip to the other side   * of its anchor. It travels 4px toward the anchor as it enters and 2px away as it leaves; margins are swapped   * with the flip, so the travel follows the side it opened on.   */  @supports (position-area: block-end) {    .coachmark {      --coachmark-travel: 2px;      margin: calc(var(--anchored-gap) + var(--coachmark-travel)) .5rem;      position-try-fallbacks: flip-block;      anchor-name: --coachmark-card;      anchor-scope: --coachmark-card;      &:popover-open {        --coachmark-travel: 0px;        @starting-style {          --coachmark-travel: 4px;        }      }      @media (prefers-reduced-motion: reduce) {        &, &:popover-open {          --coachmark-travel: 0px;        }      }      /*       * The arrow: a square turned a quarter, its middle on the edge of the card that faces the element it       * points at, and a patch of the card's ink over its inner half, so only the point outside the card is       * seen. Both lie over the card's face and under its content, so the point covers the card's contour where       * they join and its own contour carries the card's into the point.       * They are fixed to the viewport and placed with anchor(), between that element and the card itself:       * across, at the element's middle, but never into the card's rounded corners; up and down, at whichever       * of the card's edges is nearer to it. With no element to point at, they meet in the card's middle, where       * the patch hides the arrow.       */      &::before, &::after {        --coachmark-arrow-side: calc(var(--coachmark-arrow) * 1.4142);        --coachmark-arrow-reach: calc(var(--radius-control-sm) * var(--corner-scale) + var(--coachmark-inset) + var(--coachmark-arrow));        --coachmark-arrow-x: clamp(          anchor(--coachmark-card left, 0px) + var(--coachmark-arrow-reach),          anchor(--coachmark-target center, anchor(--coachmark-card center, 0px)),          anchor(--coachmark-card right, 0px) - var(--coachmark-arrow-reach)        );        --coachmark-arrow-y: clamp(          anchor(--coachmark-card top, 0px),          anchor(--coachmark-target center, anchor(--coachmark-card center, 0px)),          anchor(--coachmark-card bottom, 0px)        );        content: '';        position: fixed;        z-index: -1;        background: var(--color-surface-inverse);        pointer-events: none;      }      &::before {        top: calc(var(--coachmark-arrow-y) - var(--coachmark-arrow-side) / 2);        left: calc(var(--coachmark-arrow-x) - var(--coachmark-arrow-side) / 2);        width: var(--coachmark-arrow-side);        height: var(--coachmark-arrow-side);        border-radius: 2px;        /* The light catches the two flanks that face up, which the patch hides when the arrow points down. */        box-shadow: inset .5px .5px 0 var(--color-ink-highlight), 0 0 0 .5px var(--color-ink-edge);        rotate: 45deg;      }      &::after {        top: clamp(          anchor(--coachmark-card top, 0px),          var(--coachmark-arrow-y) - var(--coachmark-arrow) - 1px,          anchor(--coachmark-card bottom, 0px) - var(--coachmark-arrow) * 2 - 2px        );        left: calc(var(--coachmark-arrow-x) - var(--coachmark-arrow) - .5px);        width: calc(var(--coachmark-arrow) * 2 + 1px);        height: calc(var(--coachmark-arrow) * 2 + 2px);      }      /*       * Forced colors repaint both as the canvas, and the card would point at nothing: the arrow is kept in the       * system's text color, and the patch in the canvas the card is repainted with.       */      @media (forced-colors: active) {        &::before, &::after {          forced-color-adjust: none;        }        &::before {          background: CanvasText;          box-shadow: none;        }        &::after {          background: Canvas;        }      }    }    /* The element right before an open coachmark is what its arrow points at. */    :where(:has(+ .coachmark:popover-open)) {      anchor-name: --coachmark-target;    }    /* A tour keeps the name to itself, so the arrows of its steps find its spotlight and no other. */    .coachmark-tour {      anchor-scope: --coachmark-target;    }    /*     * Over the target the tour opened it against, and 4px around it, with the corner of a control plus that     * inset. It is what the arrow of the open step points at.     */    .coachmark-spotlight {      /* The element it was opened against; anchor() alone does not reach for it as position-area does. */      position-anchor: auto;      inset: auto;      top: anchor(top);      right: anchor(right);      bottom: anchor(bottom);      left: anchor(left);      width: auto;      height: auto;      margin: calc(var(--coachmark-spotlight-inset) * -1);      border-radius: calc(var(--coachmark-spotlight-radius) * var(--corner-scale) + var(--coachmark-spotlight-inset));      corner-shape: var(--corner-shape);      anchor-name: --coachmark-target;      /*       * Dimmed: a scrim as wide as the screen, drawn as the spotlight's ring, so the target stays lit. It       * fades in as the tour starts and out as it ends, a fade reduced motion keeps; from one step to the       * next the hole moves at once, so there is no travel to take away.       */      &.coachmark-spotlight-dim {        box-shadow: 0 0 0 100vmax var(--color-surface-scrim);        opacity: 0;        transition-property: opacity, overlay, display;        transition-duration: var(--duration-quick);        transition-timing-function: var(--easing-glide);        transition-behavior: allow-discrete;        &:popover-open {          opacity: 1;          transition-duration: var(--duration-base);          @starting-style {            opacity: 0;          }        }        /* Shadows are gone in forced colors: the target is marked by an outline of the system's highlight. */        @media (forced-colors: active) {          outline: 2px solid Highlight;        }      }    }  }  /* Where the step stands in the tour: "2 of 4". */  .coachmark-count {    margin: 0;    color: color-mix(in oklab, currentColor 62%, transparent);    font-size: .75rem;    font-weight: var(--font-weight-control);    font-variant-numeric: tabular-nums;    line-height: 1.4;  }  .coachmark-title {    margin: 0;    color: inherit;    font: var(--font-weight-control) .875rem/1.4 var(--font-family-sans);    font-feature-settings: inherit;    text-wrap: balance;  }  .coachmark-text {    margin: 0;    color: color-mix(in oklab, currentColor 76%, transparent);    text-wrap: pretty;  }  /*   * The actions, along the foot: 12px from the card's edges, so a small button's corner nests in the card's.   * The first of several stands at the start (Skip, or Back), the others at the end.   */  .coachmark-actions {    display: flex;    flex-wrap: wrap;    align-items: center;    justify-content: flex-end;    gap: .25rem;    margin: .625rem -4px 0;    .btn:first-child:not(:only-child) {      margin-inline-end: auto;    }    /*     * The first is the first the row draws: a button left hidden on this step, such as Back on the first, is     * not counted, and a button left alone beside a hidden one stays at the end.     */    .btn:nth-child(1 of :not([hidden])) {      margin-inline-end: auto;    }    .btn:nth-child(1 of :not([hidden])):nth-last-child(1 of :not([hidden])) {      margin-inline-end: 0;    }  }  /*   * A quiet button on ink takes a quieter step of the card's ink, and a tint of it under the pointer; busy, it   * does not answer the pointer. These rules outweigh the quiet button's own hover, which would otherwise lay   * a pearl sheet in the strong ink of a page on the card.   */  .coachmark .btn.btn-quiet:not(:disabled, [aria-disabled="true"]) {    color: color-mix(in oklab, var(--color-text-inverse) 72%, transparent);    @media (hover: hover) {      &:hover:not([aria-busy="true"]) {        background: color-mix(in oklab, var(--color-text-inverse) 12%, transparent);        color: var(--color-text-inverse);        box-shadow: none;      }    }    &:active:not([aria-busy="true"]) {      background: color-mix(in oklab, var(--color-text-inverse) 18%, transparent);      color: var(--color-text-inverse);      box-shadow: none;    }  }  /*   * The beacon: a 10px dot of ink with a rim of the surface it stands on, and a ring that leaves it now and then   * to say there is something to see. The page places it, beside or on the corner of what it marks; its target   * is 24px, and 44px on a touch screen.   */  .coachmark-beacon {    --coachmark-beacon-size: .625rem;    position: relative;    display: inline-block;    flex: none;    width: var(--coachmark-beacon-size);    height: var(--coachmark-beacon-size);    margin: 0;    padding: 0;    border: 0;    border-radius: 999px;    corner-shape: round;    background: var(--color-surface-inverse);    box-shadow: 0 0 0 2px var(--surface-color, var(--color-surface-base)), 0 1px 3px 1.5px var(--color-shade-1);    vertical-align: middle;    appearance: none;    cursor: pointer;    touch-action: manipulation;    -webkit-tap-highlight-color: transparent;    transition: scale var(--duration-quick) var(--easing-glide);    /* The ring that leaves the dot. */    &::before {      content: '';      position: absolute;      inset: 0;      border-radius: inherit;      corner-shape: inherit;      box-shadow: 0 0 0 0 transparent;      pointer-events: none;      animation: coachmark-beacon 2.4s var(--easing-glide) infinite;    }    /* The target a pointer and a finger need, around the dot. */    &::after {      content: '';      position: absolute;      inset: calc((var(--coachmark-beacon-size) - 1.5rem) / 2);      @media (pointer: coarse) {        inset: calc((var(--coachmark-beacon-size) - 2.75rem) / 2);      }    }    @media (hover: hover) {      &:hover {        scale: 1.2;      }      &:hover::before {        box-shadow: 0 0 0 4px color-mix(in oklab, var(--color-surface-inverse) 14%, transparent);        animation: none;      }    }    &:active {      scale: .9;      transition-duration: var(--duration-press);    }    &:focus-visible {      @apply --focus-ring;      outline-offset: 4px;    }    /* Found: while it has focus or its step is open, the ring rests as a halo, as it does under the pointer. */    &:is(:focus-visible, :has(+ .coachmark:popover-open))::before {      box-shadow: 0 0 0 4px color-mix(in oklab, var(--color-surface-inverse) 14%, transparent);      animation: none;    }    @media (prefers-reduced-motion: reduce) {      transition: none;      &::before {        box-shadow: 0 0 0 4px color-mix(in oklab, var(--color-surface-inverse) 14%, transparent);        animation: none;      }      &:hover, &:active {        scale: none;      }    }    @media (forced-colors: active) {      outline: 2px solid ButtonText;      outline-offset: -2px;      background: ButtonText;      &::before {        animation: none;      }      /* The halo is a shadow, gone here: found, the dot takes the system's highlight instead. */      &:has(+ .coachmark:popover-open) {        outline-color: Highlight;        background: Highlight;      }      /* Keyboard focus is a ring of the highlight, as on a button. */      &:focus-visible {        outline: 2px solid Highlight;        outline-offset: 4px;      }    }  }}@keyframes coachmark-beacon {  0%, 20% {    box-shadow: 0 0 0 0 color-mix(in oklab, var(--color-surface-inverse) 42%, transparent);  }  75%, 100% {    box-shadow: 0 0 0 .625rem transparent;  }}