collab_panel.rs

  1use crate::prelude::*;
  2use crate::{
  3    static_collab_panel_channels, static_collab_panel_current_call, v_stack, Icon, List,
  4    ListHeader, ToggleState,
  5};
  6use std::marker::PhantomData;
  7
  8#[derive(Element)]
  9pub struct CollabPanel<S: 'static + Send + Sync> {
 10    id: ElementId,
 11    state_type: PhantomData<S>,
 12}
 13
 14impl<S: 'static + Send + Sync> CollabPanel<S> {
 15    pub fn new(id: impl Into<ElementId>) -> Self {
 16        Self {
 17            id: id.into(),
 18            state_type: PhantomData,
 19        }
 20    }
 21
 22    fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
 23        let theme = theme(cx);
 24
 25        v_stack()
 26            .id(self.id.clone())
 27            .h_full()
 28            .bg(theme.surface)
 29            .child(
 30                v_stack()
 31                    .id("crdb")
 32                    .w_full()
 33                    .overflow_y_scroll()
 34                    .child(
 35                        div().pb_1().border_color(theme.border).border_b().child(
 36                            List::new(static_collab_panel_current_call())
 37                                .header(
 38                                    ListHeader::new("CRDB")
 39                                        .left_icon(Icon::Hash.into())
 40                                        .toggle(ToggleState::Toggled),
 41                                )
 42                                .toggle(ToggleState::Toggled),
 43                        ),
 44                    )
 45                    .child(
 46                        v_stack().id("channels").py_1().child(
 47                            List::new(static_collab_panel_channels())
 48                                .header(ListHeader::new("CHANNELS").toggle(ToggleState::Toggled))
 49                                .empty_message("No channels yet. Add a channel to get started.")
 50                                .toggle(ToggleState::Toggled),
 51                        ),
 52                    )
 53                    .child(
 54                        v_stack().id("contacts-online").py_1().child(
 55                            List::new(static_collab_panel_current_call())
 56                                .header(
 57                                    ListHeader::new("CONTACTS – ONLINE")
 58                                        .toggle(ToggleState::Toggled),
 59                                )
 60                                .toggle(ToggleState::Toggled),
 61                        ),
 62                    )
 63                    .child(
 64                        v_stack().id("contacts-offline").py_1().child(
 65                            List::new(static_collab_panel_current_call())
 66                                .header(
 67                                    ListHeader::new("CONTACTS – OFFLINE")
 68                                        .toggle(ToggleState::NotToggled),
 69                                )
 70                                .toggle(ToggleState::NotToggled),
 71                        ),
 72                    ),
 73            )
 74            .child(
 75                div()
 76                    .h_7()
 77                    .px_2()
 78                    .border_t()
 79                    .border_color(theme.border)
 80                    .flex()
 81                    .items_center()
 82                    .child(
 83                        div()
 84                            .text_sm()
 85                            .text_color(theme.text_placeholder)
 86                            .child("Find..."),
 87                    ),
 88            )
 89    }
 90}
 91
 92#[cfg(feature = "stories")]
 93pub use stories::*;
 94
 95#[cfg(feature = "stories")]
 96mod stories {
 97    use crate::Story;
 98
 99    use super::*;
100
101    #[derive(Element)]
102    pub struct CollabPanelStory<S: 'static + Send + Sync> {
103        state_type: PhantomData<S>,
104    }
105
106    impl<S: 'static + Send + Sync> CollabPanelStory<S> {
107        pub fn new() -> Self {
108            Self {
109                state_type: PhantomData,
110            }
111        }
112
113        fn render(
114            &mut self,
115            _view: &mut S,
116            cx: &mut ViewContext<S>,
117        ) -> impl Element<ViewState = S> {
118            Story::container(cx)
119                .child(Story::title_for::<_, CollabPanel<S>>(cx))
120                .child(Story::label(cx, "Default"))
121                .child(CollabPanel::new("collab-panel"))
122        }
123    }
124}