leptos_use/docs/
boolean_display.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use leptos::*;

#[component]
pub fn BooleanDisplay(
    #[prop(into)] value: MaybeSignal<bool>,
    #[prop(optional, into)] class: String,
    #[prop(default = "true")] true_str: &'static str,
    #[prop(default = "false")] false_str: &'static str,
) -> impl IntoView {
    let true_class = "text-green-600 dark:text-green-500";
    let false_class = "text-[--brand-color]";

    let class = move || {
        format!(
            "{} {} opacity-75",
            if value.get() { true_class } else { false_class },
            class
        )
    };

    view! { <span class=class>{move || if value.get() { true_str } else { false_str }}</span> }
}