Skip to main content

basecoat_core/classes/
dialog.rs

1use crate::props::dialog::DialogProps;
2
3/// Returns the canonical CSS class string for a dialog.
4///
5/// Upstream: `.dialog` class on the `<dialog>` element.
6pub fn dialog(p: &DialogProps) -> String {
7    match &p.class {
8        Some(extra) if !extra.is_empty() => format!("dialog {extra}"),
9        _ => "dialog".to_string(),
10    }
11}
12
13#[cfg(test)]
14mod tests {
15    use super::*;
16    use crate::props::dialog::DialogProps;
17
18    #[test]
19    fn base_class() {
20        assert_eq!(dialog(&DialogProps::default()), "dialog");
21    }
22
23    #[test]
24    fn with_extra_class() {
25        let p = DialogProps {
26            class: Some("max-w-lg".into()),
27            ..Default::default()
28        };
29        assert_eq!(dialog(&p), "dialog max-w-lg");
30    }
31}