This commit is contained in:
2026-03-10 09:20:13 +07:00
parent 12a0e6db08
commit 2b2ff135ba
9 changed files with 238 additions and 45 deletions

View File

@@ -29,9 +29,13 @@ impl NotificationKind {
fn icon(&self, cx: &App) -> Icon {
match self {
Self::Info => Icon::new(IconName::Info).text_color(cx.theme().icon),
Self::Success => Icon::new(IconName::CheckCircle).text_color(cx.theme().icon_accent),
Self::Warning => Icon::new(IconName::Warning).text_color(cx.theme().warning_active),
Self::Error => Icon::new(IconName::CloseCircle).text_color(cx.theme().danger_active),
Self::Warning => Icon::new(IconName::Warning).text_color(cx.theme().warning_foreground),
Self::Success => {
Icon::new(IconName::CheckCircle).text_color(cx.theme().secondary_foreground)
}
Self::Error => {
Icon::new(IconName::CloseCircle).text_color(cx.theme().danger_foreground)
}
}
}
}
@@ -282,6 +286,9 @@ impl Styled for Notification {
}
impl Render for Notification {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let closing = self.closing;
let placement = cx.theme().notification.placement;
let content = self
.content_builder
.clone()
@@ -297,9 +304,15 @@ impl Render for Notification {
Some(kind) => Some(kind.icon(cx)),
};
let has_icon = icon.is_some();
let closing = self.closing;
let placement = cx.theme().notification.placement;
let background = match self.kind {
Some(NotificationKind::Error) => cx.theme().danger_background,
_ => cx.theme().surface_background,
};
let text_color = match self.kind {
Some(NotificationKind::Error) => cx.theme().danger_foreground,
_ => cx.theme().text,
};
h_flex()
.id("notification")
@@ -309,7 +322,8 @@ impl Render for Notification {
.w_112()
.border_1()
.border_color(cx.theme().border)
.bg(cx.theme().surface_background)
.bg(background)
.text_color(text_color)
.rounded(cx.theme().radius_lg)
.when(cx.theme().shadow, |this| this.shadow_md())
.p_2()
@@ -318,22 +332,23 @@ impl Render for Notification {
.items_start()
.refine_style(&self.style)
.when_some(icon, |this, icon| {
this.child(div().flex_shrink_0().pt_1().child(icon))
this.child(div().flex_shrink_0().pt(px(3.)).child(icon))
})
.child(
v_flex()
.flex_1()
.overflow_hidden()
.when(has_icon, |this| this.pl_1())
.when_some(self.title.clone(), |this, title| {
this.child(div().text_sm().font_semibold().child(title))
})
.when_some(self.message.clone(), |this, message| {
this.child(div().text_sm().child(message))
})
.when_some(content, |this, content| this.child(content)),
.when_some(content, |this, content| this.child(content))
.when_some(action, |this, action| {
this.child(h_flex().flex_1().gap_1().justify_end().child(action))
}),
)
.when_some(action, |this, action| this.child(action))
.child(
div()
.absolute()