mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
Show component is basically a less-versatile Rust bool.then()
This commit is contained in:
parent
a9e4c16daa
commit
a8cc450939
2 changed files with 0 additions and 33 deletions
|
@ -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;
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue