1use std::marker::PhantomData;
2
3use gpui2::rems;
4
5use crate::{h_stack, prelude::*, Icon};
6
7#[derive(Element)]
8pub struct NotificationToast<S: 'static + Send + Sync + Clone> {
9 state_type: PhantomData<S>,
10 label: SharedString,
11 icon: Option<Icon>,
12}
13
14impl<S: 'static + Send + Sync + Clone> NotificationToast<S> {
15 pub fn new(label: SharedString) -> Self {
16 Self {
17 state_type: PhantomData,
18 label,
19 icon: None,
20 }
21 }
22
23 pub fn icon<I>(mut self, icon: I) -> Self
24 where
25 I: Into<Option<Icon>>,
26 {
27 self.icon = icon.into();
28 self
29 }
30
31 fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
32 let theme = theme(cx);
33
34 h_stack()
35 .z_index(5)
36 .absolute()
37 .top_1()
38 .right_1()
39 .w(rems(9999.))
40 .max_w_56()
41 .py_1()
42 .px_1p5()
43 .rounded_lg()
44 .shadow_md()
45 .bg(theme.elevated_surface)
46 .child(div().size_full().child(self.label.clone()))
47 }
48}