components/tag
Anzeige · 19 / 64

Tag

ui.widgets.Tag

Schließbare oder schreibgeschützte Kategorie-Labels.

BEHAVIOR CONTRACT

Farbe, variant, size, closable und Callbacks teilen konsistente Größen und Fokus.

RECORDED INTERACTION

Zeigt neutrale, Akzent- und Statusfarben sowie outline.

examples/storybook/stories.zig:552
// ── Tag ──
pub fn buildTag(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
    const a = cx.allocator;
    const c = try col(cx, 12);

    // ── 全部颜色(含 info)──
    const r1 = try row(cx, 8);
    inline for (.{ W.TagColor.neutral, .accent, .success, .warning, .danger, .info }, .{ "neutral", "accent", "success", "warning", "danger", "info" }) |col_, t| {
        try r1.appendChild(a, try W.Tag(.{ .text = t, .color = col_ }).mount(scope, cx));
    }
    try c.appendChild(a, try label(cx, "Colors"));
    try c.appendChild(a, r1);

    // ── 尺寸 ──
    try c.appendChild(a, try label(cx, "Sizes (sm / md)"));
    const r_sz = try row(cx, 8);
    inline for (.{ W.TagSize.sm, .md }, .{ "Small", "Medium" }) |sz, t| {
        try r_sz.appendChild(a, try W.Tag(.{ .text = t, .color = .accent, .size = sz }).mount(scope, cx));
    }
    try c.appendChild(a, r_sz);

    // ── 变体 ──
    try c.appendChild(a, try label(cx, "Variants"));
    const r2 = try row(cx, 8);
    try r2.appendChild(a, try W.Tag(.{ .text = "Default", .variant = .default }).mount(scope, cx));
    try r2.appendChild(a, try W.Tag(.{ .text = "Outline", .variant = .outline }).mount(scope, cx));
    try r2.appendChild(a, try W.Tag(.{ .text = "Closable", .closable = true }).mount(scope, cx));
    try r2.appendChild(a, try W.Tag(.{ .text = "Outline + close", .variant = .outline, .color = .danger, .closable = true }).mount(scope, cx));
    try c.appendChild(a, r2);
    return c;
}
Quellcode auf GitHub ansehenexamples/storybook/stories.zig:552

Der unveränderte Quellcode der Story aus dem Storybook (zenit 5f9add5+wip 2026-09-30). W steht für ui.widgets; col / row / label sind kleine Layout-Helfer des Storybooks.

zenit · DoppellizenzKostenlos für Open-Source-Projekte unter GPL-3.0-only; Closed-Source- oder kommerzielle Produkte benötigen eine kommerzielle Lizenz.Kontakt zum Autor: zongyi.xzy#gmail.com (# durch @ ersetzen)zenit 5f9add5+wip 2026-09-30