Skip to main content

impulse_thaw/toast/
toast_title.rs

1use leptos::{either::Either, prelude::*};
2use thaw_components::OptionComp;
3use thaw_utils::class_list;
4
5use crate::ToastIntent;
6
7#[component]
8pub fn ToastTitle(
9    #[prop(optional)] toast_title_media: Option<ToastTitleMedia>,
10    children: Children,
11    #[prop(optional)] toast_title_action: Option<ToastTitleAction>,
12) -> impl IntoView {
13    let intent: ToastIntent = expect_context();
14
15    view! {
16        <div class=class_list![
17            "thaw-toast-title__media", format!("thaw-toast-title__{:?}", intent).to_lowercase()
18        ]>
19            {if let Some(media) = toast_title_media {
20                Either::Left((media.children)())
21            } else {
22                {
23                    Either::Right(
24                        view! {
25                            <svg
26                                fill="currentColor"
27                                aria-hidden="true"
28                                width="1em"
29                                height="1em"
30                                viewBox="0 0 20 20"
31                            >
32                                {match intent {
33                                    ToastIntent::Info => {
34                                        view! {
35                                            <path
36                                                d="M18 10a8 8 0 1 0-16 0 8 8 0 0 0 16 0ZM9.5 8.91a.5.5 0 0 1 1 0V13.6a.5.5 0 0 1-1 0V8.9Zm-.25-2.16a.75.75 0 1 1 1.5 0 .75.75 0 0 1-1.5 0Z"
37                                                fill="currentColor"
38                                            ></path>
39                                        }
40                                            .into_any()
41                                    }
42                                    ToastIntent::Success => {
43                                        view! {
44                                            <path
45                                                d="M10 2a8 8 0 1 1 0 16 8 8 0 0 1 0-16Zm3.36 5.65a.5.5 0 0 0-.64-.06l-.07.06L9 11.3 7.35 9.65l-.07-.06a.5.5 0 0 0-.7.7l.07.07 2 2 .07.06c.17.11.4.11.56 0l.07-.06 4-4 .07-.08a.5.5 0 0 0-.06-.63Z"
46                                                fill="currentColor"
47                                            ></path>
48                                        }
49                                            .into_any()
50                                    }
51                                    ToastIntent::Warning => {
52                                        view! {
53                                            <path
54                                                d="M8.68 2.79a1.5 1.5 0 0 1 2.64 0l6.5 12A1.5 1.5 0 0 1 16.5 17h-13a1.5 1.5 0 0 1-1.32-2.21l6.5-12ZM10.5 7.5a.5.5 0 0 0-1 0v4a.5.5 0 0 0 1 0v-4Zm.25 6.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"
55                                                fill="currentColor"
56                                            ></path>
57                                        }
58                                            .into_any()
59                                    }
60                                    ToastIntent::Error => {
61                                        view! {
62                                            <path
63                                                d="M10 2a8 8 0 1 1 0 16 8 8 0 0 1 0-16ZM7.8 7.11a.5.5 0 0 0-.63.06l-.06.07a.5.5 0 0 0 .06.64L9.3 10l-2.12 2.12-.06.07a.5.5 0 0 0 .06.64l.07.06c.2.13.47.11.64-.06L10 10.7l2.12 2.12.07.06c.2.13.46.11.64-.06l.06-.07a.5.5 0 0 0-.06-.64L10.7 10l2.12-2.12.06-.07a.5.5 0 0 0-.06-.64l-.07-.06a.5.5 0 0 0-.64.06L10 9.3 7.88 7.17l-.07-.06Z"
64                                                fill="currentColor"
65                                            ></path>
66                                        }
67                                            .into_any()
68                                    }
69                                }}
70                            </svg>
71                        },
72                    )
73                }
74            }}
75        </div>
76        <div class="thaw-toast-title">{children()}</div>
77        <OptionComp value=toast_title_action let:action>
78            <div class="thaw-toast-title__action">{(action.children)()}</div>
79        </OptionComp>
80    }
81}
82
83#[slot]
84pub struct ToastTitleMedia {
85    children: Children,
86}
87
88#[slot]
89pub struct ToastTitleAction {
90    children: Children,
91}