tab.rs

  1use std::cmp::Ordering;
  2
  3use gpui::Render;
  4use story::Story;
  5
  6use crate::{prelude::*, TabPosition};
  7use crate::{Indicator, Tab};
  8
  9pub struct TabStory;
 10
 11impl Render for TabStory {
 12    fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
 13        Story::container()
 14            .child(Story::title_for::<Tab>())
 15            .child(Story::label("Default"))
 16            .child(h_stack().child(Tab::new("tab_1").child("Tab 1")))
 17            .child(Story::label("With indicator"))
 18            .child(
 19                h_stack().child(
 20                    Tab::new("tab_1")
 21                        .start_slot(Indicator::dot().color(Color::Warning))
 22                        .child("Tab 1"),
 23                ),
 24            )
 25            .child(Story::label("With close button"))
 26            .child(
 27                h_stack().child(
 28                    Tab::new("tab_1")
 29                        .end_slot(
 30                            IconButton::new("close_button", Icon::Close)
 31                                .icon_color(Color::Muted)
 32                                .size(ButtonSize::None)
 33                                .icon_size(IconSize::XSmall),
 34                        )
 35                        .child("Tab 1"),
 36                ),
 37            )
 38            .child(Story::label("List of tabs"))
 39            .child(
 40                h_stack()
 41                    .child(Tab::new("tab_1").child("Tab 1"))
 42                    .child(Tab::new("tab_2").child("Tab 2")),
 43            )
 44            .child(Story::label("List of tabs with first tab selected"))
 45            .child(
 46                h_stack()
 47                    .child(
 48                        Tab::new("tab_1")
 49                            .selected(true)
 50                            .position(TabPosition::First)
 51                            .child("Tab 1"),
 52                    )
 53                    .child(
 54                        Tab::new("tab_2")
 55                            .position(TabPosition::Middle(Ordering::Greater))
 56                            .child("Tab 2"),
 57                    )
 58                    .child(
 59                        Tab::new("tab_3")
 60                            .position(TabPosition::Middle(Ordering::Greater))
 61                            .child("Tab 3"),
 62                    )
 63                    .child(Tab::new("tab_4").position(TabPosition::Last).child("Tab 4")),
 64            )
 65            .child(Story::label("List of tabs with last tab selected"))
 66            .child(
 67                h_stack()
 68                    .child(
 69                        Tab::new("tab_1")
 70                            .position(TabPosition::First)
 71                            .child("Tab 1"),
 72                    )
 73                    .child(
 74                        Tab::new("tab_2")
 75                            .position(TabPosition::Middle(Ordering::Less))
 76                            .child("Tab 2"),
 77                    )
 78                    .child(
 79                        Tab::new("tab_3")
 80                            .position(TabPosition::Middle(Ordering::Less))
 81                            .child("Tab 3"),
 82                    )
 83                    .child(
 84                        Tab::new("tab_4")
 85                            .position(TabPosition::Last)
 86                            .selected(true)
 87                            .child("Tab 4"),
 88                    ),
 89            )
 90            .child(Story::label("List of tabs with second tab selected"))
 91            .child(
 92                h_stack()
 93                    .child(
 94                        Tab::new("tab_1")
 95                            .position(TabPosition::First)
 96                            .child("Tab 1"),
 97                    )
 98                    .child(
 99                        Tab::new("tab_2")
100                            .position(TabPosition::Middle(Ordering::Equal))
101                            .selected(true)
102                            .child("Tab 2"),
103                    )
104                    .child(
105                        Tab::new("tab_3")
106                            .position(TabPosition::Middle(Ordering::Greater))
107                            .child("Tab 3"),
108                    )
109                    .child(Tab::new("tab_4").position(TabPosition::Last).child("Tab 4")),
110            )
111    }
112}