chore: audit components
This commit is contained in:
+21
-18
@@ -3,13 +3,16 @@ use std::rc::Rc;
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
Animation, AnimationExt as _, App, Context, ElementId, Entity, InteractiveElement as _,
|
||||
IntoElement, ParentElement as _, RenderOnce, SharedString, StatefulInteractiveElement as _,
|
||||
Styled as _, Window, deferred, div, ease_out_quint, px,
|
||||
IntoElement, ParentElement as _, RenderOnce, Role, SharedString,
|
||||
StatefulInteractiveElement as _, Styled as _, Window, deferred, div, ease_out_quint,
|
||||
};
|
||||
use gpui_native_icons::{Icon, IconRole, icon};
|
||||
use gpui_native_theme::{ActiveTheme as _, Size};
|
||||
use gpui_native_theme::{ActiveTheme as _, ENTER_SLIDE_DISTANCE, Size};
|
||||
use gpui_native_utils::ResultLogErr as _;
|
||||
|
||||
use crate::button::{Button, ButtonVariant};
|
||||
use crate::common::DismissHandler;
|
||||
use crate::common::Sizable as _;
|
||||
use crate::common::v_flex;
|
||||
|
||||
/// How alarming an [`Alert`] is; picks the icon and the accent color.
|
||||
@@ -28,6 +31,7 @@ pub enum AlertSeverity {
|
||||
|
||||
/// A static callout banner.
|
||||
#[derive(Clone, IntoElement)]
|
||||
#[must_use]
|
||||
pub struct Alert {
|
||||
id: ElementId,
|
||||
title: Option<SharedString>,
|
||||
@@ -129,7 +133,6 @@ impl RenderOnce for Alert {
|
||||
|
||||
let foreground = theme.colors.foreground;
|
||||
let muted_foreground = theme.colors.muted_foreground;
|
||||
let muted = theme.colors.muted;
|
||||
let surface = theme.colors.surface;
|
||||
|
||||
let border = if theme.borders.overlays {
|
||||
@@ -145,6 +148,8 @@ impl RenderOnce for Alert {
|
||||
let caption_size = metrics.caption_size;
|
||||
|
||||
div()
|
||||
.id(self.id.clone())
|
||||
.role(Role::Alert)
|
||||
.w_full()
|
||||
.flex()
|
||||
.items_start()
|
||||
@@ -197,18 +202,11 @@ impl RenderOnce for Alert {
|
||||
)
|
||||
.when_some(self.on_dismiss, |alert, on_dismiss| {
|
||||
alert.child(
|
||||
div()
|
||||
.id((self.id, "alert-close"))
|
||||
.flex_none()
|
||||
.cursor_pointer()
|
||||
.p_1()
|
||||
.rounded(theme.radius.sm)
|
||||
.hover(|style| style.bg(muted))
|
||||
.child(
|
||||
icon(IconRole::Close)
|
||||
.size(theme.sizes.small.dense_icon_size)
|
||||
.color(theme.colors.muted_foreground),
|
||||
)
|
||||
Button::new((self.id.clone(), "alert-close"))
|
||||
.icon(IconRole::Close)
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.small()
|
||||
.accessibility_label("Dismiss")
|
||||
.on_click(move |_, _window, cx| on_dismiss(cx)),
|
||||
)
|
||||
})
|
||||
@@ -240,7 +238,9 @@ impl Alerts {
|
||||
let stack = cx.entity().downgrade();
|
||||
|
||||
alert.on_dismiss = Some(Rc::new(move |cx: &mut App| {
|
||||
stack.update(cx, |alerts, cx| alerts.dismiss(id, cx)).ok();
|
||||
stack
|
||||
.update(cx, |alerts, cx| alerts.dismiss(id, cx))
|
||||
.log_err();
|
||||
}));
|
||||
|
||||
self.entries.push(AlertEntry {
|
||||
@@ -294,6 +294,7 @@ impl Alerts {
|
||||
|
||||
/// The floating stack of pushed alerts, topmost right.
|
||||
#[derive(IntoElement)]
|
||||
#[must_use]
|
||||
pub struct AlertsView {
|
||||
alerts: Entity<Alerts>,
|
||||
id: ElementId,
|
||||
@@ -341,7 +342,9 @@ impl RenderOnce for AlertsView {
|
||||
.with_animation(
|
||||
("alert-enter", id),
|
||||
Animation::new(enter_duration),
|
||||
move |layer, delta| layer.left(px(24. * (1. - ease_slide(delta)))),
|
||||
move |layer, delta| {
|
||||
layer.left(ENTER_SLIDE_DISTANCE * (1. - ease_slide(delta)))
|
||||
},
|
||||
)
|
||||
})),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user