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
|
2024-01-31 20:13:26 +08:00
|
|
|
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
|
|
|
}
|