icon_button.rs

 1use gpui::{Div, Render};
 2use story::Story;
 3
 4use crate::{prelude::*, Tooltip};
 5use crate::{Icon, IconButton};
 6
 7pub struct IconButtonStory;
 8
 9impl Render for IconButtonStory {
10    type Element = Div;
11
12    fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
13        Story::container()
14            .child(Story::title_for::<IconButton>())
15            .child(Story::label("Default"))
16            .child(div().w_8().child(IconButton::new("icon_a", Icon::Hash)))
17            .child(Story::label("Selected"))
18            .child(
19                div()
20                    .w_8()
21                    .child(IconButton::new("icon_a", Icon::Hash).selected(true)),
22            )
23            .child(Story::label("Disabled"))
24            .child(
25                div()
26                    .w_8()
27                    .child(IconButton::new("icon_a", Icon::Hash).disabled(true)),
28            )
29            .child(Story::label("With `on_click`"))
30            .child(
31                div()
32                    .w_8()
33                    .child(
34                        IconButton::new("with_on_click", Icon::Ai).on_click(|_event, _cx| {
35                            println!("Clicked!");
36                        }),
37                    ),
38            )
39            .child(Story::label("With `tooltip`"))
40            .child(
41                div().w_8().child(
42                    IconButton::new("with_tooltip", Icon::MessageBubbles)
43                        .tooltip(|cx| Tooltip::text("Open messages", cx)),
44                ),
45            )
46    }
47}