Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add notification toast component and remove ToastVariant from toast.rs
Nate Butlerc32b08102939
diff --git a/crates/ui2/src/components.rs b/crates/ui2/src/components.rsindex f47676ed5f7..bbbe9d1c37d 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.rsnew file mode 100644index 00000000000..606096aeffc--- /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<S: 'static + Send + Sync + Clone> {+ left_icon: Option<Icon>,+ title: String,+ message: String,+ actions: Vec<Button<S>>,+}++impl<S: 'static + Send + Sync + Clone> NotificationToast<S> {+ pub fn new(+ title: impl Into<String>,+ message: impl Into<String>,+ actions: Vec<Button<S>>,+ ) -> 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<S>) -> impl Element<ViewState = S> {+ 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.rsindex 3acac818942..81651ddf168 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.rsindex bad5e7e2f42..74ee43b0670 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<S>) -> impl Element<ViewState = S> {+ fn render(+ &mut self,+ _view: &mut S,+ cx: &mut ViewContext<S>,+ ) -> impl Element<ViewState = S> {let icons = Icon::iter();Story::container(cx)