components/switch
Actions · 03 / 64

Switch

ui.widgets.Switch

Un interrupteur pour les réglages qui s'appliquent immédiatement.

BEHAVIOR CONTRACT

États off, on et disabled bien distincts, avec sémantique clavier et accessibilité.

RECORDED INTERACTION

Le harness bascule le switch Off ; la piste et le texte d'état changent ensemble.

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

    const status = try ui.text(cx, "toggled → (none)", .{ .font_size = 13, .color = light.color.fg_secondary });
    status.meta.ownership.meta.test_id = "story.switch.status";
    try c.appendChild(a, status);
    const story = try cx.bindState(SwitchStory, .{ .status = status });

    const off_switch = try W.Switch(.{
        .label_text = "Off",
        .initial_checked = false,
        .on_change = ui.Cx.boolHandlerFrom(SwitchStory, story, SwitchStory.onChange),
    }).mount(scope, cx);
    off_switch.meta.ownership.meta.test_id = "story.switch.off";
    try c.appendChild(a, off_switch);
    try c.appendChild(a, try W.Switch(.{ .label_text = "On", .initial_checked = true }).mount(scope, cx));
    try c.appendChild(a, try W.Switch(.{ .label_text = "Disabled", .disabled = true }).mount(scope, cx));
    return c;
}
Voir le code sur GitHubexamples/storybook/stories.zig:392

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.

zenit · Double licenceGratuit pour les projets open source sous GPL-3.0-only ; les produits propriétaires ou commerciaux nécessitent une licence commerciale.Contacter l’auteur : zongyi.xzy#gmail.com (remplacez # par @)zenit 5f9add5+wip 2026-09-30