button.rs

 1use gpui::{Div, Render};
 2use story::Story;
 3
 4use crate::prelude::*;
 5use crate::{h_stack, Button, Icon, IconPosition};
 6
 7pub struct ButtonStory;
 8
 9impl Render for ButtonStory {
10    type Element = Div;
11
12    fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
13        Story::container()
14            .child(Story::title_for::<Button>())
15            .child(
16                div()
17                    .flex()
18                    .gap_8()
19                    .child(
20                        div().child(Story::label("Ghost (Default)")).child(
21                            h_stack()
22                                .gap_2()
23                                .child(Button::new("Label").variant(ButtonVariant::Ghost)),
24                        ),
25                    )
26                    .child(Story::label("Ghost – Left Icon"))
27                    .child(
28                        h_stack().gap_2().child(
29                            Button::new("Label")
30                                .variant(ButtonVariant::Ghost)
31                                .icon(Icon::Plus)
32                                .icon_position(IconPosition::Left),
33                        ),
34                    ),
35            )
36            .child(Story::label("Ghost – Right Icon"))
37            .child(
38                h_stack().gap_2().child(
39                    Button::new("Label")
40                        .variant(ButtonVariant::Ghost)
41                        .icon(Icon::Plus)
42                        .icon_position(IconPosition::Right),
43                ),
44            )
45            .child(
46                div().child(Story::label("Filled")).child(
47                    h_stack()
48                        .gap_2()
49                        .child(Button::new("Label").variant(ButtonVariant::Filled)),
50                ),
51            )
52            .child(Story::label("Filled – Left Button"))
53            .child(
54                h_stack().gap_2().child(
55                    Button::new("Label")
56                        .variant(ButtonVariant::Filled)
57                        .icon(Icon::Plus)
58                        .icon_position(IconPosition::Left),
59                ),
60            )
61            .child(Story::label("Filled – Right Button"))
62            .child(
63                h_stack().gap_2().child(
64                    Button::new("Label")
65                        .variant(ButtonVariant::Filled)
66                        .icon(Icon::Plus)
67                        .icon_position(IconPosition::Right),
68                ),
69            )
70            .child(Story::label("Button with `on_click`"))
71            .child(
72                Button::new("Label")
73                    .variant(ButtonVariant::Ghost)
74                    .on_click(|_, _cx| println!("Button clicked.")),
75            )
76    }
77}