2023-05-16 00:01:58 +08:00
|
|
|
use super::Fallback;
|
2024-06-14 09:55:49 +08:00
|
|
|
use leptos::prelude::*;
|
2023-05-16 00:01:58 +08:00
|
|
|
|
|
|
|
#[slot]
|
|
|
|
pub struct Then {
|
|
|
|
children: ChildrenFn,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[slot]
|
|
|
|
pub struct ElseIf {
|
|
|
|
cond: MaybeSignal<bool>,
|
|
|
|
children: ChildrenFn,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[component]
|
|
|
|
pub fn If(
|
2023-06-10 12:40:52 +08:00
|
|
|
#[prop(into)] cond: MaybeSignal<bool>,
|
2023-05-16 00:01:58 +08:00
|
|
|
then: Then,
|
|
|
|
#[prop(default=vec![])] else_if: Vec<ElseIf>,
|
|
|
|
#[prop(optional)] fallback: Option<Fallback>,
|
|
|
|
) -> impl IntoView {
|
|
|
|
move || {
|
|
|
|
if cond.get() {
|
2023-08-29 09:11:22 +08:00
|
|
|
(then.children)().into_view()
|
2023-05-16 00:01:58 +08:00
|
|
|
} else if let Some(else_if) = else_if.iter().find(|i| i.cond.get()) {
|
2023-08-29 09:11:22 +08:00
|
|
|
(else_if.children)().into_view()
|
2023-05-16 00:01:58 +08:00
|
|
|
} else if let Some(fallback) = &fallback {
|
2023-08-29 09:11:22 +08:00
|
|
|
(fallback.children)().into_view()
|
2023-05-16 00:01:58 +08:00
|
|
|
} else {
|
2023-08-29 09:11:22 +08:00
|
|
|
().into_view()
|
2023-05-16 00:01:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|