1use gpui::{Div, Render};
2use story::Story;
3
4use crate::{prelude::*, Tab, TabBar, TabPosition};
5
6pub struct TabBarStory;
7
8impl Render for TabBarStory {
9 type Element = Div;
10
11 fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
12 let tab_count = 20;
13 let selected_tab_index = 3;
14
15 let tabs = (0..tab_count)
16 .map(|index| {
17 Tab::new(index)
18 .selected(index == selected_tab_index)
19 .position(if index == 0 {
20 TabPosition::First
21 } else if index == tab_count - 1 {
22 TabPosition::Last
23 } else {
24 TabPosition::Middle(index.cmp(&selected_tab_index))
25 })
26 .child(Label::new(format!("Tab {}", index + 1)).color(
27 if index == selected_tab_index {
28 Color::Default
29 } else {
30 Color::Muted
31 },
32 ))
33 })
34 .collect::<Vec<_>>();
35
36 Story::container()
37 .child(Story::title_for::<TabBar>())
38 .child(Story::label("Default"))
39 .child(
40 h_stack().child(
41 TabBar::new("tab_bar_1")
42 .start_child(
43 IconButton::new("navigate_backward", Icon::ArrowLeft)
44 .icon_size(IconSize::Small),
45 )
46 .start_child(
47 IconButton::new("navigate_forward", Icon::ArrowRight)
48 .icon_size(IconSize::Small),
49 )
50 .end_child(IconButton::new("new", Icon::Plus).icon_size(IconSize::Small))
51 .end_child(
52 IconButton::new("split_pane", Icon::Split).icon_size(IconSize::Small),
53 )
54 .children(tabs),
55 ),
56 )
57 }
58}