#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ToastLevel {
Info,
Success,
Warning,
Error,
}
impl From<ToastLevel> for crate::style::SemanticColor {
fn from(level: ToastLevel) -> Self {
match level {
ToastLevel::Info => Self::Info,
ToastLevel::Success => Self::Success,
ToastLevel::Warning => Self::Warning,
ToastLevel::Error => Self::Error,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ToastItem {
pub id: String,
pub message: String,
pub level: ToastLevel,
pub ttl_ms: u32,
pub action_label: Option<String>,
}
impl ToastItem {
pub fn new(
id: impl Into<String>,
message: impl Into<String>,
level: ToastLevel,
ttl_ms: u32,
) -> Self {
Self {
id: id.into(),
message: message.into(),
level,
ttl_ms: ttl_ms.max(100),
action_label: None,
}
}
pub fn with_action(mut self, label: impl Into<String>) -> Self {
self.action_label = Some(label.into());
self
}
}