diff --git a/crates/ui2/src/components.rs b/crates/ui2/src/components.rs index f47676ed5f..bbbe9d1c37 100644 --- a/crates/ui2/src/components.rs +++ b/crates/ui2/src/components.rs @@ -12,6 +12,7 @@ mod keybinding; mod language_selector; mod list; mod multi_buffer; +mod notification; mod palette; mod panel; mod panes; @@ -43,6 +44,7 @@ pub use keybinding::*; pub use language_selector::*; pub use list::*; pub use multi_buffer::*; +pub use notification::*; pub use palette::*; pub use panel::*; pub use panes::*; diff --git a/crates/ui2/src/components/notification.rs b/crates/ui2/src/components/notification.rs new file mode 100644 index 0000000000..606096aeff --- /dev/null +++ b/crates/ui2/src/components/notification.rs @@ -0,0 +1,63 @@ +use gpui3::{Element, ParentElement, StyleHelpers, ViewContext}; + +use crate::{ + h_stack, v_stack, Button, Icon, IconButton, IconElement, Label, ThemeColor, Toast, ToastOrigin, +}; + +/// Notification toasts are used to display a message +/// that requires them to take action. +/// +/// To simply convey information, use a Status. +pub struct NotificationToast { + left_icon: Option, + title: String, + message: String, + actions: Vec>, +} + +impl NotificationToast { + pub fn new( + title: impl Into, + message: impl Into, + actions: Vec>, + ) -> Self { + Self { + left_icon: None, + title: title.into(), + message: message.into(), + actions, + } + } + + pub fn set_left_icon(mut self, icon: Icon) -> Self { + self.left_icon = Some(icon); + self + } + + fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + let color = ThemeColor::new(cx); + + let notification = h_stack() + .gap_1() + .items_start() + .children(self.left_icon.map(|i| IconElement::new(i))) + .child( + v_stack() + .child( + h_stack() + .justify_between() + .p_1() + .child(Label::new(self.title)) + .child(IconButton::new(Icon::Close)), + ) + .child( + h_stack() + .p_1() + .child(Label::new(self.message)) + .children(self.actions.iter().map(|action| action)), + ), + ); + + Toast::new(ToastOrigin::BottomRight) + } +} diff --git a/crates/ui2/src/components/toast.rs b/crates/ui2/src/components/toast.rs index 3acac81894..81651ddf16 100644 --- a/crates/ui2/src/components/toast.rs +++ b/crates/ui2/src/components/toast.rs @@ -10,13 +10,6 @@ pub enum ToastOrigin { BottomRight, } -#[derive(Default, Debug, PartialEq, Eq, Clone, Copy)] -pub enum ToastVariant { - #[default] - Toast, - Status, -} - /// A toast is a small, temporary window that appears to show a message to the user /// or indicate a required action. /// diff --git a/crates/ui2/src/elements/icon.rs b/crates/ui2/src/elements/icon.rs index bad5e7e2f4..74ee43b067 100644 --- a/crates/ui2/src/elements/icon.rs +++ b/crates/ui2/src/elements/icon.rs @@ -206,7 +206,11 @@ mod stories { } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + fn render( + &mut self, + _view: &mut S, + cx: &mut ViewContext, + ) -> impl Element { let icons = Icon::iter(); Story::container(cx)