use silex_core::traits::{IntoRx, RxGet};
use silex_dom::prelude::*;
use silex_macros::component;
#[component]
pub fn Show<C>(
when: C,
#[prop(render)]
#[chain]
children: AnyView,
#[prop(render)]
#[chain(default = AnyView::Empty)]
fallback: AnyView,
) -> impl View
where
C: RxGet<Value = bool> + Clone + 'static,
{
silex_core::rx! {
if when.get() {
children.clone()
} else {
fallback.clone()
}
}
}
pub trait SignalShowExt: IntoRx<Value = bool> {
fn when<V>(self, view: V) -> ShowComponent<Self::RxType>
where
Self::RxType: RxGet<Value = bool> + Clone + 'static,
V: View + 'static;
}
impl<S> SignalShowExt for S
where
S: IntoRx<Value = bool>,
{
fn when<V>(self, view: V) -> ShowComponent<Self::RxType>
where
Self::RxType: RxGet<Value = bool> + Clone + 'static,
V: View + 'static,
{
Show(self.into_rx()).children(view)
}
}