Skip to main content

basecoat_core/classes/
alert.rs

1use crate::props::alert::{AlertProps, AlertVariant};
2
3/// Returns the canonical CSS class string for an alert.
4///
5/// Upstream: `.alert` or `.alert-destructive`.
6pub fn alert(p: &AlertProps) -> String {
7    let base = match p.variant {
8        AlertVariant::Default => "alert",
9        AlertVariant::Destructive => "alert-destructive",
10    };
11
12    match &p.class {
13        Some(extra) if !extra.is_empty() => format!("{base} {extra}"),
14        _ => base.to_string(),
15    }
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21    use crate::props::alert::{AlertProps, AlertVariant};
22
23    #[test]
24    fn default_variant() {
25        assert_eq!(alert(&AlertProps::default()), "alert");
26    }
27
28    #[test]
29    fn destructive_variant() {
30        let p = AlertProps {
31            variant: AlertVariant::Destructive,
32            ..Default::default()
33        };
34        assert_eq!(alert(&p), "alert-destructive");
35    }
36}