WIP IconButton story

This commit is contained in:
Nate Butler 2023-12-14 17:51:08 -05:00
parent 3cf003763e
commit 936c78be94
2 changed files with 163 additions and 53 deletions

View file

@ -1,5 +1,5 @@
use gpui::{ use gpui::{
div, green, red, Component, Div, HighlightStyle, InteractiveText, IntoElement, ParentElement, div, green, red, Component, HighlightStyle, InteractiveText, IntoElement, ParentElement,
Render, Styled, StyledText, View, VisualContext, WindowContext, Render, Styled, StyledText, View, VisualContext, WindowContext,
}; };
use indoc::indoc; use indoc::indoc;

View file

@ -1,5 +1,5 @@
use gpui::{Div, Render}; use gpui::{Component, Div, Render};
use story::Story; use story::{Story, StoryContainer, StoryItem, StorySection};
use crate::{prelude::*, Tooltip}; use crate::{prelude::*, Tooltip};
use crate::{Icon, IconButton}; use crate::{Icon, IconButton};
@ -7,57 +7,167 @@ use crate::{Icon, IconButton};
pub struct IconButtonStory; pub struct IconButtonStory;
impl Render for IconButtonStory { impl Render for IconButtonStory {
type Element = Div; type Element = Component<StoryContainer>;
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element { fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
Story::container() let default_button = StoryItem::new(
.child(Story::title_for::<IconButton>()) "Default",
.child(Story::label("Default")) IconButton::new("default_icon_button", Icon::Hash),
.child(div().w_8().child(IconButton::new("icon_a", Icon::Hash))) )
.child(Story::label("Selected")) .description("Displays an icon button.")
.child( .usage(
div() r#"
.w_8() IconButton::new("default_icon_button", Icon::Hash)
.child(IconButton::new("icon_a", Icon::Hash).selected(true)), "#,
) );
.child(Story::label("Selected with `selected_icon`"))
.child( let selected_button = StoryItem::new(
div().w_8().child( "Selected",
IconButton::new("icon_a", Icon::AudioOn) IconButton::new("selected_icon_button", Icon::Hash).selected(true),
.selected(true) )
.selected_icon(Icon::AudioOff), .description("Displays an icon button that is selected.")
), .usage(
) r#"
.child(Story::label("Disabled")) IconButton::new("selected_icon_button", Icon::Hash).selected(true)
.child( "#,
div() );
.w_8()
.child(IconButton::new("icon_a", Icon::Hash).disabled(true)), let selected_with_selected_icon = StoryItem::new(
) "Selected with `selected_icon`",
.child(Story::label("With `on_click`")) IconButton::new("selected_with_selected_icon_button", Icon::AudioOn)
.child( .selected(true)
div() .selected_icon(Icon::AudioOff),
.w_8() )
.child( .description(
IconButton::new("with_on_click", Icon::Ai).on_click(|_event, _cx| { "Displays an icon button that is selected and shows a different icon when selected.",
println!("Clicked!"); )
}), .usage(
), r#"
) IconButton::new("selected_with_selected_icon_button", Icon::AudioOn)
.child(Story::label("With `tooltip`")) .selected(true)
.child( .selected_icon(Icon::AudioOff)
div().w_8().child( "#,
IconButton::new("with_tooltip", Icon::MessageBubbles) );
.tooltip(|cx| Tooltip::text("Open messages", cx)),
), let disabled_button = StoryItem::new(
) "Disabled",
.child(Story::label("Selected with `tooltip`")) IconButton::new("disabled_icon_button", Icon::Hash).disabled(true),
.child( )
div().w_8().child( .description("Displays an icon button that is disabled.")
IconButton::new("selected_with_tooltip", Icon::InlayHint) .usage(
.selected(true) r#"
.tooltip(|cx| Tooltip::text("Toggle inlay hints", cx)), IconButton::new("disabled_icon_button", Icon::Hash).disabled(true)
), "#,
) );
let with_on_click_button = StoryItem::new(
"With `on_click`",
IconButton::new("with_on_click_button", Icon::Ai).on_click(|_event, _cx| {
println!("Clicked!");
}),
)
.description("Displays an icon button which triggers an event on click.")
.usage(
r#"
IconButton::new("with_on_click_button", Icon::Ai).on_click(|_event, _cx| {
println!("Clicked!");
})
"#,
);
let with_tooltip_button = StoryItem::new(
"With `tooltip`",
IconButton::new("with_tooltip_button", Icon::MessageBubbles)
.tooltip(|cx| Tooltip::text("Open messages", cx)),
)
.description("Displays an icon button that has a tooltip when hovered.")
.usage(
r#"
IconButton::new("with_tooltip_button", Icon::MessageBubbles)
.tooltip(|cx| Tooltip::text("Open messages", cx))
"#,
);
let selected_with_tooltip_button = StoryItem::new(
"Selected with `tooltip`",
IconButton::new("selected_with_tooltip_button", Icon::InlayHint)
.selected(true)
.tooltip(|cx| Tooltip::text("Toggle inlay hints", cx)),
)
.description("Displays a selected icon button with tooltip.")
.usage(
r#"
IconButton::new("selected_with_tooltip_button", Icon::InlayHint)
.selected(true)
.tooltip(|cx| Tooltip::text("Toggle inlay hints", cx))
"#,
);
let buttons = vec![
default_button,
selected_button,
selected_with_selected_icon,
disabled_button,
with_on_click_button,
with_tooltip_button,
selected_with_tooltip_button,
];
StoryContainer::new(
"Icon Button",
"crates/ui2/src/components/stories/icon_button.rs",
)
.children(vec![StorySection::new().children(buttons)])
.into_element()
// Story::container()
// .child(Story::title_for::<IconButton>())
// .child(Story::label("Default"))
// .child(div().w_8().child(IconButton::new("icon_a", Icon::Hash)))
// .child(Story::label("Selected"))
// .child(
// div()
// .w_8()
// .child(IconButton::new("icon_a", Icon::Hash).selected(true)),
// )
// .child(Story::label("Selected with `selected_icon`"))
// .child(
// div().w_8().child(
// IconButton::new("icon_a", Icon::AudioOn)
// .selected(true)
// .selected_icon(Icon::AudioOff),
// ),
// )
// .child(Story::label("Disabled"))
// .child(
// div()
// .w_8()
// .child(IconButton::new("icon_a", Icon::Hash).disabled(true)),
// )
// .child(Story::label("With `on_click`"))
// .child(
// div()
// .w_8()
// .child(
// IconButton::new("with_on_click", Icon::Ai).on_click(|_event, _cx| {
// println!("Clicked!");
// }),
// ),
// )
// .child(Story::label("With `tooltip`"))
// .child(
// div().w_8().child(
// IconButton::new("with_tooltip", Icon::MessageBubbles)
// .tooltip(|cx| Tooltip::text("Open messages", cx)),
// ),
// )
// .child(Story::label("Selected with `tooltip`"))
// .child(
// div().w_8().child(
// IconButton::new("selected_with_tooltip", Icon::InlayHint)
// .selected(true)
// .tooltip(|cx| Tooltip::text("Toggle inlay hints", cx)),
// ),
// )
} }
} }