Show component is basically a less-versatile Rust bool.then()

This commit is contained in:
Greg Johnston 2022-08-01 19:29:35 -04:00
parent a9e4c16daa
commit a8cc450939
2 changed files with 0 additions and 33 deletions

View file

@ -1,9 +1,7 @@
mod for_component; mod for_component;
mod map; mod map;
mod show;
pub use for_component::*; pub use for_component::*;
pub use show::*;
pub trait Prop { pub trait Prop {
type Builder; type Builder;

View file

@ -1,31 +0,0 @@
use std::marker::PhantomData;
use crate as leptos;
use leptos_dom::{Child, Element, IntoChild};
use leptos_macro::*;
use leptos_reactive::{ReadSignal, Scope};
#[derive(Props)]
pub struct ShowProps<W, C>
where
W: Fn() -> bool,
C: for<'a> IntoChild<'a>,
{
when: W,
children: C,
}
#[allow(non_snake_case)]
pub fn Show<'a, W, C>(cx: Scope<'a>, props: ShowProps<W, C>) -> impl Fn() -> Child<'a>
where
W: Fn() -> bool,
C: for<'c> IntoChild<'c> + Clone,
{
move || {
if (props.when)() {
props.children.clone().into_child(cx)
} else {
Child::Null
}
}
}