ochreui 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +153 -2
  3. package/cli/ochreui.mjs +601 -0
  4. package/mcp/core.mjs +126 -0
  5. package/mcp/docs.json +906 -0
  6. package/mcp/server.mjs +23 -0
  7. package/package.json +393 -3
  8. package/registry/agent-team.ts +350 -0
  9. package/registry/avatar.ts +300 -0
  10. package/registry/badge.ts +207 -0
  11. package/registry/breadcrumb.ts +435 -0
  12. package/registry/button.ts +238 -0
  13. package/registry/card.ts +221 -0
  14. package/registry/change-summary.ts +200 -0
  15. package/registry/checkbox.ts +204 -0
  16. package/registry/code-block.ts +332 -0
  17. package/registry/color-picker.ts +720 -0
  18. package/registry/comment-thread.ts +503 -0
  19. package/registry/context-menu.ts +281 -0
  20. package/registry/cover-flow.ts +623 -0
  21. package/registry/date-picker.ts +799 -0
  22. package/registry/decision-inbox.ts +340 -0
  23. package/registry/dialog.ts +577 -0
  24. package/registry/dropdown-menu.ts +864 -0
  25. package/registry/email-draft.ts +916 -0
  26. package/registry/empty-calendar.ts +199 -0
  27. package/registry/empty-state.ts +164 -0
  28. package/registry/enrichment-orbit.ts +164 -0
  29. package/registry/filter-menu.ts +541 -0
  30. package/registry/form-field.ts +308 -0
  31. package/registry/frost-cloud.ts +381 -0
  32. package/registry/ghosted-chat.ts +210 -0
  33. package/registry/glow-cloud.ts +402 -0
  34. package/registry/grid-background.ts +164 -0
  35. package/registry/hover-card.ts +401 -0
  36. package/registry/icon-button.ts +133 -0
  37. package/registry/index.json +2124 -0
  38. package/registry/integration-beam.ts +588 -0
  39. package/registry/integration-grid.ts +209 -0
  40. package/registry/kbd.ts +176 -0
  41. package/registry/layer-stack.ts +351 -0
  42. package/registry/lead-sourcing.ts +285 -0
  43. package/registry/logo-cluster.ts +239 -0
  44. package/registry/logo-marquee.ts +505 -0
  45. package/registry/message-actions.ts +833 -0
  46. package/registry/model-orbit.ts +583 -0
  47. package/registry/model-wheel.ts +372 -0
  48. package/registry/notification-stack.ts +301 -0
  49. package/registry/number-input.ts +552 -0
  50. package/registry/number-ticker.ts +261 -0
  51. package/registry/ochre.css +917 -0
  52. package/registry/otp-input.ts +704 -0
  53. package/registry/overlay.ts +312 -0
  54. package/registry/pagination.ts +362 -0
  55. package/registry/popover.ts +296 -0
  56. package/registry/profile-menu.ts +332 -0
  57. package/registry/progress-tracker.ts +291 -0
  58. package/registry/rating.ts +461 -0
  59. package/registry/reaction-bar.ts +322 -0
  60. package/registry/region-map.ts +537 -0
  61. package/registry/resizable.ts +489 -0
  62. package/registry/scroll-area.ts +271 -0
  63. package/registry/segmented-control.ts +433 -0
  64. package/registry/select.ts +769 -0
  65. package/registry/separator.ts +97 -0
  66. package/registry/shimmer-loader.ts +211 -0
  67. package/registry/side-folder.ts +152 -0
  68. package/registry/skeleton.ts +136 -0
  69. package/registry/skill/INSTRUCTIONS.md +11 -0
  70. package/registry/skill/SKILL.md +65 -0
  71. package/registry/skill/checklist.md +45 -0
  72. package/registry/skill/references/agent-team.md +105 -0
  73. package/registry/skill/references/avatar.md +88 -0
  74. package/registry/skill/references/badge.md +92 -0
  75. package/registry/skill/references/breadcrumb.md +99 -0
  76. package/registry/skill/references/button.md +82 -0
  77. package/registry/skill/references/card.md +111 -0
  78. package/registry/skill/references/catalog.md +114 -0
  79. package/registry/skill/references/change-summary.md +103 -0
  80. package/registry/skill/references/checkbox.md +105 -0
  81. package/registry/skill/references/code-block.md +109 -0
  82. package/registry/skill/references/color-picker.md +138 -0
  83. package/registry/skill/references/comment-thread.md +164 -0
  84. package/registry/skill/references/context-menu.md +205 -0
  85. package/registry/skill/references/cover-flow.md +128 -0
  86. package/registry/skill/references/date-picker.md +154 -0
  87. package/registry/skill/references/decision-inbox.md +126 -0
  88. package/registry/skill/references/dialog.md +155 -0
  89. package/registry/skill/references/dropdown-menu.md +144 -0
  90. package/registry/skill/references/email-draft.md +182 -0
  91. package/registry/skill/references/empty-calendar.md +74 -0
  92. package/registry/skill/references/empty-state.md +118 -0
  93. package/registry/skill/references/enrichment-orbit.md +71 -0
  94. package/registry/skill/references/filter-menu.md +143 -0
  95. package/registry/skill/references/form-field.md +118 -0
  96. package/registry/skill/references/frost-cloud.md +80 -0
  97. package/registry/skill/references/ghosted-chat.md +75 -0
  98. package/registry/skill/references/glow-cloud.md +84 -0
  99. package/registry/skill/references/grid-background.md +76 -0
  100. package/registry/skill/references/hover-card.md +125 -0
  101. package/registry/skill/references/icon-button.md +99 -0
  102. package/registry/skill/references/integration-beam.md +107 -0
  103. package/registry/skill/references/integration-grid.md +100 -0
  104. package/registry/skill/references/kbd.md +65 -0
  105. package/registry/skill/references/layer-stack.md +115 -0
  106. package/registry/skill/references/lead-sourcing.md +92 -0
  107. package/registry/skill/references/logo-cluster.md +92 -0
  108. package/registry/skill/references/logo-marquee.md +123 -0
  109. package/registry/skill/references/message-actions.md +146 -0
  110. package/registry/skill/references/model-orbit.md +106 -0
  111. package/registry/skill/references/model-wheel.md +84 -0
  112. package/registry/skill/references/notification-stack.md +138 -0
  113. package/registry/skill/references/number-input.md +117 -0
  114. package/registry/skill/references/number-ticker.md +73 -0
  115. package/registry/skill/references/otp-input.md +142 -0
  116. package/registry/skill/references/pagination.md +112 -0
  117. package/registry/skill/references/popover.md +143 -0
  118. package/registry/skill/references/profile-menu.md +123 -0
  119. package/registry/skill/references/progress-tracker.md +122 -0
  120. package/registry/skill/references/rating.md +111 -0
  121. package/registry/skill/references/reaction-bar.md +128 -0
  122. package/registry/skill/references/region-map.md +109 -0
  123. package/registry/skill/references/resizable.md +127 -0
  124. package/registry/skill/references/scroll-area.md +113 -0
  125. package/registry/skill/references/segmented-control.md +96 -0
  126. package/registry/skill/references/select.md +122 -0
  127. package/registry/skill/references/separator.md +69 -0
  128. package/registry/skill/references/shimmer-loader.md +83 -0
  129. package/registry/skill/references/side-folder.md +75 -0
  130. package/registry/skill/references/skeleton.md +95 -0
  131. package/registry/skill/references/smart-recommendation.md +132 -0
  132. package/registry/skill/references/spinner.md +84 -0
  133. package/registry/skill/references/switch.md +79 -0
  134. package/registry/skill/references/tab-overload.md +70 -0
  135. package/registry/skill/references/tag-input.md +126 -0
  136. package/registry/skill/references/team-invite.md +94 -0
  137. package/registry/skill/references/testimonial-wall.md +110 -0
  138. package/registry/skill/references/text-area.md +115 -0
  139. package/registry/skill/references/text-field.md +126 -0
  140. package/registry/skill/references/text-reveal.md +71 -0
  141. package/registry/skill/references/thinking-loader.md +87 -0
  142. package/registry/skill/references/time-picker.md +122 -0
  143. package/registry/skill/references/tips-panel.md +115 -0
  144. package/registry/skill/references/toggle-group.md +98 -0
  145. package/registry/skill/references/tool-call-card.md +151 -0
  146. package/registry/skill/references/tooltip.md +94 -0
  147. package/registry/skill/references/tree-view.md +172 -0
  148. package/registry/skill/theming.md +57 -0
  149. package/registry/smart-recommendation.ts +415 -0
  150. package/registry/spinner.ts +67 -0
  151. package/registry/switch.ts +146 -0
  152. package/registry/tab-overload.ts +211 -0
  153. package/registry/tag-input.ts +620 -0
  154. package/registry/team-invite.ts +248 -0
  155. package/registry/testimonial-wall.ts +521 -0
  156. package/registry/text-area.ts +432 -0
  157. package/registry/text-field.ts +415 -0
  158. package/registry/text-reveal.ts +175 -0
  159. package/registry/theme.ts +68 -0
  160. package/registry/thinking-loader.ts +302 -0
  161. package/registry/time-picker.ts +828 -0
  162. package/registry/tips-panel.ts +312 -0
  163. package/registry/toggle-group.ts +357 -0
  164. package/registry/tool-call-card.ts +578 -0
  165. package/registry/tooltip.ts +486 -0
  166. package/registry/tree-view.ts +454 -0
  167. package/styles/base.css +500 -0
  168. package/styles/tokens.css +415 -0
@@ -0,0 +1,308 @@
1
+ // Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
2
+ /**
3
+ * Form Field, from Ochre (https://ochreui.dev).
4
+ * Needs ochre.css (the --ui-* tokens and the .ui-icon and .ui-sr classes), which `npx ochreui init` adds once.
5
+ *
6
+ * <ui-form-field label="Region" hint="Where the runs execute."><select uiFieldControl [formField]="form.region">…</select></ui-form-field>
7
+ * Label, required mark or "Optional", and a hint, error or count line for any control without its own.
8
+ * Native inputs, selects and textareas get the Text Field look; others are named with aria-labelledby.
9
+ *
10
+ * Public styling hooks (set them on the element or any ancestor):
11
+ * --ui-form-field-gap space between the label, the control and the line under it (default 6px; Classic 7px)
12
+ * --ui-form-field-required color of the required mark (default: muted text)
13
+ * --ui-text-field-edge resting edge of native controls, shared with Text Field
14
+ * --ui-text-field-edge-hover edge on hover
15
+ * --ui-text-field-edge-focus edge while focused (default: the input border, 3:1 or more)
16
+ * --ui-text-field-radius corners (default 7px; Classic 10px)
17
+ */
18
+ import {
19
+ Component,
20
+ DOCUMENT,
21
+ DestroyRef,
22
+ Directive,
23
+ ElementRef,
24
+ afterNextRender,
25
+ afterRenderEffect,
26
+ booleanAttribute,
27
+ computed,
28
+ contentChildren,
29
+ inject,
30
+ input,
31
+ isDevMode,
32
+ signal,
33
+ viewChild,
34
+ } from '@angular/core';
35
+
36
+ export type FormFieldSize = 'sm' | 'md' | 'lg';
37
+
38
+ export interface FormFieldLabels {
39
+ optional: string;
40
+ required: string;
41
+ }
42
+
43
+ const LABELS: FormFieldLabels = { optional: 'Optional', required: '*' };
44
+ const LABELABLE = /^(INPUT|SELECT|TEXTAREA|BUTTON|METER|OUTPUT|PROGRESS)$/;
45
+ const UNSTYLED = /^(checkbox|radio|range|color|file|hidden|button|submit|reset|image)$/;
46
+
47
+ let nextId = 0;
48
+
49
+ /** Put it on the control inside a `<ui-form-field>`: a native input, select or textarea, or any custom control. */
50
+ @Directive({
51
+ selector: '[uiFieldControl]',
52
+ host: {
53
+ '[id]': 'id',
54
+ '[attr.aria-describedby]': 'describedBy()',
55
+ '[attr.aria-labelledby]': 'labelledBy()',
56
+ '[class.ui-fc]': 'styled()',
57
+ },
58
+ })
59
+ export class UiFieldControl {
60
+ /** Your own descriptions, kept alongside the field's. Set it as `aria-describedby="…"`, not `[attr.aria-describedby]`. */
61
+ readonly ariaDescribedby = input<string>(undefined, { alias: 'aria-describedby' });
62
+
63
+ readonly el = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
64
+ protected readonly field = inject(UiFormField, { optional: true });
65
+ readonly id = this.el.getAttribute('id') || `ui-form-field-${nextId++}`;
66
+ readonly labelable = LABELABLE.test(this.el.tagName);
67
+ readonly select = this.el.tagName === 'SELECT' && !this.el.hasAttribute('multiple') && !(Number(this.el.getAttribute('size')) > 1);
68
+ private readonly named = this.el.hasAttribute('aria-label') || this.el.hasAttribute('aria-labelledby');
69
+ private readonly mine = new Set<string>();
70
+
71
+ readonly disabled = signal(false);
72
+ readonly required = signal(false);
73
+ protected readonly styled = signal(this.native());
74
+
75
+ protected readonly describedBy = computed(
76
+ () => [this.ariaDescribedby(), ...(this.field?.describers() ?? [])].filter(Boolean).join(' ') || null,
77
+ );
78
+ protected readonly labelledBy = computed(() => {
79
+ const f = this.field;
80
+ return f && f.label() && !this.labelable && !this.named && f.control() === this ? f.labelId : null;
81
+ });
82
+
83
+ constructor() {
84
+ const el = this.el;
85
+ if (this.styled() && el.tagName !== 'SELECT' && !el.hasAttribute('dir')) el.setAttribute('dir', 'auto');
86
+ if (isDevMode() && !this.field) console.warn('uiFieldControl: put it inside a <ui-form-field>.', el);
87
+ afterRenderEffect(() => {
88
+ this.mark('aria-invalid', !!this.field?.invalid());
89
+ this.mark('aria-required', !!this.field?.required());
90
+ });
91
+ const destroy = inject(DestroyRef);
92
+ afterNextRender(() => {
93
+ this.read();
94
+ const view = el.ownerDocument.defaultView;
95
+ if (!view?.MutationObserver) return;
96
+ const watch = new view.MutationObserver(() => this.read());
97
+ watch.observe(el, { attributes: true, attributeFilter: ['disabled', 'required', 'type', 'aria-disabled', 'aria-required'] });
98
+ destroy.onDestroy(() => watch.disconnect());
99
+ });
100
+ }
101
+
102
+ read() {
103
+ const el = this.el as HTMLElement & { disabled?: boolean; required?: boolean };
104
+ this.disabled.set(!!el.disabled || el.getAttribute('aria-disabled') === 'true');
105
+ this.required.set(!!el.required || (el.getAttribute('aria-required') === 'true' && !this.mine.has('aria-required')));
106
+ this.styled.set(this.native());
107
+ }
108
+
109
+ private native() {
110
+ const el = this.el;
111
+ return /^(SELECT|TEXTAREA)$/.test(el.tagName) || (el.tagName === 'INPUT' && !UNSTYLED.test((el as HTMLInputElement).type));
112
+ }
113
+
114
+ /** Sets an ARIA state only where the control has none of its own, and removes only what it set. */
115
+ private mark(name: string, on: boolean) {
116
+ if (on && !this.el.hasAttribute(name)) {
117
+ this.mine.add(name);
118
+ this.el.setAttribute(name, 'true');
119
+ } else if (!on && this.mine.delete(name)) {
120
+ this.el.removeAttribute(name);
121
+ }
122
+ }
123
+ }
124
+
125
+ const space = (n: string) => `var(--ui-space-${n})`;
126
+ const SIZES: Record<FormFieldSize, Record<string, string>> = {
127
+ sm: { '--_h0': 'var(--ui-control-h-sm)', '--_ht': `calc(${space('8')} + ${space('0-5')})` },
128
+ md: { '--_h0': 'var(--ui-control-h-md)', '--_ht': `calc(${space('8')} + ${space('1-5')})` },
129
+ lg: { '--_h0': `calc(var(--ui-control-h-md) + ${space('1')})`, '--_ht': `calc(${space('10')} + ${space('0-5')})` },
130
+ };
131
+
132
+ @Component({
133
+ selector: 'ui-form-field',
134
+ exportAs: 'uiFormField',
135
+ host: {
136
+ '[attr.data-size]': 'size()',
137
+ '[attr.data-invalid]': 'invalid() || null',
138
+ '[attr.data-disabled]': 'control()?.disabled() || null',
139
+ '[style]': 'sizes[size()]',
140
+ },
141
+ template: `
142
+ @if (label()) {
143
+ <div class="top">
144
+ <label [id]="labelId" [attr.for]="labelable() ? controlId() : null" (click)="focusControl()">{{ label() }}@if (isRequired()) {<span class="req" aria-hidden="true">{{ t().required }}</span>}@if (optional()) {<span class="ui-sr"> ({{ t().optional }})</span>}</label>
145
+ @if (optional()) {<span class="opt" aria-hidden="true">{{ t().optional }}</span>}
146
+ </div>
147
+ }
148
+ <div class="ctl">
149
+ <ng-content />
150
+ @if (control()?.select) {<svg class="ui-icon chev" viewBox="0 0 16 16" aria-hidden="true"><path d="M5.5 7 8 9.5 10.5 7" /></svg>}
151
+ </div>
152
+ <div class="foot" [class.ui-sr]="!message() && !counter() && !(error() === true && hint())">
153
+ <p #msg [id]="messageId" dir="auto" aria-live="polite">{{ message() }}</p>
154
+ @if (counter()) {<span class="count" [id]="countId">{{ counter() }}</span>}
155
+ </div>
156
+ `,
157
+ styles: `
158
+ :host {
159
+ --_t: var(--ui-look-tray, 0);
160
+ --_h: calc(var(--_h0) + var(--ui-space-1) * var(--_t));
161
+ --_px: calc(var(--ui-space-2-5) + 2px * var(--_t) - 1px);
162
+ display: flex;
163
+ flex-direction: column;
164
+ gap: var(--ui-form-field-gap, calc(var(--ui-space-1-5) + 1px * var(--_t)));
165
+ min-inline-size: 0;
166
+ color: var(--ui-text);
167
+ font: var(--ui-text-base) / var(--ui-leading-base) var(--ui-font-sans);
168
+ }
169
+ :host([data-disabled]) { opacity: var(--ui-disabled-opacity); }
170
+ .top { display: flex; align-items: baseline; gap: var(--ui-space-1-5); padding-inline: calc(2px * var(--_t)); }
171
+ label { min-inline-size: 0; font-weight: var(--ui-weight-medium); overflow-wrap: anywhere; }
172
+ .req { margin-inline-start: 2px; color: var(--ui-form-field-required, var(--ui-text-muted)); font-weight: var(--ui-weight-regular); }
173
+ .opt, .foot { color: var(--ui-text-muted); font-size: calc(var(--ui-text-sm) + 0.5px * var(--_t)); line-height: calc(var(--ui-leading-xs) + 1px * var(--_t)); }
174
+ .opt { flex: none; font-size: var(--ui-text-sm); line-height: var(--ui-leading-xs); }
175
+ .ctl { position: relative; display: grid; justify-items: start; min-inline-size: 0; }
176
+ .chev { position: absolute; inset-block: 0; inset-inline-end: calc(var(--_px) + 1px); inline-size: 16px; block-size: 16px; margin-block: auto; color: var(--ui-text-muted); pointer-events: none; }
177
+ .foot { display: flex; gap: var(--ui-space-3); padding-inline: calc(2px * var(--_t)); }
178
+ p { flex: 1; min-inline-size: 0; min-block-size: 1lh; margin: 0; overflow-wrap: anywhere; }
179
+ :host([data-invalid]) p { color: var(--ui-danger); }
180
+ .count { flex: none; margin-inline-start: auto; font-size: var(--ui-text-sm); font-variant-numeric: tabular-nums; white-space: nowrap; }
181
+ :host ::ng-deep .ui-fc {
182
+ --_e: var(--ui-text-field-edge, var(--ui-hairline));
183
+ --_w: calc(0.5px + 0.5px * var(--_t));
184
+ --_fill: var(--ui-bg-surface);
185
+ box-sizing: border-box;
186
+ inline-size: 100%;
187
+ min-inline-size: 0;
188
+ block-size: var(--_h);
189
+ margin: 0;
190
+ padding: 0 var(--_px);
191
+ border: 1px solid transparent;
192
+ border-radius: var(--ui-text-field-radius, calc(var(--ui-radius-sm) + 1px + 3px * var(--_t)));
193
+ outline: 0;
194
+ background: var(--_fill);
195
+ box-shadow: 0 0 0 var(--_w) var(--_e), 0 1px 2px color-mix(in srgb, var(--ui-gray-1000) 6%, transparent);
196
+ color: inherit;
197
+ font: inherit;
198
+ font-size: calc(var(--ui-text-base) + 0.5px * var(--_t));
199
+ appearance: none;
200
+ transition: var(--ui-duration-2) var(--ui-ease-out);
201
+ transition-property: box-shadow, background;
202
+ }
203
+ :host ::ng-deep select.ui-fc { padding-inline-end: calc(var(--_px) + var(--ui-space-5)); }
204
+ :host ::ng-deep textarea.ui-fc { display: block; block-size: auto; padding-block: calc(var(--ui-space-1-5) + 1px * var(--_t)); overflow: auto; resize: none; }
205
+ :host ::ng-deep .ui-fc::placeholder { color: var(--ui-text-placeholder); }
206
+ @media (hover: hover) { :host ::ng-deep .ui-fc:hover { --_e: var(--ui-text-field-edge-hover, color-mix(in srgb, var(--ui-text) 18%, transparent)); } }
207
+ :host ::ng-deep .ui-fc:focus { --_w: 1px; --_e: var(--ui-text-field-edge-focus, var(--ui-border-input)); }
208
+ :host([data-invalid]) ::ng-deep .ui-fc {
209
+ --_w: 1px;
210
+ --_e: color-mix(in srgb, var(--ui-danger) 55%, transparent);
211
+ --_fill: color-mix(in srgb, var(--ui-danger-soft) calc(50% * var(--_t)), var(--ui-bg-surface));
212
+ }
213
+ :host([data-invalid]) ::ng-deep .ui-fc:focus { --_e: var(--ui-danger); }
214
+ :host ::ng-deep .ui-fc[readonly] { --_fill: var(--ui-bg-subtle); }
215
+ :host ::ng-deep .ui-fc:disabled { --_e: var(--ui-hairline); cursor: not-allowed; }
216
+ @media (pointer: coarse) {
217
+ :host { --_h: calc(var(--_ht) + var(--ui-space-1) * var(--_t)); }
218
+ :host ::ng-deep .ui-fc { font-size: var(--ui-text-field-touch); }
219
+ }
220
+ @media (forced-colors: active) {
221
+ :host ::ng-deep .ui-fc { border-color: CanvasText; }
222
+ :host([data-invalid]) ::ng-deep .ui-fc { outline: 1px solid CanvasText; }
223
+ :host ::ng-deep .ui-fc:focus { outline: 2px solid Highlight; }
224
+ }
225
+ `,
226
+ })
227
+ export class UiFormField {
228
+ /** Shown above the control. Clicking it focuses the control. */
229
+ readonly label = input<string>();
230
+ /** A quiet line under the control. The error takes its place while there is one. */
231
+ readonly hint = input<string>();
232
+ /** Marks the field invalid and shows this message where the hint was. `true` marks it invalid with no message. */
233
+ readonly error = input<string | boolean | null | undefined>();
234
+ /** Adds the required mark and `aria-required`. The mark also shows when the control itself is required. */
235
+ readonly required = input(false, { transform: booleanAttribute });
236
+ /** Adds "Optional" after the label, for forms where most fields are required. */
237
+ readonly optional = input(false, { transform: booleanAttribute });
238
+ /** Text at the end of the line under the control, such as "12/40". You build it. */
239
+ readonly counter = input<string>();
240
+ /** The id of a control you can't mark with `uiFieldControl`. */
241
+ readonly htmlFor = input<string>(undefined, { alias: 'for' });
242
+ /** Height of native inputs and selects: 28, 32 or 36px; Classic 32, 36 or 40px. Taller, with 16px text, on touch screens. */
243
+ readonly size = input<FormFieldSize>('md');
244
+ /** Words to translate: the "Optional" tag and the required mark. */
245
+ readonly labels = input<Partial<FormFieldLabels>>({});
246
+
247
+ private readonly controls = contentChildren(UiFieldControl, { descendants: true });
248
+ readonly control = computed(() => this.controls()[0]);
249
+ protected readonly sizes = SIZES;
250
+ protected readonly t = computed(() => ({ ...LABELS, ...this.labels() }));
251
+ readonly labelId = `ui-form-field-label-${nextId++}`;
252
+ readonly messageId = `${this.labelId}-msg`;
253
+ readonly countId = `${this.labelId}-count`;
254
+
255
+ readonly invalid = computed(() => !!this.error());
256
+ protected readonly message = computed(() => {
257
+ const e = this.error();
258
+ return (typeof e === 'string' && e) || (e === true ? '' : this.hint()) || '';
259
+ });
260
+ protected readonly isRequired = computed(() => this.required() || !!this.control()?.required());
261
+ protected readonly controlId = computed(() => this.htmlFor() ?? this.control()?.id);
262
+ protected readonly labelable = computed(() => !!this.htmlFor() || !!this.control()?.labelable);
263
+ /** The ids that describe the control: the message and the count, when they have text. */
264
+ readonly describers = computed(() => [this.message() ? this.messageId : '', this.counter() ? this.countId : '']);
265
+
266
+ private readonly msg = viewChild<ElementRef<HTMLElement>>('msg');
267
+ private readonly doc = inject(DOCUMENT);
268
+ private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
269
+
270
+ constructor() {
271
+ let shown: string | undefined;
272
+ afterRenderEffect(() => {
273
+ const text = this.message();
274
+ const p = this.msg()?.nativeElement;
275
+ if (shown !== undefined && text !== shown && p?.animate && this.motion()) {
276
+ p.animate([{ opacity: 0, filter: 'blur(2px)', transform: 'translateY(-2px)' }, {}], { duration: 260 * this.motion(), easing: 'ease-out' });
277
+ }
278
+ shown = text;
279
+ });
280
+ afterNextRender(() => {
281
+ if (!isDevMode()) return;
282
+ const el = this.control()?.el;
283
+ if (!el && !this.htmlFor()) console.warn('ui-form-field: mark the control with uiFieldControl, or give the field `for`.', this.host);
284
+ if (el && !this.label() && !el.hasAttribute('aria-label') && !el.hasAttribute('aria-labelledby')) {
285
+ console.warn('ui-form-field: give it a label, or an aria-label on the control.', el);
286
+ }
287
+ });
288
+ }
289
+
290
+ /** Clicking the label focuses a control that a label can't point at, such as a segmented control or a rating. */
291
+ protected focusControl() {
292
+ const c = this.control();
293
+ if (this.labelable() || !c || c.disabled()) return;
294
+ const el = c.el;
295
+ const target =
296
+ el.querySelector<HTMLElement>('[tabindex="0"], :checked') ??
297
+ el.querySelector<HTMLElement>('input:not([type=hidden]), button:not(:disabled), select, textarea, [tabindex]:not([tabindex="-1"])');
298
+ (target ?? el).focus();
299
+ }
300
+
301
+ /** 0 under reduced motion, otherwise the app's motion scale (1 by default). */
302
+ private motion() {
303
+ const view = this.doc.defaultView;
304
+ if (!view?.matchMedia || view.matchMedia('(prefers-reduced-motion: reduce)').matches) return 0;
305
+ const scale = parseFloat(view.getComputedStyle(this.host).getPropertyValue('--ui-motion-scale'));
306
+ return Number.isNaN(scale) ? 1 : scale;
307
+ }
308
+ }