impulse_thaw/label/
label.rs1use leptos::prelude::*;
2use thaw_components::{If, Then};
3use thaw_utils::{class_list, mount_style};
4
5#[component]
6pub fn Label(
7 #[prop(optional, into)] class: MaybeProp<String>,
8 #[prop(optional, into)]
10 size: Signal<LabelSize>,
11 #[prop(optional, into)]
13 weight: Signal<LabelWeight>,
14 #[prop(optional, into)]
16 required: Signal<bool>,
17 #[prop(optional, into)]
19 disabled: Signal<bool>,
20 children: Children,
21) -> impl IntoView {
22 mount_style("label", include_str!("./label.css"));
23
24 view! {
25 <label class=class_list![
26 "thaw-label",
27 ("thaw-label--disabled", move || disabled.get()),
28 move || format!("thaw-label--{}", size.get().as_str()),
29 move || format!("thaw-label--{}", weight.get().as_str()),
30 class
31 ]>
32 {children()} <If cond=required>
33 <Then slot>
34 <span aria-hidden="true" class="thaw-label__required">
35 "*"
36 </span>
37 </Then>
38 </If>
39 </label>
40 }
41}
42
43#[derive(Debug, Default, Clone)]
44pub enum LabelSize {
45 Small,
46 #[default]
47 Medium,
48 Large,
49}
50
51impl LabelSize {
52 pub fn as_str(&self) -> &'static str {
53 match self {
54 Self::Small => "small",
55 Self::Medium => "medium",
56 Self::Large => "large",
57 }
58 }
59}
60
61#[derive(Debug, Default, Clone)]
62pub enum LabelWeight {
63 #[default]
64 Regular,
65 Semibold,
66}
67
68impl LabelWeight {
69 pub fn as_str(&self) -> &'static str {
70 match self {
71 Self::Regular => "regular",
72 Self::Semibold => "semibold",
73 }
74 }
75}