audit toast

This commit is contained in:
2026-11-07 20:25:14 +07:00
parent 2b3e3b4e99
commit 65cae95851
2 changed files with 24 additions and 26 deletions
+20 -25
View File
@@ -12,7 +12,8 @@ use gpui::{
use gpui_native_icons::{IconRole, icon};
use gpui_native_theme::ActiveTheme as _;
use crate::common::DismissHandler;
use crate::button::{Button, ButtonVariant};
use crate::common::{DismissHandler, Sizable as _};
/// The action handler of a [`Toast`].
pub type ActionHandler = Rc<dyn Fn(&mut App)>;
@@ -256,12 +257,13 @@ impl RenderOnce for ToastsView {
fn pill(entry: &ToastEntry, toasts: &Entity<Toasts>, cx: &App) -> gpui::Stateful<gpui::Div> {
let theme = cx.theme();
let surface = theme.colors.surface;
let border = theme.colors.border;
let border = if theme.borders.overlays {
theme.colors.border
} else {
surface
};
let foreground = theme.colors.foreground;
let muted = theme.colors.muted;
let primary = theme.ramps.primary.base;
let primary_hover = theme.ramps.primary.hover;
let primary_foreground = theme.colors.primary_foreground;
let radius = theme.radius.full;
let shadows = theme.elevations.popover.shadows();
let icon_size = theme.sizes.small.icon_size;
@@ -304,25 +306,18 @@ fn pill(entry: &ToastEntry, toasts: &Entity<Toasts>, cx: &App) -> gpui::Stateful
.when_some(toast.action.clone(), |pill, action| {
let toasts = toasts.clone();
pill.child(
div()
.id(("toast-action", id))
.flex_none()
.ml_1p5()
.cursor_pointer()
.px_2()
.py_0p5()
.rounded(radius)
.bg(primary)
.hover(|style| style.bg(primary_hover))
.text_size(text_size)
.text_color(primary_foreground)
.child(action.label.clone())
.on_click(move |_, _window, cx| {
(action.handler.clone())(cx);
toasts.update(cx, |toasts, cx| {
toasts.dismiss(id, cx);
});
}),
div().flex_none().ml_2p5().child(
Button::new(("toast-action", id))
.label(action.label.clone())
.variant(ButtonVariant::Primary)
.small()
.on_click(move |_, _window, cx| {
(action.handler.clone())(cx);
toasts.update(cx, |toasts, cx| {
toasts.dismiss(id, cx);
});
}),
),
)
})
.child(
@@ -331,7 +326,7 @@ fn pill(entry: &ToastEntry, toasts: &Entity<Toasts>, cx: &App) -> gpui::Stateful
.flex_none()
.ml_4()
.cursor_pointer()
.p_0p5()
.p_1()
.rounded(theme.radius.sm)
.hover(|style| style.bg(muted))
.child(