thaw/thaw_components/src/option_comp.rs

22 lines
497 B
Rust
Raw Normal View History

2023-06-09 22:24:39 +08:00
use super::Fallback;
2024-08-12 17:38:43 +08:00
use leptos::{either::EitherOf3, prelude::*};
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-08-12 17:38:43 +08:00
EitherOf3::A(children(value))
2023-06-09 22:24:39 +08:00
} else if let Some(fallback) = fallback {
2024-08-12 17:38:43 +08:00
EitherOf3::B((fallback.children)())
2023-05-15 12:52:03 +08:00
} else {
2024-08-12 17:38:43 +08:00
EitherOf3::C(())
2024-07-10 11:29:22 +08:00
}
2023-05-15 12:52:03 +08:00
}