Tabs
ui.widgets.TabsBasculer entre des vues sœurs dans un même contexte.
BEHAVIOR CONTRACT
underline / pill / tab, les tailles, les badges, disabled et l'id actif partagent un même modèle de sélection.
RECORDED INTERACTION
Le harness clique sur Details ; l'indicateur et le panneau basculent ensemble.
pub fn buildTabs(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
const a = cx.allocator;
const c = try col(cx, 16);
const items = [_]W.tabs.TabItem{
.{ .id = "t1", .label_text = "Overview" },
.{ .id = "t2", .label_text = "Details" },
.{ .id = "t3", .label_text = "Settings", .badge = 3 },
.{ .id = "t4", .label_text = "Disabled", .disabled = true },
};
const status = try ui.text(cx, "active → (none)", .{ .font_size = 13, .color = light.color.fg_secondary });
status.meta.ownership.meta.test_id = "story.tabs.status";
try c.appendChild(a, status);
const story = try cx.bindState(TabsStory, .{ .status = status });
// ── 变体 ──
inline for (.{ W.tabs.TabsVariant.underline, .pill, .tab }, .{ "underline", "pill", "tab" }) |variant, name| {
try c.appendChild(a, try label(cx, name));
const tabs_node = try W.Tabs(.{
.items = &items,
.variant = variant,
.on_change = ui.Cx.strHandlerFrom(TabsStory, story, TabsStory.onChange),
}).mount(scope, cx);
if (variant == .underline) tabs_node.meta.ownership.meta.test_id = "story.tabs.underline";
try c.appendChild(a, tabs_node);
}
// ── 尺寸 ──
const size_items = [_]W.tabs.TabItem{
.{ .id = "a", .label_text = "One" },
.{ .id = "b", .label_text = "Two" },
.{ .id = "c", .label_text = "Three" },
};
try c.appendChild(a, try label(cx, "Sizes (xs / sm / md / lg)"));
inline for (.{ W.tabs.TabsSize.xs, .sm, .md, .lg }) |sz| {
try c.appendChild(a, try W.Tabs(.{ .items = &size_items, .variant = .pill, .size = sz }).mount(scope, cx));
}
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.
TabsProps
ui.widgets.Tabsfn Tabs(props: TabsProps) TabsBuilderChamp
Type
Défaut
Description
items[]const TabItem—
—
active_id?[]const u8null—
default_active_id?[]const u8null—
variantTabsVariant.underline.pill.tab.underline—
sizeTabsSize.md—
closableboolfalse—
on_change?core.HandlerRefnull2026-07-31 并轨:统一 ?core.HandlerRef,用 invokeWithStr 触发 (payload = tab id)。
on_close?core.HandlerRefnull—
context?*anyopaquenull—
state_id?u64null—
TabPanelProps
ui.widgets.TabPanelfn TabPanel(props: TabPanelProps) TabPanelBuilderChamp
Type
Défaut
Description
id[]const u8—
—
activebooltrue—
*Node
ui.widgets.Tabsmount renvoie directement *Node : ajoutez-le à un parent.
TabPanelBuilder
ui.widgets.TabPanelmount renvoie directement TabPanelBuilder : ajoutez-le à un parent.