yew_bootstrap/component/
alert.rs1use yew::prelude::*;
2
3use crate::util::Color;
4
5pub struct Alert {}
24
25#[derive(Properties, Clone, PartialEq)]
27pub struct AlertProps {
28 #[prop_or_default]
30 pub class: String,
31
32 #[prop_or_default]
34 pub children: Children,
35
36 #[prop_or(Color::Primary)]
38 pub style: Color,
39
40 #[prop_or_default]
42 pub text: String,
43}
44
45impl Component for Alert {
46 type Message = ();
47 type Properties = AlertProps;
48
49 fn create(_ctx: &Context<Self>) -> Self {
50 Self {}
51 }
52
53 fn view(&self, ctx: &Context<Self>) -> Html {
54 let props = ctx.props();
55 let mut classes = Classes::new();
56 classes.push("alert");
57 classes.push(format!("alert-{}", props.style));
58 classes.push(props.class.clone());
59
60 html! {
61 <div
62 class={classes}
63 role="alert"
64 >
65 { &props.text }
66 { for props.children.iter() }
67 </div>
68 }
69 }
70}