Skip to main content

orbital_base_components/form/label/
base.rs

1use leptos::prelude::*;
2
3use crate::form::types::{LabelSize, LabelWeight};
4
5/// Headless native `<label>` — `for`, required marker, and modifier classes only.
6#[component(transparent)]
7pub fn BaseLabel(
8    #[prop(optional, into)] class: MaybeProp<String>,
9    #[prop(optional, into)] size: MaybeProp<String>,
10    #[prop(optional, into)] weight: MaybeProp<String>,
11    #[prop(optional, into)] label_size: Signal<LabelSize>,
12    #[prop(optional, into)] label_weight: Signal<LabelWeight>,
13    #[prop(optional, into)] required: Signal<bool>,
14    #[prop(optional, into)] disabled: Signal<bool>,
15    #[prop(optional, into)] attr_for: MaybeProp<String>,
16    children: Children,
17) -> impl IntoView {
18    let _ = (label_size, label_weight, disabled);
19    view! {
20        <label
21            class=move || {
22                let mut parts = Vec::new();
23                if let Some(c) = class.get() {
24                    if !c.is_empty() {
25                        parts.push(c);
26                    }
27                }
28                if let Some(c) = size.get() {
29                    if !c.is_empty() {
30                        parts.push(c);
31                    }
32                }
33                if let Some(c) = weight.get() {
34                    if !c.is_empty() {
35                        parts.push(c);
36                    }
37                }
38                parts.join(" ")
39            }
40            for=move || attr_for.get()
41        >
42            {children()}
43            {move || required.get().then(|| view! { <span aria-hidden="true">"*"</span> })}
44        </label>
45    }
46}