diff --git a/crates/storybook2/src/story_selector.rs b/crates/storybook2/src/story_selector.rs index 0c4abf9a136a9f1c294b0428cef3e451df4f8f86..9945b2e7ef599dcdf525ad27d84b0df585966338 100644 --- a/crates/storybook2/src/story_selector.rs +++ b/crates/storybook2/src/story_selector.rs @@ -18,6 +18,7 @@ pub enum ComponentStory { ContextMenu, Focus, Icon, + IconButton, Input, Keybinding, Label, @@ -37,6 +38,7 @@ impl ComponentStory { Self::ContextMenu => cx.build_view(|_| ui::ContextMenuStory).into(), Self::Focus => FocusStory::view(cx).into(), Self::Icon => cx.build_view(|_| ui::IconStory).into(), + Self::IconButton => cx.build_view(|_| ui::IconButtonStory).into(), Self::Input => cx.build_view(|_| ui::InputStory).into(), Self::Keybinding => cx.build_view(|_| ui::KeybindingStory).into(), Self::Label => cx.build_view(|_| ui::LabelStory).into(), diff --git a/crates/ui2/src/components/icon_button.rs b/crates/ui2/src/components/icon_button.rs index b5f4c07b0c824e179d331af11fff266d4a9c432c..b2f3f8403d6b050b6ecaa4e0638972ad3bdbe36e 100644 --- a/crates/ui2/src/components/icon_button.rs +++ b/crates/ui2/src/components/icon_button.rs @@ -65,8 +65,7 @@ impl RenderOnce for IconButton { } } - // todo! this extra wrapping div is to work around a bug - // where tooltips otherwise don't show up. + // HACK: Add an additional identified element wrapper to fix tooltips not showing up. div().id(self.id.clone()).child(button) } } diff --git a/crates/ui2/src/components/stories.rs b/crates/ui2/src/components/stories.rs index 6211bfff31955583e2405457488876385f13a00a..d1cec68b8979a8867ec27ce7f2ef244a639a15ec 100644 --- a/crates/ui2/src/components/stories.rs +++ b/crates/ui2/src/components/stories.rs @@ -3,6 +3,7 @@ mod button; mod checkbox; mod context_menu; mod icon; +mod icon_button; mod input; mod keybinding; mod label; @@ -13,6 +14,7 @@ pub use button::*; pub use checkbox::*; pub use context_menu::*; pub use icon::*; +pub use icon_button::*; pub use input::*; pub use keybinding::*; pub use label::*; diff --git a/crates/ui2/src/components/stories/icon_button.rs b/crates/ui2/src/components/stories/icon_button.rs new file mode 100644 index 0000000000000000000000000000000000000000..85a9e1a0e88b871265495561c0e4822172a0ff18 --- /dev/null +++ b/crates/ui2/src/components/stories/icon_button.rs @@ -0,0 +1,35 @@ +use gpui::{Div, Render}; +use story::Story; + +use crate::{prelude::*, Tooltip}; +use crate::{Icon, IconButton}; + +pub struct IconButtonStory; + +impl Render for IconButtonStory { + type Element = Div; + + fn render(&mut self, _cx: &mut ViewContext) -> Self::Element { + Story::container() + .child(Story::title_for::()) + .child(Story::label("Default")) + .child(div().w_8().child(IconButton::new("icon_a", Icon::Hash))) + .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)), + ), + ) + } +}