デザインの見直し
見出しの大きさと余白の段をそろえる。
一覧と詳細を並べる。PC(1024px 以上)と iPad の横では 2 列、スマホ(横向きも)と iPad の縦では 1 列になり、一覧か詳細の片方を出す。切り替えは CSS だけで決まるので、幅が変わっても選んだ物は残る。
import { ListDetail, List } from "knowidea-ui";カテゴリ: Layout。同じカテゴリ: Stack、Grid、FeaturedList、Container、Divider、AppShell
一覧の行を押すと詳細が替わる。1 列の時は詳細に移り、一覧へ戻るボタンが出る。
import { useState } from "react";import { EmptyState, Icon, List, ListDetail, type ListEntry } from "knowidea-ui";const rows = [ { id: "a", title: "デザインの見直し", text: "見出しの大きさと余白の段をそろえる。" }, { id: "b", title: "アイコンの整理", text: "使っていないアイコンを外し、名前をそろえる。" }, { id: "c", title: "色の検査", text: "本文と線の差を、すべてのページで確かめる。" },];function Sample({ initial }: { initial?: string }) { const [id, setId] = useState<string | undefined>(initial); const [show, setShow] = useState(false); const row = rows.find((r) => r.id === id); const items: ListEntry[] = rows.map((r) => ({ id: r.id, title: r.title, href: `#${r.id}` })); return ( <div style={{ width: "100%" }} onClick={(e) => { const a = (e.target as HTMLElement).closest("a[href^='#']"); const next = a?.getAttribute("href")?.slice(1); if (next && rows.some((r) => r.id === next)) { e.preventDefault(); setId(next); setShow(true); } }}> <ListDetail list={<List label="仕事の一覧" items={items} />} detail={row ? <article><h3 style={{ marginTop: 0 }}>{row.title}</h3><p>{row.text}</p></article> : undefined} showDetail={show && !!row} onBack={() => setShow(false)} empty={<EmptyState title="仕事を選ぶ" icon={<Icon name="file" />}>左の一覧から選ぶと、ここに中身が出る。</EmptyState>} /> </div> );}function Basic() { return <Sample initial="a" />;}何も選んでいない時、2 列では詳細の側に empty を出す。
import { useState } from "react";import { EmptyState, Icon, List, ListDetail, type ListEntry } from "knowidea-ui";const rows = [ { id: "a", title: "デザインの見直し", text: "見出しの大きさと余白の段をそろえる。" }, { id: "b", title: "アイコンの整理", text: "使っていないアイコンを外し、名前をそろえる。" }, { id: "c", title: "色の検査", text: "本文と線の差を、すべてのページで確かめる。" },];function Sample({ initial }: { initial?: string }) { const [id, setId] = useState<string | undefined>(initial); const [show, setShow] = useState(false); const row = rows.find((r) => r.id === id); const items: ListEntry[] = rows.map((r) => ({ id: r.id, title: r.title, href: `#${r.id}` })); return ( <div style={{ width: "100%" }} onClick={(e) => { const a = (e.target as HTMLElement).closest("a[href^='#']"); const next = a?.getAttribute("href")?.slice(1); if (next && rows.some((r) => r.id === next)) { e.preventDefault(); setId(next); setShow(true); } }}> <ListDetail list={<List label="仕事の一覧" items={items} />} detail={row ? <article><h3 style={{ marginTop: 0 }}>{row.title}</h3><p>{row.text}</p></article> : undefined} showDetail={show && !!row} onBack={() => setShow(false)} empty={<EmptyState title="仕事を選ぶ" icon={<Icon name="file" />}>左の一覧から選ぶと、ここに中身が出る。</EmptyState>} /> </div> );}function Unselected() { return <Sample />;}すべてのコンポーネントが、Empty、Loading、Error、Disabled、Focus の 5 つの状態を備える。Hover と Active は、確認用に固定して表示している。そのコンポーネントにあてはまらない状態は「対象外」とし、理由を添える。
| Name | Type | Default | Description |
|---|---|---|---|
list | ReactNode | - | 一覧。List や Table など |
detail | ReactNode | - | 選んだ物の詳細。無ければ empty を出す |
showDetail | boolean | false | 1 列の時に、一覧でなく詳細を出す |
onBack | () => void | - | 1 列で詳細を出している時の、一覧へ戻るボタン。渡した時だけ出る |
backLabel | string | "一覧へ戻る" | 戻るボタンの文字 |
empty | ReactNode | - | 2 列で何も選んでいない時に、詳細の側に出す物 |
listLabel / detailLabel | string | "一覧" / "詳細" | 読み上げの名前 |
| Name | Description |
|---|---|
.ki-listdetail | 本体。data-show: list | detail |
.ki-listdetail__list、__detail | 一覧と詳細の <section> |
.ki-listdetail__back、__empty | 戻るボタンの行、何も選んでいない時の面 |
コンポーネントが参照するのは、役割を表す名前の変数だけで、素の値は参照しない。オーバーライドの方法は Overriding を参照。
| Variable | Usage |
|---|---|
| --space-4、--space-5 | 列の間 |