1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
use *;
use ;
use component_doc;
use inject_style;
use label_styles;
/// Label renders accessible caption text for a control or section heading.
///
/// Set `html_for` to associate a standalone control, or use [`Field`](crate::Field) when the label, required marker, and validation message belong together.
/// Size and weight adjust typographic hierarchy without changing semantic meaning.
/// Orbital does not use floating labels — labels stay outside the control boundary.
///
/// # When to use
///
/// - Standalone labels adjacent to custom controls - Section headings in dense forms when Field layout is not needed - Required-field indicators beside control labels
///
/// # Usage
///
/// 1. Wrap label text in the component children. 2. Set `required=true` when the paired control must have a value. 3. Set `disabled=true` when the labeled control is unavailable. 4. Use `size` and `weight` for typographic hierarchy (small captions vs large section titles).
///
/// # Best Practices
///
/// ## Do's
///
/// * Prefer [`Field`](crate::Field) when the label pairs with one input and validation * Set `required` when the field is mandatory — do not rely on color alone * Match `disabled` to the associated control state
///
/// ## Don'ts
///
/// * Do not use as the only accessible name for a control — associate via Field or `for` * Do not put `data-testid` on the component — wrap with a native element
///
/// # Examples
///
/// ## Default label
/// Baseline label typography for form fields and inline copy.
/// <!-- preview -->
/// ```rust
/// view! {
/// <div data-testid="label-preview">
/// <Label>"Display name"</Label>
/// </div>
/// }
/// ```
///
/// ## Required
/// Shows the required asterisk beside the label text.
/// <!-- preview -->
/// ```rust
/// view! {
/// <div data-testid="label-required">
/// <Label required=true>"Email"</Label>
/// </div>
/// }
/// ```
///
/// ## Sizes
/// Small, medium, and large type scales for captions, default fields, and section titles.
/// <!-- preview -->
/// ```rust
/// use crate::{Label, LabelSize};
/// view! {
/// <div data-testid="label-size-matrix">
/// <div data-testid="label-size-sm"><Label size=LabelSize::Small>"Small"</Label></div>
/// <div data-testid="label-size-md"><Label>"Medium"</Label></div>
/// <div data-testid="label-size-lg"><Label size=LabelSize::Large>"Large"</Label></div>
/// </div>
/// }
/// ```
///
/// ## Weights
/// Regular and semibold weights for emphasis without changing size.
/// <!-- preview -->
/// ```rust
/// use crate::{Label, LabelWeight};
/// view! {
/// <div data-testid="label-weight-matrix">
/// <Label weight=LabelWeight::Regular>"Regular"</Label>
/// <Label weight=LabelWeight::Semibold>"Semibold"</Label>
/// </div>
/// }
/// ```
///
/// ## Disabled
/// Muted label when the associated control is disabled.
/// <!-- preview -->
/// ```rust
/// view! {
/// <div data-testid="label-disabled">
/// <Label disabled=true>"Unavailable field"</Label>
/// </div>
/// }
/// ```