Chip
ui.widgets.ChipChoix compacts, filtres ou tokens avec icône.
BEHAVIOR CONTRACT
active, outline, disabled, closable et les icônes réutilisent le control shell.
RECORDED INTERACTION
Parcourt les états, tailles et combinaisons d'icônes.
// ── 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;
}Le code source tel quel de la story dans le Storybook (zenit 5f9add5+wip 2026-09-30). W désigne ui.widgets ; col / row / label sont de petits helpers de mise en page du Storybook.
ChipProps
ui.widgets.Chipfn Chip(props: ChipProps) ChipBuilderChamp
Type
Défaut
Description
label[]const u8—
—
sizeChipSize.xs.sm.md.sm—
variantChipVariant.default.active.outline.disabled.default—
icon_asset?svg_assets.Assetnull—
closableboolfalse—
readonlybooltrue—
on_click?core.HandlerRefnull—
on_close?core.HandlerRefnull—
*Node
ui.widgets.Chipmount renvoie directement *Node : ajoutez-le à un parent.