ZIm/crates/ui/src/components/stories/tab_bar.rs
Marshall Bowers fa53353c57
Rename IconElement to just Icon (#3974)
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
2024-01-09 10:11:20 -05:00

59 lines
2.1 KiB
Rust

use gpui::Render;
use story::Story;
use crate::{prelude::*, Tab, TabBar, TabPosition};
pub struct TabBarStory;
impl Render for TabBarStory {
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
let tab_count = 20;
let selected_tab_index = 3;
let tabs = (0..tab_count)
.map(|index| {
Tab::new(index)
.selected(index == selected_tab_index)
.position(if index == 0 {
TabPosition::First
} else if index == tab_count - 1 {
TabPosition::Last
} else {
TabPosition::Middle(index.cmp(&selected_tab_index))
})
.child(Label::new(format!("Tab {}", index + 1)).color(
if index == selected_tab_index {
Color::Default
} else {
Color::Muted
},
))
})
.collect::<Vec<_>>();
Story::container()
.child(Story::title_for::<TabBar>())
.child(Story::label("Default"))
.child(
h_stack().child(
TabBar::new("tab_bar_1")
.start_child(
IconButton::new("navigate_backward", IconName::ArrowLeft)
.icon_size(IconSize::Small),
)
.start_child(
IconButton::new("navigate_forward", IconName::ArrowRight)
.icon_size(IconSize::Small),
)
.end_child(
IconButton::new("new", IconName::Plus).icon_size(IconSize::Small),
)
.end_child(
IconButton::new("split_pane", IconName::Split)
.icon_size(IconSize::Small),
)
.children(tabs),
),
)
}
}