bootstrap-rs/src/alert/mod.rs

55 lines
1.3 KiB
Rust
Raw Normal View History

2020-10-17 18:04:26 +00:00
mod bus;
2020-06-21 15:57:50 +00:00
mod props;
2020-10-17 18:04:26 +00:00
mod sub;
2020-06-20 16:03:49 +00:00
2020-06-21 15:57:50 +00:00
use self::props::Props;
use crate::{prelude::*, render};
2020-10-17 18:04:26 +00:00
pub use bus::{Bus, Request};
pub use sub::AlertSubscriber;
2020-06-21 15:57:50 +00:00
use yew::prelude::*;
2020-06-20 16:03:49 +00:00
pub struct Alert {
link: ComponentLink<Self>,
props: Props,
}
impl Component for Alert {
type Properties = Props;
type Message = ();
fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {
Self { link, props }
}
fn update(&mut self, _: Self::Message) -> ShouldRender {
self.props.on_close.emit(());
true
}
fn change(&mut self, props: Self::Properties) -> ShouldRender {
render_if_ne(&mut self.props, props)
2020-06-20 16:03:49 +00:00
}
fn view(&self) -> Html {
2020-06-21 15:57:50 +00:00
let html = html! {
<div>
2020-07-22 20:50:09 +00:00
{ self.props.children.clone() }
2020-06-20 16:03:49 +00:00
<button
type="button"
class="close"
data-dismiss="alert"
aria-label="Close"
onclick=self.link.callback(|_| ())
>
<span aria-hidden="true">{ "×" }</span>
</button>
</div>
2020-06-21 15:57:50 +00:00
};
render::render_with_prefix(
&self.props,
vec!["alert", &self.props.color.with_prefix("alert")],
html,
)
2020-06-20 16:03:49 +00:00
}
}