assistant_panel.rs

 1use gpui2::{rems, AbsoluteLength};
 2
 3use crate::prelude::*;
 4use crate::{Icon, IconButton, Label, Panel, PanelSide};
 5
 6#[derive(Component)]
 7pub struct AssistantPanel {
 8    id: ElementId,
 9    current_side: PanelSide,
10}
11
12impl AssistantPanel {
13    pub fn new(id: impl Into<ElementId>) -> Self {
14        Self {
15            id: id.into(),
16            current_side: PanelSide::default(),
17        }
18    }
19
20    pub fn side(mut self, side: PanelSide) -> Self {
21        self.current_side = side;
22        self
23    }
24
25    fn render<V: 'static>(self, view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
26        Panel::new(self.id.clone(), cx)
27            .children(vec![div()
28                .flex()
29                .flex_col()
30                .h_full()
31                .px_2()
32                .gap_2()
33                // Header
34                .child(
35                    div()
36                        .flex()
37                        .justify_between()
38                        .gap_2()
39                        .child(
40                            div()
41                                .flex()
42                                .child(IconButton::new("menu", Icon::Menu))
43                                .child(Label::new("New Conversation")),
44                        )
45                        .child(
46                            div()
47                                .flex()
48                                .items_center()
49                                .gap_px()
50                                .child(IconButton::new("split_message", Icon::SplitMessage))
51                                .child(IconButton::new("quote", Icon::Quote))
52                                .child(IconButton::new("magic_wand", Icon::MagicWand))
53                                .child(IconButton::new("plus", Icon::Plus))
54                                .child(IconButton::new("maximize", Icon::Maximize)),
55                        ),
56                )
57                // Chat Body
58                .child(
59                    div()
60                        .id("chat-body")
61                        .w_full()
62                        .flex()
63                        .flex_col()
64                        .gap_3()
65                        .overflow_y_scroll()
66                        .child(Label::new("Is this thing on?")),
67                )
68                .render()])
69            .side(self.current_side)
70            .width(AbsoluteLength::Rems(rems(32.)))
71    }
72}
73
74#[cfg(feature = "stories")]
75pub use stories::*;
76
77#[cfg(feature = "stories")]
78mod stories {
79    use crate::Story;
80
81    use super::*;
82
83    #[derive(Component)]
84    pub struct AssistantPanelStory;
85
86    impl AssistantPanelStory {
87        fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
88            Story::container(cx)
89                .child(Story::title_for::<_, AssistantPanel>(cx))
90                .child(Story::label(cx, "Default"))
91                .child(AssistantPanel::new("assistant-panel"))
92        }
93    }
94}