assistant_panel.rs

  1use std::marker::PhantomData;
  2
  3use gpui3::{rems, AbsoluteLength};
  4
  5use crate::prelude::*;
  6use crate::{Icon, IconButton, Label, Panel, PanelSide};
  7
  8#[derive(Element)]
  9pub struct AssistantPanel<S: 'static + Send + Sync + Clone> {
 10    state_type: PhantomData<S>,
 11    scroll_state: ScrollState,
 12    current_side: PanelSide,
 13}
 14
 15impl<S: 'static + Send + Sync + Clone> AssistantPanel<S> {
 16    pub fn new() -> Self {
 17        Self {
 18            state_type: PhantomData,
 19            scroll_state: ScrollState::default(),
 20            current_side: PanelSide::default(),
 21        }
 22    }
 23
 24    pub fn side(mut self, side: PanelSide) -> Self {
 25        self.current_side = side;
 26        self
 27    }
 28
 29    fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
 30        let theme = theme(cx);
 31
 32        Panel::new(cx)
 33            .children(vec![div()
 34                .flex()
 35                .flex_col()
 36                .h_full()
 37                .px_2()
 38                .gap_2()
 39                // Header
 40                .child(
 41                    div()
 42                        .flex()
 43                        .justify_between()
 44                        .gap_2()
 45                        .child(
 46                            div()
 47                                .flex()
 48                                .child(IconButton::new(Icon::Menu))
 49                                .child(Label::new("New Conversation")),
 50                        )
 51                        .child(
 52                            div()
 53                                .flex()
 54                                .items_center()
 55                                .gap_px()
 56                                .child(IconButton::new(Icon::SplitMessage))
 57                                .child(IconButton::new(Icon::Quote))
 58                                .child(IconButton::new(Icon::MagicWand))
 59                                .child(IconButton::new(Icon::Plus))
 60                                .child(IconButton::new(Icon::Maximize)),
 61                        ),
 62                )
 63                // Chat Body
 64                .child(
 65                    div()
 66                        .w_full()
 67                        .flex()
 68                        .flex_col()
 69                        .gap_3()
 70                        .overflow_y_scroll(self.scroll_state.clone())
 71                        .child(Label::new("Is this thing on?")),
 72                )
 73                .into_any()])
 74            .side(self.current_side)
 75            .width(AbsoluteLength::Rems(rems(32.)))
 76    }
 77}
 78
 79#[cfg(feature = "stories")]
 80pub use stories::*;
 81
 82#[cfg(feature = "stories")]
 83mod stories {
 84    use crate::Story;
 85
 86    use super::*;
 87
 88    #[derive(Element)]
 89    pub struct AssistantPanelStory<S: 'static + Send + Sync + Clone> {
 90        state_type: PhantomData<S>,
 91    }
 92
 93    impl<S: 'static + Send + Sync + Clone> AssistantPanelStory<S> {
 94        pub fn new() -> Self {
 95            Self {
 96                state_type: PhantomData,
 97            }
 98        }
 99
100        fn render(
101            &mut self,
102            _view: &mut S,
103            cx: &mut ViewContext<S>,
104        ) -> impl Element<ViewState = S> {
105            Story::container(cx)
106                .child(Story::title_for::<_, AssistantPanel<S>>(cx))
107                .child(Story::label(cx, "Default"))
108                .child(AssistantPanel::new())
109        }
110    }
111}