use crate::class::Class;
use dioxus::prelude::*;
use zino_core::SharedString;
pub fn ModalCard(props: ModalCardProps) -> Element {
let mut visible = props.visible;
let size = props.size.as_ref();
let width = match size {
"small" => "25rem",
"medium" => "50rem",
"large" => "75rem",
_ => {
if matches!(size, "default" | "") {
"40rem"
} else {
size
}
}
};
rsx! {
div {
class: "{props.class}",
class: if visible() { "{props.active_class}" },
style: "--bulma-modal-content-width:{width}",
div { class: "modal-background" }
div {
class: "modal-card",
header {
class: "modal-card-head",
div {
class: "modal-card-title {props.title_class}",
{ props.title }
}
button {
r#type: "button",
class: props.close_class,
onclick: move |event| {
visible.set(false);
if let Some(handler) = props.on_close.as_ref() {
handler.call(event);
}
}
}
}
section {
class: "modal-card-body",
{ props.children }
}
}
}
}
}
#[derive(Clone, PartialEq, Props)]
pub struct ModalCardProps {
#[props(into, default = "modal")]
pub class: Class,
#[props(into, default = "is-active")]
pub active_class: Class,
#[props(into, default)]
pub title_class: Class,
#[props(into, default = "delete")]
pub close_class: Class,
pub visible: Signal<bool>,
#[props(into, default)]
pub size: SharedString,
#[props(into)]
pub title: SharedString,
pub on_close: Option<EventHandler<MouseEvent>>,
children: Element,
}
#[derive(Clone, Default, PartialEq)]
pub struct ModalData<T> {
id: Option<T>,
name: SharedString,
title: SharedString,
visible: bool,
}
impl<T> ModalData<T> {
#[inline]
pub fn new(title: impl Into<SharedString>) -> Self {
Self {
id: None,
name: "modal".into(),
title: title.into(),
visible: false,
}
}
#[inline]
pub fn set_id(&mut self, id: T) {
self.id = Some(id);
}
#[inline]
pub fn set_name(&mut self, name: impl Into<SharedString>) {
self.name = name.into();
}
#[inline]
pub fn set_title(&mut self, title: impl Into<SharedString>) {
self.title = title.into();
}
#[inline]
pub fn set_visible(&mut self, visible: bool) {
self.visible = visible;
}
#[inline]
pub fn id(&self) -> Option<&T> {
self.id.as_ref()
}
#[inline]
pub fn name(&self) -> &str {
self.name.as_ref()
}
#[inline]
pub fn title(&self) -> String {
self.title.as_ref().to_owned()
}
#[inline]
pub fn visible(&self) -> bool {
self.visible
}
}