use dioxus::prelude::*;
#[component]
pub fn ConfirmationDialog(
title: String,
message: String,
confirm_label: Option<String>,
cancel_label: Option<String>,
#[props(default = false)] danger: bool,
on_confirm: EventHandler<()>,
on_cancel: EventHandler<()>,
) -> Element {
let confirm_text = confirm_label.unwrap_or_else(|| "Confirm".to_string());
let cancel_text = cancel_label.unwrap_or_else(|| "Cancel".to_string());
let confirm_class = if danger {
"btn btn--danger"
} else {
"btn btn--primary"
};
rsx! {
div {
class: "confirmation-dialog",
div {
class: "confirmation-dialog__backdrop",
onclick: move |_| on_cancel.call(()),
}
div {
class: "confirmation-dialog__content",
h3 { class: "confirmation-dialog__title", "{title}" }
p { class: "confirmation-dialog__message", "{message}" }
div {
class: "confirmation-dialog__actions",
button {
class: "btn btn--secondary",
onclick: move |_| on_cancel.call(()),
"{cancel_text}"
}
button {
class: "{confirm_class}",
onclick: move |_| on_confirm.call(()),
"{confirm_text}"
}
}
}
}
}
}