v0.1.0-alpha
官网Home
components/accordion
导航Navigation · 36 / 64

Accordion

ui.widgets.Accordion

折叠和展开分段内容。Collapse and expand sections.

BEHAVIOR CONTRACT

exclusive / 多开、expanded 状态、键盘激活与 body 生命周期一致。Exclusive or multi-open, expanded state, keyboard activation and body lifetime are consistent.

RECORDED INTERACTION

Harness 展开 Section Two。The harness expands Section Two.

examples/storybook/stories.zig:2323
// ── Accordion ──
pub fn buildAccordion(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
    const a = cx.allocator;
    const acc = try W.Accordion(.{ .exclusive = false, .gap = 8 }).mount(scope, cx);
    inline for (.{ "Section One", "Section Two", "Section Three" }, 0..) |title, i| {
        const item = try W.AccordionItem(.{ .title = title, .expanded = (i == 0) }).mount(scope, cx);
        try item.body.appendChild(a, try ui.text(cx, "Panel body content.", .{ .font_size = 13, .color = light.color.fg_secondary }));
        try acc.container.appendChild(a, item.item);
    }
    return acc.container;
}
在 GitHub 查看源码View source on GitHubexamples/storybook/stories.zig:2323

这是 Storybook 中该 story 的原样代码(zenit 5f9add5+wip 2026-09-30)。其中 W 即 ui.widgets,col / row / label 是 Storybook 内的布局小工具。The story's verbatim source from the Storybook (zenit 5f9add5+wip 2026-09-30). W is ui.widgets; col / row / label are small Storybook layout helpers.

zenit · 双授权Dual-licensed开源项目可按 GPL-3.0-only 免费使用;闭源或商业产品需要商业授权。Free for open-source projects under GPL-3.0-only; closed-source or commercial products need a commercial license.可联系作者:Contact the author: zongyi.xzy#gmail.com(# 换成 @) (replace # with @)zenit 5f9add5+wip 2026-09-30