thaw/thaw_components/src/option_comp.rs

22 lines
503 B
Rust
Raw Normal View History

2023-06-09 22:24:39 +08:00
use super::Fallback;
2024-07-01 10:52:57 +08:00
use leptos::{prelude::*, tachys::view::any_view::IntoAny};
2023-05-15 12:52:03 +08:00
#[component]
2023-06-09 22:24:39 +08:00
pub fn OptionComp<T, CF, IV>(
2023-05-16 00:01:58 +08:00
value: Option<T>,
2023-06-09 22:24:39 +08:00
children: CF,
#[prop(optional)] fallback: Option<Fallback>,
2023-05-16 00:01:58 +08:00
) -> impl IntoView
2023-05-15 12:52:03 +08:00
where
CF: FnOnce(T) -> IV + 'static,
2024-07-01 10:52:57 +08:00
IV: IntoView + 'static,
2023-05-15 12:52:03 +08:00
{
if let Some(value) = value {
2024-07-01 10:52:57 +08:00
children(value).into_any()
2023-06-09 22:24:39 +08:00
} else if let Some(fallback) = fallback {
2024-07-01 10:52:57 +08:00
(fallback.children)().into_any()
2023-05-15 12:52:03 +08:00
} else {
2024-07-01 10:52:57 +08:00
().into_any()
};
2023-05-15 12:52:03 +08:00
}