components/rate
Aktionen · 06 / 64

Rate

ui.widgets.Rate

Sternebewertungen oder Bewertungen mit begrenzter Anzahl.

BEHAVIOR CONTRACT

count, value, Größe und schreibgeschützt; die Hover-Vorschau entspricht dem übernommenen Wert.

RECORDED INTERACTION

Zeigt 5 und 10 Elemente, schreibgeschützt und drei Größen.

examples/storybook/stories.zig:2393
// ── Rate ──
pub fn buildRate(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
    const a = cx.allocator;
    const c = try col(cx, 16);
    const r1 = try W.Rate(.{ .count = 5, .value = 3 }).mount(scope, cx);
    try c.appendChild(a, try label(cx, "value 3 / 5"));
    try c.appendChild(a, r1.wrapper);
    const r2 = try W.Rate(.{ .count = 5, .value = 4, .disabled = true }).mount(scope, cx);
    try c.appendChild(a, try label(cx, "readonly value 4"));
    try c.appendChild(a, r2.wrapper);

    // ── count 变体 ──
    const r3 = try W.Rate(.{ .count = 10, .value = 7 }).mount(scope, cx);
    try c.appendChild(a, try label(cx, "count 10, value 7"));
    try c.appendChild(a, r3.wrapper);

    // ── size 变体 ──
    try c.appendChild(a, try label(cx, "Sizes (16 / 24 / 36)"));
    const sizes_row = try row(cx, 24);
    inline for (.{ 16, 24, 36 }) |sz| {
        const rn = try W.Rate(.{ .count = 5, .value = 3, .size = @as(f32, sz) }).mount(scope, cx);
        try sizes_row.appendChild(a, rn.wrapper);
    }
    try c.appendChild(a, sizes_row);
    return c;
}
Quellcode auf GitHub ansehenexamples/storybook/stories.zig:2393

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