notifications_panel.rs

 1use crate::{prelude::*, static_new_notification_items, static_read_notification_items};
 2use crate::{List, ListHeader};
 3
 4#[derive(Component)]
 5pub struct NotificationsPanel {
 6    id: ElementId,
 7}
 8
 9impl NotificationsPanel {
10    pub fn new(id: impl Into<ElementId>) -> Self {
11        Self { id: id.into() }
12    }
13
14    fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
15        div()
16            .id(self.id.clone())
17            .flex()
18            .flex_col()
19            .w_full()
20            .h_full()
21            .bg(cx.theme().colors().surface)
22            .child(
23                div()
24                    .id("header")
25                    .w_full()
26                    .flex()
27                    .flex_col()
28                    .overflow_y_scroll()
29                    .child(
30                        List::new(static_new_notification_items())
31                            .header(ListHeader::new("NEW").toggle(ToggleState::Toggled))
32                            .toggle(ToggleState::Toggled),
33                    )
34                    .child(
35                        List::new(static_read_notification_items())
36                            .header(ListHeader::new("EARLIER").toggle(ToggleState::Toggled))
37                            .empty_message("No new notifications")
38                            .toggle(ToggleState::Toggled),
39                    ),
40            )
41    }
42}
43
44#[cfg(feature = "stories")]
45pub use stories::*;
46
47#[cfg(feature = "stories")]
48mod stories {
49    use super::*;
50    use crate::{Panel, Story};
51    use gpui2::{Div, Render};
52
53    pub struct NotificationsPanelStory;
54
55    impl Render for NotificationsPanelStory {
56        type Element = Div<Self>;
57
58        fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
59            Story::container(cx)
60                .child(Story::title_for::<_, NotificationsPanel>(cx))
61                .child(Story::label(cx, "Default"))
62                .child(
63                    Panel::new("panel", cx).child(NotificationsPanel::new("notifications_panel")),
64                )
65        }
66    }
67}