Skip to main content

basecoat_core/props/
toast.rs

1use crate::{AttrMap, BasecoatProps};
2use std::borrow::Cow;
3
4/// Toast category — maps to `data-category` attribute.
5/// Determines icon and ARIA role in upstream basecoat.
6#[derive(Clone, Debug, PartialEq, Eq, Default)]
7pub enum ToastCategory {
8    #[default]
9    Success,
10    Error,
11    Info,
12    Warning,
13}
14
15impl std::fmt::Display for ToastCategory {
16    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17        let s = match self {
18            ToastCategory::Success => "success",
19            ToastCategory::Error => "error",
20            ToastCategory::Info => "info",
21            ToastCategory::Warning => "warning",
22        };
23        f.write_str(s)
24    }
25}
26
27/// Props for a single toast message.
28#[derive(BasecoatProps, Default, Clone, Debug)]
29pub struct ToastProps {
30    #[prop(default)]
31    pub category: ToastCategory,
32    #[prop(optional, into)]
33    pub title: Option<Cow<'static, str>>,
34    #[prop(optional, into)]
35    pub description: Option<Cow<'static, str>>,
36    #[prop(optional, into)]
37    pub class: Option<Cow<'static, str>>,
38    #[prop(extend)]
39    pub attrs: AttrMap,
40}
41
42/// Props for the toaster container that holds multiple toasts.
43#[derive(BasecoatProps, Default, Clone, Debug)]
44pub struct ToasterProps {
45    #[prop(default = Cow::Borrowed("toaster"))]
46    pub id: Cow<'static, str>,
47    #[prop(optional, into)]
48    pub class: Option<Cow<'static, str>>,
49    #[prop(extend)]
50    pub attrs: AttrMap,
51}