components/chip
データ表示 · 20 / 64

Chip

ui.widgets.Chip

コンパクトな選択肢、フィルター条件、アイコン付き token。

BEHAVIOR CONTRACT

active、outline、disabled、closable とアイコンの組み合わせは control shell を再利用します。

RECORDED INTERACTION

状態、サイズ、アイコンの組み合わせを一巡します。

examples/storybook/stories.zig:584
// ── Chip ──
pub fn buildChip(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
    const a = cx.allocator;
    const icons = ui.assets.common;
    const c = try col(cx, 12);

    // ── 变体(含 disabled)──
    try c.appendChild(a, try label(cx, "Variants"));
    const r = try row(cx, 8);
    try r.appendChild(a, try W.Chip(.{ .label = "Default" }).mount(scope, cx));
    try r.appendChild(a, try W.Chip(.{ .label = "Active", .variant = .active }).mount(scope, cx));
    try r.appendChild(a, try W.Chip(.{ .label = "Outline", .variant = .outline }).mount(scope, cx));
    try r.appendChild(a, try W.Chip(.{ .label = "Disabled", .variant = .disabled }).mount(scope, cx));
    try r.appendChild(a, try W.Chip(.{ .label = "Closable", .closable = true }).mount(scope, cx));
    try c.appendChild(a, r);

    // ── 尺寸 ──
    try c.appendChild(a, try label(cx, "Sizes (xs / sm / md)"));
    const r_sz = try row(cx, 8);
    inline for (.{ W.ChipSize.xs, .sm, .md }, .{ "XS", "SM", "MD" }) |sz, t| {
        try r_sz.appendChild(a, try W.Chip(.{ .label = t, .size = sz, .variant = .active }).mount(scope, cx));
    }
    try c.appendChild(a, r_sz);

    // ── 带图标 ──
    try c.appendChild(a, try label(cx, "With icon"));
    const r_ic = try row(cx, 8);
    try r_ic.appendChild(a, try W.Chip(.{ .label = "Starred", .icon_asset = icons.star }).mount(scope, cx));
    try r_ic.appendChild(a, try W.Chip(.{ .label = "Folder", .icon_asset = icons.folder, .closable = true }).mount(scope, cx));
    try c.appendChild(a, r_ic);
    return c;
}
GitHub でソースを見るexamples/storybook/stories.zig:584

Storybook にあるこの story のコードそのままです(zenit 5f9add5+wip 2026-09-30)。W は ui.widgets のことで、col / row / label は Storybook 内の小さなレイアウトヘルパーです。

zenit · デュアルライセンスオープンソースプロジェクトは GPL-3.0-only のもとで無料で使えます。クローズドソースや商用製品には商用ライセンスが必要です。作者への連絡先:zongyi.xzy#gmail.com(# を @ に置き換え)zenit 5f9add5+wip 2026-09-30