
This PR renames the `IconElement` component to just `Icon`. This better matches the rest of our components, as `IconElement` was the only one using this naming convention. The `Icon` enum has been renamed to `IconName` to free up the name. I was trying to come up with a way that would allow rendering an `Icon::Zed` directly (and thus make the `IconElement` a hidden part of the API), but I couldn't come up with a way to do this cleanly. Release Notes: - N/A
112 lines
4.2 KiB
Rust
112 lines
4.2 KiB
Rust
use std::cmp::Ordering;
|
|
|
|
use gpui::Render;
|
|
use story::Story;
|
|
|
|
use crate::{prelude::*, TabPosition};
|
|
use crate::{Indicator, Tab};
|
|
|
|
pub struct TabStory;
|
|
|
|
impl Render for TabStory {
|
|
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
|
Story::container()
|
|
.child(Story::title_for::<Tab>())
|
|
.child(Story::label("Default"))
|
|
.child(h_stack().child(Tab::new("tab_1").child("Tab 1")))
|
|
.child(Story::label("With indicator"))
|
|
.child(
|
|
h_stack().child(
|
|
Tab::new("tab_1")
|
|
.start_slot(Indicator::dot().color(Color::Warning))
|
|
.child("Tab 1"),
|
|
),
|
|
)
|
|
.child(Story::label("With close button"))
|
|
.child(
|
|
h_stack().child(
|
|
Tab::new("tab_1")
|
|
.end_slot(
|
|
IconButton::new("close_button", IconName::Close)
|
|
.icon_color(Color::Muted)
|
|
.size(ButtonSize::None)
|
|
.icon_size(IconSize::XSmall),
|
|
)
|
|
.child("Tab 1"),
|
|
),
|
|
)
|
|
.child(Story::label("List of tabs"))
|
|
.child(
|
|
h_stack()
|
|
.child(Tab::new("tab_1").child("Tab 1"))
|
|
.child(Tab::new("tab_2").child("Tab 2")),
|
|
)
|
|
.child(Story::label("List of tabs with first tab selected"))
|
|
.child(
|
|
h_stack()
|
|
.child(
|
|
Tab::new("tab_1")
|
|
.selected(true)
|
|
.position(TabPosition::First)
|
|
.child("Tab 1"),
|
|
)
|
|
.child(
|
|
Tab::new("tab_2")
|
|
.position(TabPosition::Middle(Ordering::Greater))
|
|
.child("Tab 2"),
|
|
)
|
|
.child(
|
|
Tab::new("tab_3")
|
|
.position(TabPosition::Middle(Ordering::Greater))
|
|
.child("Tab 3"),
|
|
)
|
|
.child(Tab::new("tab_4").position(TabPosition::Last).child("Tab 4")),
|
|
)
|
|
.child(Story::label("List of tabs with last tab selected"))
|
|
.child(
|
|
h_stack()
|
|
.child(
|
|
Tab::new("tab_1")
|
|
.position(TabPosition::First)
|
|
.child("Tab 1"),
|
|
)
|
|
.child(
|
|
Tab::new("tab_2")
|
|
.position(TabPosition::Middle(Ordering::Less))
|
|
.child("Tab 2"),
|
|
)
|
|
.child(
|
|
Tab::new("tab_3")
|
|
.position(TabPosition::Middle(Ordering::Less))
|
|
.child("Tab 3"),
|
|
)
|
|
.child(
|
|
Tab::new("tab_4")
|
|
.position(TabPosition::Last)
|
|
.selected(true)
|
|
.child("Tab 4"),
|
|
),
|
|
)
|
|
.child(Story::label("List of tabs with second tab selected"))
|
|
.child(
|
|
h_stack()
|
|
.child(
|
|
Tab::new("tab_1")
|
|
.position(TabPosition::First)
|
|
.child("Tab 1"),
|
|
)
|
|
.child(
|
|
Tab::new("tab_2")
|
|
.position(TabPosition::Middle(Ordering::Equal))
|
|
.selected(true)
|
|
.child("Tab 2"),
|
|
)
|
|
.child(
|
|
Tab::new("tab_3")
|
|
.position(TabPosition::Middle(Ordering::Greater))
|
|
.child("Tab 3"),
|
|
)
|
|
.child(Tab::new("tab_4").position(TabPosition::Last).child("Tab 4")),
|
|
)
|
|
}
|
|
}
|