Stack
子要素を 1 方向に並べ、間隔をそろえる。縦(デフォルト)と横を選べる。間隔は余白のステップ(1〜7)で渡す。
tsx
import { Stack } from "knowidea-ui";カテゴリ: Layout。同じカテゴリ: Grid、FeaturedList、Container、Divider、AppShell、ListDetail
Demos
Column
デフォルトの向き。間隔は gap で指定する(デフォルトは 3 = 12px)。
1
2
3
Show code
tsx
import { Stack } from "knowidea-ui";const Box = ({ children }: { children: React.ReactNode }) => ( <div style={{ padding: "var(--space-2) var(--space-3)", background: "var(--color-surface)", border: "1px solid var(--color-line-strong)", borderRadius: "var(--radius-2)" }}>{children}</div>);function Column() { return ( <Stack gap={3} style={{ width: "min(100%, 320px)" }}> <Box>1</Box><Box>2</Box><Box>3</Box> </Stack> );}Row
wrap で折り返し、align で交差方向の位置をそろえる。
下書き
Show code
tsx
import { Stack, Button, Chip } from "knowidea-ui";function Row() { return ( <Stack direction="row" gap={2} wrap align="center" style={{ width: "100%" }}> <Button>保存する</Button> <Button variant="secondary">キャンセル</Button> <Chip label="下書き" /> </Stack> );}Space between
justify="between" を指定すると、両端に寄せて配置する。
見出し
Show code
tsx
import { Stack, Button } from "knowidea-ui";function Between() { return ( <Stack direction="row" justify="between" align="center" style={{ width: "100%" }}> <strong>見出し</strong> <Button variant="secondary">操作</Button> </Stack> );}Plain HTML
React を使わないページでは、knowidea-css の CSS を読み込み、クラスを指定する。
1
2
3
Show code
html
<div class="ki-stack" style="--ki-gap: var(--space-3)"> <p>1</p><p>2</p><p>3</p></div>States
すべてのコンポーネントが、Empty、Loading、Error、Disabled、Focus の 5 つの状態を備える。Hover と Active は、確認用に固定して表示している。そのコンポーネントにあてはまらない状態は「対象外」とし、理由を添える。
| State | Appearance |
|---|---|
| Empty | 子要素がなければ高さもない |
| Loading | 対象外。並べるだけのコンポーネントなので、ローディング状態を持たない |
| Error | 対象外。エラー状態を持たない |
| Disabled | 対象外。無効状態を持たない |
| Focus | 対象外。Stack 自身はフォーカスを受けない。子要素の順に Tab が進む |
API
| Name | Type | Default | Description |
|---|---|---|---|
direction | "column" | "row" | "column" | 縦か横か |
gap | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 3 | 余白のステップ(--space-N)。4、8、12、16、24、32、48px |
align | "start" | "center" | "end" | "stretch" | "baseline" | "stretch" | 交差方向の位置 |
justify | "start" | "center" | "end" | "between" | "start" | 並ぶ方向の位置 |
wrap | boolean | false | 収まらないときに折り返す |
as | ElementType | "div" | 描画する要素(ul、section など) |
CSS
Classes and data attributes
| Name | Description |
|---|---|
.ki-stack | 本体。data-direction="row"、data-wrap |
--ki-gap、--ki-align、--ki-justify | 間隔と位置(style で渡す) |
CSS variables
コンポーネントが参照するのは、役割を表す名前の変数だけで、素の値は参照しない。オーバーライドの方法は Overriding を参照。
| Variable | Usage |
|---|---|
| --space-1 〜 --space-7 | gap のステップ |
Accessibility
- 並べるだけのコンポーネントで、読み上げの順序は子要素の並び順のまま。CSS で見た目の順序だけを入れ替えない