アイコン
インラインアイコンのサイズは、配置先のコンポーネントに合わせます。
このページの内容
<svg>、<img>、またはアイコンコンポーネント自体にiconを指定します。各コンポーネントは子要素の種類でスタイルを振り分けず、--icon-sizeを設定してアイコンのサイズを決めます。そのため、同じマークアップでも、ボタン、バッジ、タブではアイコンのサイズが異なります。
同じアイコンを3つのコンポーネントで使う
<button type="button" class="btn btn-sm"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> Small</button><button type="button" class="btn"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> Medium</button><button type="button" class="btn btn-lg"> <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 10L16 10" /><path d="M10 4L10 16" /> </svg> Large</button>import PlusIcon16 from '@master/icons-react/native/16/soft/plus'import PlusIcon20 from '@master/icons-react/native/20/soft/plus'<> <button type="button" className="btn btn-sm"><PlusIcon16 className="icon" /> Small</button> <button type="button" className="btn"><PlusIcon16 className="icon" /> Medium</button> <button type="button" className="btn btn-lg"><PlusIcon20 className="icon" /> Large</button></><script> import PlusIcon16 from '@master/icons-svelte/native/16/soft/plus' import PlusIcon20 from '@master/icons-svelte/native/20/soft/plus'</script><button type="button" class="btn btn-sm"><PlusIcon16 class="icon" /> Small</button><button type="button" class="btn"><PlusIcon16 class="icon" /> Medium</button><button type="button" class="btn btn-lg"><PlusIcon20 class="icon" /> Large</button><script setup>import PlusIcon16 from '@master/icons-vue/native/16/soft/plus'import PlusIcon20 from '@master/icons-vue/native/20/soft/plus'</script><template> <button type="button" class="btn btn-sm"><PlusIcon16 class="icon" /> Small</button> <button type="button" class="btn"><PlusIcon16 class="icon" /> Medium</button> <button type="button" class="btn btn-lg"><PlusIcon20 class="icon" /> Large</button></template>#テキスト内
コンポーネントの外では、アイコンのサイズは1emです。小文字と揃うように、ベースラインよりわずかに下に配置します。
テキスト内
<p class="m(0) text-sm fg-text-body"> Press <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" role="img" aria-label="Download"> <path d="M8.5 9L8.4994 1.9755A0.5 0.5 0 0 0 7.5054 1.9266L7.5 2L7.5014 9.0379A0.5007 0.5007 0 0 0 7.5892 9.285A0.7044 0.7044 0 0 0 8.4108 9.285A0.4996 0.4996 0 0 0 8.5 9Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><path d="M5 6L7.8586 8.8586A0.2 0.2 0 0 0 8.1414 8.8586L11 6" /><path d="M2.5 10.5L2.5 12.5A1 1 0 0 0 3.5 13.5L12.5 13.5A1 1 0 0 0 13.5 12.5L13.5 10.5" /> </svg> to download the report.</p>import DownloadIcon from '@master/icons-react/native/16/soft/download'<p className="m(0) text-sm fg-text-body"> Press <DownloadIcon className="icon" aria-label="Download" /> to download the report.</p><script> import DownloadIcon from '@master/icons-svelte/native/16/soft/download'</script><p class="m(0) text-sm fg-text-body"> Press <DownloadIcon class="icon" aria-label="Download" /> to download the report.</p><script setup>import DownloadIcon from '@master/icons-vue/native/16/soft/download'</script><template> <p class="m(0) text-sm fg-text-body"> Press <DownloadIcon class="icon" aria-label="Download" /> to download the report. </p></template>#Master Icons
Master UI 自身のコンポーネントと例は Master Icons を使います。各アイコンは 16、20、24px 用に 3 回描かれ、currentColor で描画されます。icon は任意の SVG、画像、アイコンコンポーネントを受け取るため、ほかのセットも同じように使えます。Master Icons は既定であり、必須ではありません。
npm install @master/icons-react --save-exactフレームワークに合うパッケージをインストールします。@master/icons-react、-vue、-svelte、-preact、-astro のいずれか、SVG ファイルと素の JavaScript だけなら @master/icons です。
コンポーネントがアイコンに与えるサイズで図案を選び、その図案だけをインポートして icon を付けます。
| コンポーネントが設定するサイズ | 図案 | 図案の線幅 |
|---|---|---|
| 17px 以下 | 16 | 1 |
| 18〜22px | 20 | 1.25 |
| 22px 超 | 24 | 1.5 |
import SearchIcon from '@master/icons-react/native/16/soft/search'<button type="button" className="btn btn-square" aria-label="Search"> <SearchIcon className="icon" /></button>HTML では、コレクションから SVG をコピーして icon を付けます。名前はほかのセットと異なるため、書く前に検索します。
node node_modules/@master/icons/skills/master-icons/scripts/search.mjs "arrow left"#線幅
アイコンは図案が持つ線幅を保ちます。Master Icons はどのサイズもグリッドの 16 分の 1 の線幅で描かれているため、16px では 1px になり、コンポーネントが設定するサイズに比例して太くなります。Master Icons の太さを変えるには、@master/icons-react/16/soft などの固定エントリーで strokeWidth を選びます。切り欠きと隙間はその線幅に合わせて描き直されます。
線幅
<svg class="icon fg-text-strong" style="--icon-size: 1.5rem" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="12" cy="12" r="9" /><path d="M12 6.5L12 11.8892A0.2 0.2 0 0 0 12.094 12.0588L16 14.5" /></svg><svg class="icon fg-text-strong" style="--icon-size: 1.5rem; --icon-stroke: 1.25" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="12" cy="12" r="9" /><path d="M12 6.5L12 11.8892A0.2 0.2 0 0 0 12.094 12.0588L16 14.5" /></svg><svg class="icon fg-text-strong" style="--icon-size: 1.5rem; --icon-stroke: 2" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="12" cy="12" r="9" /><path d="M12 6.5L12 11.8892A0.2 0.2 0 0 0 12.094 12.0588L16 14.5" /></svg>import ClockIcon from '@master/icons-react/native/24/soft/clock'<> <ClockIcon className="icon fg-text-strong" style={{ '--icon-size': '1.5rem' } as React.CSSProperties} /> <ClockIcon className="icon fg-text-strong" style={{ '--icon-size': '1.5rem', '--icon-stroke': '1.25' } as React.CSSProperties} /> <ClockIcon className="icon fg-text-strong" style={{ '--icon-size': '1.5rem', '--icon-stroke': '2' } as React.CSSProperties} /></><script> import ClockIcon from '@master/icons-svelte/native/24/soft/clock'</script><ClockIcon class="icon fg-text-strong" style="--icon-size: 1.5rem" /><ClockIcon class="icon fg-text-strong" style="--icon-size: 1.5rem; --icon-stroke: 1.25" /><ClockIcon class="icon fg-text-strong" style="--icon-size: 1.5rem; --icon-stroke: 2" /><script setup>import ClockIcon from '@master/icons-vue/native/24/soft/clock'</script><template> <ClockIcon class="icon fg-text-strong" style="--icon-size: 1.5rem" /> <ClockIcon class="icon fg-text-strong" style="--icon-size: 1.5rem; --icon-stroke: 1.25" /> <ClockIcon class="icon fg-text-strong" style="--icon-size: 1.5rem; --icon-stroke: 2" /></template>--icon-stroke は図案の線幅を、図案の viewBox の単位で置き換えます。塗りつぶしアイコンには影響しません。単純な線画アイコンのセットをインターフェースの太さに合わせるときに使います。コンテナーに設定すると、中のアイコンすべてに適用されます。
#アクセシビリティ
- 装飾用のアイコンは、
aria-hidden="true"で支援技術から隠します。 - アイコンだけのコントロールには、コントロール自体に名前を付けます。たとえば、正方形ボタンには
aria-labelを指定します。 - 上の例のダウンロードの矢印のように、文中で語の代わりになるアイコンは、その語そのものです。
role="img"を指定し、見た目ではなく表している内容をaria-labelで示します。
#カスタムプロパティ
| プロパティ | 既定値 | 説明 |
|---|---|---|
--icon-size | アイコンの幅と高さです。アイコンを含むコンポーネントが設定します。コンポーネントの外では 1em になります。 | |
--icon-stroke | 図案の線幅を、図案の viewBox の単位で置き換えます。未設定時はアイコン自身の線幅を保ちます。塗りつぶしアイコンには影響しません。 | |
--icon-color | アイコンの色です。コンポーネントは、アイコンの色を控えめにしたり、色味を加えたりするために設定します。コンポーネントの外ではテキストと同じ色になります。 |
#クラス
| クラス | 説明 |
|---|---|
icon | --icon-size でサイズを指定するインラインアイコンです。コンポーネントの外では 1em になります。ベースラインよりわずかに下に配置します。 |