nova_forms/components/dialog.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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
use leptos::*;
use crate::Button;
/// The kind of dialog to display.
/// There are four kinds of dialogs: success, info, warn, and error.
#[derive(Copy, Clone, Debug)]
pub enum DialogKind {
Success,
Info,
Warn,
Error,
}
impl DialogKind {
pub fn class(&self) -> &'static str {
match self {
DialogKind::Success => "success",
DialogKind::Info => "info",
DialogKind::Warn => "warn",
DialogKind::Error => "error",
}
}
}
/// A dialog component.
#[component]
pub fn Dialog(
/// The kind of dialog to display.
kind: DialogKind,
/// Whether the dialog is open.
#[prop(into, optional, default=true.into())] open: MaybeSignal<bool>,
/// The callback to close the dialog.
#[prop(into, optional)] close: Option<Callback<(), ()>>,
/// The title of the dialog.
#[prop(into)] title: TextProp,
/// The message of the dialog.
#[prop(into)] msg: TextProp,
) -> impl IntoView {
view! {
<Show when=move || open.get()>
<div class="dialog">
<dialog
open=open.get()
class=kind.class()
>
<div class="dialog-header">{
let title = title.clone();
move || title.clone()
}</div>
<div class="dialog-main">{
let msg = msg.clone();
move || msg.clone()
}</div>
{
if let Some(close) = close {
view! {
<div class="dialog-footer">
<Button icon="close" label="Close" on:click=move |_ev| close.call(()) />
</div>
}.into_view()
} else {
View::default()
}
}
</dialog>
</div>
</Show>
}
}