notifications_panel.rs

 1use std::marker::PhantomData;
 2
 3use crate::{prelude::*, static_new_notification_items, static_read_notification_items};
 4use crate::{List, ListHeader};
 5
 6#[derive(Element)]
 7pub struct NotificationsPanel<S: 'static + Send + Sync> {
 8    id: ElementId,
 9    state_type: PhantomData<S>,
10}
11
12impl<S: 'static + Send + Sync> NotificationsPanel<S> {
13    pub fn new(id: impl Into<ElementId>) -> Self {
14        Self {
15            id: id.into(),
16            state_type: PhantomData,
17        }
18    }
19
20    fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
21        let theme = theme(cx);
22
23        div()
24            .id(self.id.clone())
25            .flex()
26            .flex_col()
27            .w_full()
28            .h_full()
29            .bg(theme.surface)
30            .child(
31                div()
32                    .id("header")
33                    .w_full()
34                    .flex()
35                    .flex_col()
36                    .overflow_y_scroll()
37                    .child(
38                        List::new(static_new_notification_items())
39                            .header(ListHeader::new("NEW").toggle(ToggleState::Toggled))
40                            .toggle(ToggleState::Toggled),
41                    )
42                    .child(
43                        List::new(static_read_notification_items())
44                            .header(ListHeader::new("EARLIER").toggle(ToggleState::Toggled))
45                            .empty_message("No new notifications")
46                            .toggle(ToggleState::Toggled),
47                    ),
48            )
49    }
50}
51
52#[cfg(feature = "stories")]
53pub use stories::*;
54
55#[cfg(feature = "stories")]
56mod stories {
57    use crate::{Panel, Story};
58
59    use super::*;
60
61    #[derive(Element)]
62    pub struct NotificationsPanelStory<S: 'static + Send + Sync + Clone> {
63        state_type: PhantomData<S>,
64    }
65
66    impl<S: 'static + Send + Sync + Clone> NotificationsPanelStory<S> {
67        pub fn new() -> Self {
68            Self {
69                state_type: PhantomData,
70            }
71        }
72
73        fn render(
74            &mut self,
75            _view: &mut S,
76            cx: &mut ViewContext<S>,
77        ) -> impl Element<ViewState = S> {
78            Story::container(cx)
79                .child(Story::title_for::<_, NotificationsPanel<S>>(cx))
80                .child(Story::label(cx, "Default"))
81                .child(
82                    Panel::new("panel", cx).child(NotificationsPanel::new("notifications_panel")),
83                )
84        }
85    }
86}