Tabs
ui.widgets.Tabs같은 맥락 안에서 동등한 뷰를 전환합니다.
BEHAVIOR CONTRACT
underline / pill / tab, 크기, badge, disabled, active id가 하나의 선택 모델을 공유합니다.
RECORDED INTERACTION
harness가 Details를 클릭하면 인디케이터와 패널이 함께 전환됩니다.
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;
}Storybook에 있는 이 story의 원본 코드입니다(zenit 5f9add5+wip 2026-09-30). W는 ui.widgets이며, col / row / label은 Storybook 내부의 작은 레이아웃 헬퍼입니다.
TabsProps
ui.widgets.Tabsfn Tabs(props: TabsProps) TabsBuilder필드
타입
기본값
설명
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) TabPanelBuilder필드
타입
기본값
설명
id[]const u8—
—
activebooltrue—
*Node
ui.widgets.Tabsmount는 *Node을(를) 직접 반환합니다. 부모 노드에 append하면 됩니다.
TabPanelBuilder
ui.widgets.TabPanelmount는 TabPanelBuilder을(를) 직접 반환합니다. 부모 노드에 append하면 됩니다.