KNOW IDEA UIv0.18.0GitHub

List

行の一覧。タイトル、2 行目のメタ情報、末尾の操作を持ち、行を選択できるようにもできる。幅に応じてレイアウトが切り替わる。

tsx
import { List } from "knowidea-ui";

カテゴリ: Data display。同じカテゴリ: Avatar、Badge、Chip、Status、Stat、Table、Timeline、Tooltip、Popover、CodeBlock、Kbd、Quote、Display、Jacket、Conversation、CodeEditor、DiffView

Demos

デモの数値はすべてサンプルであり、実際の値ではない。

Basic

タイトルはリンクで、行全体がクリック領域になる。

Show code
tsx
import { List, Status, Badge, type ListEntry } from "knowidea-ui";​const items: ListEntry[] = [  { id: "a", title: "デザインの見直し", href: "#a", meta: <><Status kind="working" label="処理中" /><span>更新 <time className="ki-list__num">10/13 09:28</time></span></> },  { id: "b", title: "アイコンの整理", href: "#b", meta: <><Status kind="paused" label="待機中" /><span>更新 <time className="ki-list__num">10/12 18:02</time></span></>, side: <Badge tone="warn">確認待ち</Badge> },  { id: "c", title: "色の検査", href: "#c", meta: <><Status kind="success" label="完了" /><span>更新 <time className="ki-list__num">10/12 11:40</time></span></> },];​function Basic() {  return (    <div style={{ width: "100%" }}>      <List label="項目の一覧" items={items} />    </div>  );}

Selectable

左端のチェックボックスで行を選択する。上部のチェックボックスですべてを選択する。

Show code
tsx
import { useState } from "react";import { List, Status, Badge, type ListEntry } from "knowidea-ui";​const items: ListEntry[] = [  { id: "a", title: "デザインの見直し", href: "#a", meta: <><Status kind="working" label="処理中" /><span>更新 <time className="ki-list__num">10/13 09:28</time></span></> },  { id: "b", title: "アイコンの整理", href: "#b", meta: <><Status kind="paused" label="待機中" /><span>更新 <time className="ki-list__num">10/12 18:02</time></span></>, side: <Badge tone="warn">確認待ち</Badge> },  { id: "c", title: "色の検査", href: "#c", meta: <><Status kind="success" label="完了" /><span>更新 <time className="ki-list__num">10/12 11:40</time></span></> },];​function Selectable() {  const [sel, setSel] = useState<string[]>(["b"]);  return (    <div style={{ width: "100%" }}>      <List label="項目の一覧" items={items} selected={sel} onSelectedChange={setSel} summary={`${items.length} 件`} />    </div>  );}

Queue before sending

選択して操作すると「送信待ち」の一覧に追加され、あとからまとめて 1 回で送信する。SelectionBar と組み合わせた例。

0 件を選択中

項目を選択すると、ここに操作が表示される。

送信待ち 0 件

項目を選択して操作すると、ここに追加される。

Show code
tsx
import { useState } from "react";import { List, Status, Button, SelectionBar, Stack, Alert, Icon, Badge, type ListEntry } from "knowidea-ui";​const items: ListEntry[] = [  { id: "a", title: "デザインの見直し", href: "#a", meta: <><Status kind="working" label="処理中" /><span>更新 <time className="ki-list__num">10/13 09:28</time></span></> },  { id: "b", title: "アイコンの整理", href: "#b", meta: <><Status kind="paused" label="待機中" /><span>更新 <time className="ki-list__num">10/12 18:02</time></span></>, side: <Badge tone="warn">確認待ち</Badge> },  { id: "c", title: "色の検査", href: "#c", meta: <><Status kind="success" label="完了" /><span>更新 <time className="ki-list__num">10/12 11:40</time></span></> },];​/** キューに追加してから送信する形: 選択した項目への操作を「送信待ち」の一覧に追加し、まとめて 1 回で送信する */function Queue() {  const [sel, setSel] = useState<string[]>([]);  const [queue, setQueue] = useState<{ id: string; action: string }[]>([]);  const [phase, setPhase] = useState<"idle" | "sending" | "sent">("idle");  const add = (action: string) => {    setQueue((q) => [...q.filter((x) => !sel.includes(x.id)), ...sel.map((id) => ({ id, action }))]);    setSel([]);  };  const send = () => {    setPhase("sending");    setTimeout(() => { setPhase("sent"); setQueue([]); }, 900);  };  const title = (id: string) => String(items.find((i) => i.id === id)?.title);  return (    <Stack gap={3} style={{ width: "100%" }}>      <List label="項目の一覧" items={items} selected={sel} onSelectedChange={setSel} />      <SelectionBar        count={sel.length}        actions={<>          <Button variant="secondary" icon={<Icon name="check" />} disabled={sel.length === 0} onClick={() => add("承認")}>承認</Button>          <Button variant="secondary" icon={<Icon name="close" />} disabled={sel.length === 0} onClick={() => add("却下")}>却下</Button>        </>}        onClear={() => setSel([])}      />      <Stack gap={2}>        <p style={{ margin: 0 }}><b>送信待ち</b> <span className="num">{queue.length}</span> 件</p>        {queue.length === 0 ? <p className="muted" style={{ margin: 0 }}>{phase === "sent" ? "送信した。" : "項目を選択して操作すると、ここに追加される。"}</p> : (          <ul className="plain" style={{ margin: 0 }}>            {queue.map((q) => <li key={q.id}>{q.action}: {title(q.id)} <Button variant="quiet" onClick={() => setQueue((x) => x.filter((y) => y.id !== q.id))}>取り消し</Button></li>)}          </ul>        )}        <div><Button loading={phase === "sending"} loadingLabel="送信中" disabled={queue.length === 0} onClick={send} icon={<Icon name="send" />}>まとめて送信</Button></div>        {phase === "sent" ? <Alert tone="success" live>まとめて 1 回で送信した。</Alert> : null}      </Stack>    </Stack>  );}

Motion

足した行は上から少し滑って出る。消した時と並べ替えた時は、残った行が新しい位置へ滑る。初めて出た時と、動きを減らす設定では動かない。

Show code
tsx
import { useState } from "react";import { List, Status, Button, Badge, type ListEntry } from "knowidea-ui";​const items: ListEntry[] = [  { id: "a", title: "デザインの見直し", href: "#a", meta: <><Status kind="working" label="処理中" /><span>更新 <time className="ki-list__num">10/13 09:28</time></span></> },  { id: "b", title: "アイコンの整理", href: "#b", meta: <><Status kind="paused" label="待機中" /><span>更新 <time className="ki-list__num">10/12 18:02</time></span></>, side: <Badge tone="warn">確認待ち</Badge> },  { id: "c", title: "色の検査", href: "#c", meta: <><Status kind="success" label="完了" /><span>更新 <time className="ki-list__num">10/12 11:40</time></span></> },];​/** 足す、消す、並べ替える時に、行が滑る */function Motion() {  const [rows, setRows] = useState<ListEntry[]>(items);  const [n, setN] = useState(1);  return (    <div style={{ display: "grid", gap: "var(--space-3)", width: "100%" }}>      <div style={{ display: "flex", flexWrap: "wrap", gap: "var(--space-2)" }}>        <Button variant="secondary" onClick={() => { setRows([{ id: `n${n}`, title: `新しい項目 ${n}` }, ...rows]); setN(n + 1); }}>上に足す</Button>        <Button variant="secondary" disabled={rows.length === 0} onClick={() => setRows(rows.slice(1))}>先頭を消す</Button>        <Button variant="secondary" disabled={rows.length < 2} onClick={() => setRows([...rows].reverse())}>逆に並べる</Button>      </div>      <List label="動きの見本" items={rows} state={rows.length ? "ready" : "empty"} />    </div>  );}

States

すべてのコンポーネントが、Empty、Loading、Error、Disabled、Focus の 5 つの状態を備える。Hover と Active は、確認用に固定して表示している。そのコンポーネントにあてはまらない状態は「対象外」とし、理由を添える。

StateAppearance
Empty
  • 項目がない

Loading
読み込み中
Error
  • 一覧を取得できなかった。

Disabled
  • デザインの見直し

    処理中更新

  • 色の検査

    完了更新

選択できない行は文字が薄くなり、チェックボックスも操作できない

Focus

タイトルのリンクにフォーカスが移ると、2px のリングが表示される。実物は Tab で確認する

Hover

行にポインターを置くと背景が変わる

Selected

API

NameTypeDefaultDescription
labelstring-一覧の名前。必須(スクリーンリーダーが読み上げる)
itemsListEntry[]-{ id, title, href?, meta?, side?, disabled? }
selected / onSelectedChangestring[] / (ids) => void-両方を渡すと、選択できる一覧になる
state"ready" | "loading" | "empty" | "error""ready"状態
summaryReactNode-チェックボックスの横に表示するテキスト(件数など)
selectAllLabel / selectedLabelstring"すべて選択" / "{count} 件を選択中"上部のチェックボックスの文言
emptyText / errorText / loadingTextstring-各状態のメッセージ

CSS

Classes and data attributes

NameDescription
.ki-list一覧。container を持ち、幅が 560px 以上になると 1 行のレイアウトに切り替わる。data-selectable
.ki-list__item行。data-selected、data-disabled、data-state
.ki-list__pick、__main、__title、__meta、__side、__head、__state内部の要素

CSS variables

コンポーネントが参照するのは、役割を表す名前の変数だけで、素の値は参照しない。オーバーライドの方法は Overriding を参照。

VariableUsage
--color-surface、--color-surface-2、--color-line背景、ホバー時の背景、区切り線
--color-primary選択中の行の左線と背景
--size-hitタイトルのリンクとチェックボックスの高さ
--font-mono時刻と番号

Accessibility

KNOW IDEA UIv0.18.0

GitHub

ページと見出しを探す。/ か Ctrl K でどのページからも開く。

Code