leptos_bootstrap/v5/
alert.rs1use leptos::prelude::*;
2use std::fmt;
3
4pub enum AlertKind {
5 Primary,
6 Secondary,
7 Success,
8 Danger,
9 Warning,
10 Info,
11 Light,
12 Dark,
13 Link,
14}
15
16impl fmt::Display for AlertKind {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 let s = match self {
19 Self::Primary => "alert-primary",
20 Self::Secondary => "alert-secondary",
21 Self::Success => "alert-success",
22 Self::Danger => "alert-danger",
23 Self::Warning => "alert-warning",
24 Self::Info => "alert-info",
25 Self::Light => "alert-light",
26 Self::Dark => "alert-dark",
27 Self::Link => "alert-link",
28 };
29 write!(f, "{}", s)
30 }
31}
32
33#[component]
34pub fn Alert<'a>(
35 #[prop(default = AlertKind::Primary)] kind: AlertKind,
36 #[prop(optional, into)] class: &'a str,
37 children: Children,
38) -> impl IntoView {
39 let class = format!("alert {} {}", kind, class);
40 view! {
41 <div class=class role="alert">
42 {children()}
43 </div>
44 }
45}
46
47#[component]
48pub fn AlertHeader<'a>(
49 #[prop(optional, into)] class: &'a str,
50 children: Children,
51) -> impl IntoView {
52 let class = format!("alert-heading {}", class);
53 view! { <h4 class=class>{children()}</h4> }
54}