ui: Make Callout constructors more flexible (#29895)

This PR updates the `Callout` constructors to be more flexible by
accepting `impl Into<SharedString>`s.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-05-04 21:18:48 -04:00 committed by GitHub
parent a2fa10f35f
commit 3e2abbf53b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 22 deletions

View file

@ -1,6 +1,7 @@
use crate::prelude::*;
use gpui::ClickEvent;
use crate::prelude::*;
#[derive(IntoElement, RegisterComponent)]
pub struct Callout {
title: SharedString,
@ -13,33 +14,33 @@ pub struct Callout {
impl Callout {
pub fn single_line(
title: SharedString,
title: impl Into<SharedString>,
icon: Icon,
cta_label: SharedString,
cta_label: impl Into<SharedString>,
cta_action: Box<dyn Fn(&ClickEvent, &mut Window, &mut App) + 'static>,
) -> Self {
Self {
title,
title: title.into(),
message: None,
icon,
cta_label,
cta_label: cta_label.into(),
cta_action,
line_height: None,
}
}
pub fn multi_line(
title: SharedString,
message: SharedString,
title: impl Into<SharedString>,
message: impl Into<SharedString>,
icon: Icon,
cta_label: SharedString,
cta_label: impl Into<SharedString>,
cta_action: Box<dyn Fn(&ClickEvent, &mut Window, &mut App) + 'static>,
) -> Self {
Self {
title,
message: Some(message),
title: title.into(),
message: Some(message.into()),
icon,
cta_label,
cta_label: cta_label.into(),
cta_action,
line_height: None,
}
@ -127,11 +128,11 @@ impl Component for Callout {
single_example(
"Single Line",
Callout::single_line(
"Your settings contain deprecated values, please update them.".into(),
"Your settings contain deprecated values, please update them.",
Icon::new(IconName::Warning)
.color(Color::Warning)
.size(IconSize::Small),
"Backup & Update".into(),
"Backup & Update",
Box::new(|_, _, _| {}),
)
.into_any_element(),
@ -140,12 +141,12 @@ impl Component for Callout {
single_example(
"Multi Line",
Callout::multi_line(
"Thread reached the token limit".into(),
"Start a new thread from a summary to continue the conversation.".into(),
"Thread reached the token limit",
"Start a new thread from a summary to continue the conversation.",
Icon::new(IconName::X)
.color(Color::Error)
.size(IconSize::Small),
"Start New Thread".into(),
"Start New Thread",
Box::new(|_, _, _| {}),
)
.into_any_element(),