assistant_panel.rs

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