2023-03-28 12:37:24 +08:00
|
|
|
use crate::card::*;
|
2023-06-10 12:40:52 +08:00
|
|
|
use crate::components::OptionComp;
|
2023-06-30 22:25:41 +08:00
|
|
|
use crate::icon::*;
|
2023-03-28 12:37:24 +08:00
|
|
|
use crate::teleport::*;
|
2023-03-30 17:12:58 +08:00
|
|
|
use crate::utils::mount_style::mount_style;
|
2023-03-28 12:37:24 +08:00
|
|
|
use leptos::*;
|
|
|
|
|
2023-06-10 12:40:52 +08:00
|
|
|
#[slot]
|
|
|
|
pub struct ModalFooter {
|
|
|
|
children: ChildrenFn,
|
|
|
|
}
|
|
|
|
|
2023-03-28 12:37:24 +08:00
|
|
|
#[component]
|
|
|
|
pub fn Modal(
|
2023-06-02 22:54:57 +08:00
|
|
|
#[prop(into)] show: RwSignal<bool>,
|
2023-06-10 12:40:52 +08:00
|
|
|
#[prop(optional, into)] title: MaybeSignal<&'static str>,
|
|
|
|
children: Children,
|
|
|
|
#[prop(optional)] modal_footer: Option<ModalFooter>,
|
2023-03-28 12:37:24 +08:00
|
|
|
) -> impl IntoView {
|
2023-10-07 21:41:03 +08:00
|
|
|
mount_style("modal", include_str!("./modal.css"));
|
2023-04-10 14:03:55 +08:00
|
|
|
|
2023-03-28 12:37:24 +08:00
|
|
|
view! {
|
|
|
|
<Teleport>
|
2023-06-02 22:54:57 +08:00
|
|
|
<div class="melt-modal-container" style=move || if show.get() { "" } else { "display: none" }>
|
2023-03-28 12:37:24 +08:00
|
|
|
<div class="melt-modal-mask"></div>
|
|
|
|
<div class="melt-modal-body">
|
2023-06-10 12:40:52 +08:00
|
|
|
<Card>
|
|
|
|
<CardHeader slot>
|
|
|
|
<span class="melt-model-title">
|
|
|
|
{ title.get() }
|
|
|
|
</span>
|
|
|
|
</CardHeader>
|
|
|
|
<CardHeaderExtra slot>
|
|
|
|
<span style="cursor: pointer;" on:click=move |_| show.set(false)>
|
2023-06-30 22:25:41 +08:00
|
|
|
<Icon icon=Icon::from(AiIcon::AiCloseOutlined)/>
|
2023-06-10 12:40:52 +08:00
|
|
|
</span>
|
|
|
|
</CardHeaderExtra>
|
2023-08-29 09:11:22 +08:00
|
|
|
{ children() }
|
2023-06-10 12:40:52 +08:00
|
|
|
<CardFooter slot if_=modal_footer.is_some()>
|
2023-10-02 17:04:03 +08:00
|
|
|
<OptionComp value=modal_footer.as_ref() let:footer>
|
2023-08-29 09:11:22 +08:00
|
|
|
{ (footer.children)() }
|
2023-06-10 12:40:52 +08:00
|
|
|
</OptionComp>
|
|
|
|
</CardFooter>
|
2023-03-28 12:37:24 +08:00
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Teleport>
|
|
|
|
}
|
|
|
|
}
|