thaw/src/components/option_comp.rs

22 lines
445 B
Rust
Raw Normal View History

2023-05-15 12:52:03 +08:00
use leptos::*;
#[component]
2023-05-16 00:01:58 +08:00
pub fn OptionComp<T, VF, IV>(
cx: Scope,
value: Option<T>,
view: VF,
2023-05-16 12:54:47 +08:00
#[prop(optional)] children: Option<Children>,
2023-05-16 00:01:58 +08:00
) -> impl IntoView
2023-05-15 12:52:03 +08:00
where
2023-05-16 12:54:47 +08:00
VF: FnOnce(Scope, T) -> IV + 'static,
2023-05-15 12:52:03 +08:00
IV: IntoView,
{
if let Some(value) = value {
view(cx, value).into_view(cx)
2023-05-16 12:54:47 +08:00
} else if let Some(children) = children {
children(cx).into_view(cx)
2023-05-15 12:52:03 +08:00
} else {
().into_view(cx)
}
}