zino_dioxus/feedback/message.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
use crate::class::Class;
use dioxus::prelude::*;
use zino_core::SharedString;
/// Contextual feedback messages for typical user actions.
pub fn Message(props: MessageProps) -> Element {
if props.hidden {
return rsx! {};
}
rsx! {
div {
class: props.class,
if !props.title.is_empty() {
div {
class: "message-header",
span { { props.title } }
button {
r#type: "button",
class: props.close_class,
onclick: move |_event| {
if let Some(handler) = props.on_close.as_ref() {
handler.call(false);
}
}
}
}
}
div {
class: "message-body",
{ props.children }
}
}
}
}
/// The [`Message`] properties struct for the configuration of the component.
#[derive(Clone, PartialEq, Props)]
pub struct MessageProps {
/// The class attribute for the component.
#[props(into, default = "message")]
pub class: Class,
/// A class to apply to the `close` button element.
#[props(into, default = "delete")]
pub close_class: Class,
/// An event handler to be called when the `close` button is clicked.
pub on_close: Option<EventHandler<bool>>,
/// A flag to determine whether the message is hidden or not.
#[props(default)]
pub hidden: bool,
/// The title in the message header.
#[props(into, default)]
pub title: SharedString,
/// The children to render within the component.
children: Element,
}