AppBar
画面上部のバー。タイトル(h1)、左側の要素、右側の操作、小さな補足を持つ。上部に固定することもできる。
tsx
import { AppBar, IconButton, Icon } from "knowidea-ui";カテゴリ: Navigation。同じカテゴリ: Link、Tabs、Menu、Breadcrumbs、Pagination、Drawer、BottomNavigation
Demos
Basic
左にナビゲーションを開くボタン、右に操作を置く。補足は右寄せにする。
Show code
tsx
import { AppBar, IconButton, Icon } from "knowidea-ui";function Basic() { return ( <div style={{ width: "100%", border: "1px solid var(--color-line)", borderRadius: "var(--radius-3)", overflow: "hidden" }}> <AppBar title="ホーム" leading={<IconButton label="ナビゲーションを開く" icon={<Icon name="menu" />} />} meta={<><span>更新</span><time>10/13 09:28</time></>} actions={<><IconButton label="更新" icon={<Icon name="refresh" />} /><IconButton label="設定" icon={<Icon name="settings" />} /></>} /> </div> );}Long title
タイトルは 1 行に収め、はみ出す分は省略記号で省く。
Show code
tsx
import { AppBar, IconButton, Icon } from "knowidea-ui";function Plain() { return ( <div style={{ width: "100%", border: "1px solid var(--color-line)", borderRadius: "var(--radius-3)", overflow: "hidden" }}> <AppBar title="とても長い画面のタイトルが入ったときは、1 行に収めて末尾を省略する" actions={<IconButton label="検索" icon={<Icon name="search" />} />} /> </div> );}Plain HTML
React を使わないページでは、knowidea-css の CSS を読み込み、クラスを指定する。
ホーム
Show code
html
<header class="ki-appbar"> <h1 class="ki-appbar__title">ホーム</h1> <div class="ki-appbar__actions"><button type="button" class="ki-button ki-icon-button" data-variant="quiet" aria-label="更新"><svg class="ki-icon" aria-hidden="true"><use href="#refresh"/></svg></button></div></header>States
すべてのコンポーネントが、Empty、Loading、Error、Disabled、Focus の 5 つの状態を備える。Hover と Active は、確認用に固定して表示している。そのコンポーネントにあてはまらない状態は「対象外」とし、理由を添える。
| State | Appearance |
|---|---|
| Empty | 対象外。タイトルのないバーは作らない |
| Loading | 対象外。タイトルは先に決まっているため、ローディング状態を持たない。コンテンツの読み込みは本文側で示す |
| Error | 対象外。エラー状態を持たない。画面のエラーは本文側の Alert で示す |
| Disabled | サンプル |
| Focus | サンプル |
API
| Name | Type | Default | Description |
|---|---|---|---|
title | ReactNode | - | タイトル(h1)。必須 |
leading | ReactNode | - | タイトルの左に置く要素。ナビゲーションを開くボタンや戻るボタン |
actions | ReactNode | - | 右側に置く操作。IconButton を並べる |
meta | ReactNode | - | 右寄せの小さな補足。2 行まで |
headingLevel | 1 | 2 | 3 | 1 | タイトルの見出しレベル。ほかの見出しと並ぶ場所では 2 にする |
position | "static" | "sticky" | "static" | sticky を指定すると上部に固定される |
CSS
Classes and data attributes
| Name | Description |
|---|---|
.ki-appbar | 本体。data-position |
.ki-appbar__leading、__brand、__title、__meta、__actions | 内部の要素 |
CSS variables
コンポーネントが参照するのは、役割を表す名前の変数だけで、素の値は参照しない。オーバーライドの方法は Overriding を参照。
| Variable | Usage |
|---|---|
| --color-bg、--color-line | 背景と下線 |
| --font-size-4 | タイトルのフォントサイズ |
| --size-hit | 最小の高さの基準 |
Accessibility
- <header> の中に h1 を 1 つ置く。AppBar は 1 画面に 1 つだけ使う
- 右側の操作には IconButton を使い、名前(label)を必ず付ける