From 7ba305e033c338df13005c7a38c82e588edc1f24 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Fri, 13 Oct 2023 11:03:59 -0400 Subject: [PATCH] Hook up buttons in NotificationToast Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com> --- crates/ui2/src/components/notification.rs | 36 ++++++++++------------- crates/ui2/src/components/toast.rs | 4 +-- crates/ui2/src/components/workspace.rs | 7 +++-- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/crates/ui2/src/components/notification.rs b/crates/ui2/src/components/notification.rs index 31e7af410f532164f7ae7200923b43301333de45..424358efb21f7e978896e651001755aa46de34ae 100644 --- a/crates/ui2/src/components/notification.rs +++ b/crates/ui2/src/components/notification.rs @@ -3,12 +3,14 @@ use std::marker::PhantomData; use gpui3::{Element, ParentElement, StyleHelpers, ViewContext}; use crate::{ - h_stack, v_stack, Icon, IconButton, IconElement, Label, ThemeColor, Toast, ToastOrigin, + 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. /// +/// You must provide a primary action for the user to take. +/// /// To simply convey information, use a Status. #[derive(Element)] pub struct NotificationToast { @@ -16,47 +18,39 @@ pub struct NotificationToast { left_icon: Option, title: String, message: String, - // primary_action: Button, - // secondary_action: Option>, + primary_action: Option>, + secondary_action: Option>, } impl NotificationToast { pub fn new( title: impl Into, message: impl Into, - // primary_action: Button, + primary_action: Button, ) -> Self { Self { state_type: PhantomData, left_icon: None, title: title.into(), message: message.into(), - // primary_action, - // secondary_action: None, + primary_action: Some(primary_action), + secondary_action: None, } } - pub fn set_left_icon(mut self, icon: Icon) -> Self { + pub fn left_icon(mut self, icon: Icon) -> Self { self.left_icon = Some(icon); self } - // pub fn set_secondary_action(mut self, action: Button) -> Self { - // self.secondary_action = Some(action); - // self - // } + pub fn secondary_action(mut self, action: Button) -> Self { + self.secondary_action = Some(action); + self + } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let color = ThemeColor::new(cx); - // TODO: Fix me - - // let secondary_action = if self.secondary_action.is_some() { - // div().child(Some(self.secondary_action)) - // } else { - // div() - // }; - let notification = h_stack() .gap_1() .items_start() @@ -78,8 +72,8 @@ impl NotificationToast { h_stack() .gap_1() .justify_end() - .child(Label::new("Secondary").color(crate::LabelColor::Muted)) - .child(Label::new("Primary")), + .children(self.secondary_action.take()) + .children(self.primary_action.take()), ), ), ); diff --git a/crates/ui2/src/components/toast.rs b/crates/ui2/src/components/toast.rs index 81651ddf168194bda83d2fdf6ac579a676386f08..3290f458a521583db0269308b023efe3f83b7d8d 100644 --- a/crates/ui2/src/components/toast.rs +++ b/crates/ui2/src/components/toast.rs @@ -48,10 +48,10 @@ impl Toast { .flex() .py_2() .px_1p5() - .min_w_40() + .min_w_64() .rounded_md() .fill(color.elevated_surface) - .max_w_64() + .max_w_96() .children(self.children.drain(..)) } } diff --git a/crates/ui2/src/components/workspace.rs b/crates/ui2/src/components/workspace.rs index 9cdbb4683f8342c6f4aedee5136433c86cbac1d5..bcd7d406732f6f914f12ae20728c145445c72f2b 100644 --- a/crates/ui2/src/components/workspace.rs +++ b/crates/ui2/src/components/workspace.rs @@ -3,9 +3,9 @@ use gpui3::{px, relative, rems, view, Context, Size, View}; use crate::{ hello_world_rust_editor_with_status_example, random_players_with_call_status, theme, v_stack, - AssistantPanel, ChatMessage, ChatPanel, CollabPanel, EditorPane, Label, LanguageSelector, - Livestream, Pane, PaneGroup, Panel, PanelAllowedSides, PanelSide, ProjectPanel, SplitDirection, - StatusBar, Terminal, TitleBar, Toast, ToastOrigin, + AssistantPanel, Button, ChatMessage, ChatPanel, CollabPanel, EditorPane, Label, + LanguageSelector, Livestream, Pane, PaneGroup, Panel, PanelAllowedSides, PanelSide, + ProjectPanel, SplitDirection, StatusBar, Terminal, TitleBar, Toast, ToastOrigin, }; use crate::{prelude::*, NotificationToast}; @@ -270,6 +270,7 @@ impl Workspace { .child(NotificationToast::new( "A notification", "This is a notification", + Button::new("Primary"), )) } }