@moni-labs/moni-ui 0.4.13 → 0.4.14

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 (96) hide show
  1. package/custom-elements.json +91 -81
  2. package/dist/browser/moni-ui.iife.min.js +1537 -1384
  3. package/dist/browser/moni-ui.iife.min.js.br +0 -0
  4. package/dist/browser/moni-ui.iife.min.js.gz +0 -0
  5. package/dist/browser/moni-ui.iife.min.js.map +1 -1
  6. package/dist/browser/moni-ui.min.js +2703 -2481
  7. package/dist/browser/moni-ui.min.js.br +0 -0
  8. package/dist/browser/moni-ui.min.js.gz +0 -0
  9. package/dist/browser/moni-ui.min.js.map +1 -1
  10. package/dist/cdn/chunks/{class-map-DsL1Jr2T.js → class-map-QyT9W7rZ.js} +1 -1
  11. package/dist/cdn/chunks/{decorate-DxJYS4gw.js → decorate-B7wZvwrn.js} +629 -543
  12. package/dist/cdn/chunks/if-defined-5hr_ccFw.js +1 -0
  13. package/dist/cdn/chunks/{live-D52JqeKf.js → live-Hm1Di_ND.js} +1 -1
  14. package/dist/cdn/components/moni-app-bar.js +1 -1
  15. package/dist/cdn/components/moni-badge.js +1 -1
  16. package/dist/cdn/components/moni-bottom-sheet.js +1 -1
  17. package/dist/cdn/components/moni-button-group.js +1 -1
  18. package/dist/cdn/components/moni-button-segment.js +1 -1
  19. package/dist/cdn/components/moni-button.js +1 -1
  20. package/dist/cdn/components/moni-card.js +1 -1
  21. package/dist/cdn/components/moni-carousel.js +1 -1
  22. package/dist/cdn/components/moni-checkbox.js +1 -1
  23. package/dist/cdn/components/moni-chip.js +1 -1
  24. package/dist/cdn/components/moni-color-field.js +1 -1
  25. package/dist/cdn/components/moni-context-menu.js +1 -1
  26. package/dist/cdn/components/moni-dialog.js +1 -1
  27. package/dist/cdn/components/moni-divider.js +1 -1
  28. package/dist/cdn/components/moni-expansion.js +1 -1
  29. package/dist/cdn/components/moni-fab-menu.js +1 -1
  30. package/dist/cdn/components/moni-fab.js +1 -1
  31. package/dist/cdn/components/moni-file-field.js +1 -1
  32. package/dist/cdn/components/moni-icon.js +1 -1
  33. package/dist/cdn/components/moni-list-item.js +1 -1
  34. package/dist/cdn/components/moni-list.js +1 -1
  35. package/dist/cdn/components/moni-loading-indicator.js +1 -1
  36. package/dist/cdn/components/moni-menu-item.js +1 -1
  37. package/dist/cdn/components/moni-menu.js +1 -1
  38. package/dist/cdn/components/moni-morph-modal.js +3 -2
  39. package/dist/cdn/components/moni-nav-item.js +1 -1
  40. package/dist/cdn/components/moni-nav.js +1 -1
  41. package/dist/cdn/components/moni-progress.js +1 -1
  42. package/dist/cdn/components/moni-radio.js +1 -1
  43. package/dist/cdn/components/moni-ripple.js +1 -1
  44. package/dist/cdn/components/moni-segmented-button.js +1 -1
  45. package/dist/cdn/components/moni-select-option.js +1 -1
  46. package/dist/cdn/components/moni-select.js +512 -473
  47. package/dist/cdn/components/moni-shape.js +1 -1
  48. package/dist/cdn/components/moni-side-sheet.js +1 -1
  49. package/dist/cdn/components/moni-slider.js +1 -1
  50. package/dist/cdn/components/moni-snackbar.js +1 -1
  51. package/dist/cdn/components/moni-split-button.js +1 -1
  52. package/dist/cdn/components/moni-step.js +1 -1
  53. package/dist/cdn/components/moni-stepper.js +1 -1
  54. package/dist/cdn/components/moni-switch.js +1 -1
  55. package/dist/cdn/components/moni-tab.js +1 -1
  56. package/dist/cdn/components/moni-tabs.js +1 -1
  57. package/dist/cdn/components/moni-text-field.js +122 -95
  58. package/dist/cdn/components/moni-textarea.js +52 -52
  59. package/dist/cdn/components/moni-time-picker.js +1 -1
  60. package/dist/cdn/components/moni-toolbar.js +1 -1
  61. package/dist/cdn/components/moni-tooltip.js +1 -1
  62. package/dist/cdn/components/moni-typography.js +1 -1
  63. package/dist/cdn/importmap.json +98 -98
  64. package/dist/components/_base/field-styles.d.ts.map +1 -1
  65. package/dist/components/_base/field-styles.js +662 -576
  66. package/dist/components/moni-morph-modal.d.ts +10 -0
  67. package/dist/components/moni-morph-modal.d.ts.map +1 -1
  68. package/dist/components/moni-morph-modal.js +323 -217
  69. package/dist/components/moni-select.d.ts +16 -16
  70. package/dist/components/moni-select.d.ts.map +1 -1
  71. package/dist/components/moni-select.js +797 -727
  72. package/dist/components/moni-text-field.d.ts +15 -15
  73. package/dist/components/moni-text-field.d.ts.map +1 -1
  74. package/dist/components/moni-text-field.js +224 -180
  75. package/dist/components/moni-textarea.d.ts +13 -13
  76. package/dist/components/moni-textarea.d.ts.map +1 -1
  77. package/dist/components/moni-textarea.js +127 -122
  78. package/docs/api.json +97 -88
  79. package/docs/assets/moni-morph-modal/autoHeight--false.png +0 -0
  80. package/docs/assets/moni-morph-modal/autoHeight--true.png +0 -0
  81. package/docs/components/morph-modal.md +16 -7
  82. package/docs/components/select.md +74 -74
  83. package/docs/components/text-field.md +75 -66
  84. package/docs/components/textarea.md +51 -51
  85. package/docs/llms.txt +3 -3
  86. package/package.json +1 -1
  87. package/src/components/_base/field-styles.ts +723 -637
  88. package/src/components/moni-morph-modal.test.ts +490 -413
  89. package/src/components/moni-morph-modal.ts +2274 -2162
  90. package/src/components/moni-select.test.ts +489 -466
  91. package/src/components/moni-select.ts +1963 -1815
  92. package/src/components/moni-text-field.test.ts +366 -342
  93. package/src/components/moni-text-field.ts +717 -645
  94. package/src/components/moni-textarea.test.ts +201 -197
  95. package/src/components/moni-textarea.ts +476 -460
  96. package/dist/cdn/chunks/if-defined-DdzvcoI7.js +0 -1
@@ -1,637 +1,723 @@
1
- /**
2
- * @file components/_base/field-styles.ts
3
- * @package @moni-labs/moni-ui
4
- * @license MIT
5
- * @contributors Moni Labs & Contributors
6
- */
7
-
8
- import { css } from 'lit';
9
-
10
- /**
11
- * Shared visual rules for all field-like input components.
12
- *
13
- * This stylesheet provides the complete CSS foundation for the Moni input
14
- * field pattern, ported and extended from the BeerCSS field system. It is
15
- * consumed by: `moni-text-field`, `moni-textarea`, `moni-select`,
16
- * `moni-color-field`, and `moni-file-field`.
17
- *
18
- * **Required DOM structure:**
19
- * Each consumer must render this exact DOM hierarchy inside its shadow root for
20
- * all selectors (especially the floating label) to function correctly:
21
- *
22
- * ```html
23
- * <div class="field [label] [fill|border] [small|large|extra] [prefix|suffix|icon] [invalid] [round*]">
24
- * <i class="leading-icon">...</i> <!-- optional leading icon -->
25
- * <input | select | textarea> <!-- native form control -->
26
- * <label>Label text</label> <!-- MUST be immediately after the control -->
27
- * <i class="trailing-icon">...</i> <!-- optional trailing icon -->
28
- * <span class="suffix-text">...</span> <!-- optional suffix text -->
29
- * <slot name="trailing"></slot> <!-- optional trailing slot -->
30
- * <output>Helper or error text</output> <!-- helper / validation message -->
31
- * </div>
32
- * ```
33
- *
34
- * **Critical ordering rule:**
35
- * The `<label>` element MUST be the immediate next sibling of the
36
- * `<input|select|textarea>`. The CSS adjacent sibling combinator (`+ label`)
37
- * and the `:focus + label` selector depend on this ordering to animate the
38
- * floating label lift. Breaking the order will prevent the label from animating.
39
- *
40
- * **Modifier classes:**
41
- * - `.label` — Activates the floating label behavior.
42
- * - `.fill` — Uses `surface-container-highest` as the input background (filled style).
43
- * - `.border` — Applies an `outline-variant` border (outlined style).
44
- * - `.small` / `.large` / `.extra` — Adjusts height and padding.
45
- * - `.prefix` / `.suffix` — Shifts input padding to make room for icons.
46
- * - `.invalid` — Applies error color to borders, label, and helper text.
47
- * - `.round` / `.round-*` — Applies pill-shaped border radius to the field.
48
- * - `.square` — Removes all border-radius (overrides everything via `!important`).
49
- *
50
- * **Internal CSS custom properties:**
51
- * | Property | Default | Description |
52
- * |------------|---------|------------------------------------------|
53
- * | `--_input` | `3rem` | Height of the input area. |
54
- * | `--_start` | `1.2rem`| Block-start padding for label alignment. |
55
- * | `--_middle`| computed| Vertical center of the input (for icons).|
56
- *
57
- * @see {@link sharedStyles} — Token bridge consumed by this stylesheet.
58
- * @see {@link interactionStyles} — State layer (not used directly in fields).
59
- */
60
- export const fieldStyles = css`
61
- :host {
62
- display: block;
63
- /* Fields are full-width by default; the parent layout controls sizing. */
64
- inline-size: 100%;
65
- }
66
-
67
- /* ─── Base field container ───────────────────────────────────────────────── */
68
- .field {
69
- /* Internal height token — overridden by size modifiers (.small, .large, .extra). */
70
- --_input: 3rem;
71
- /* Vertical start offset used for textarea padding and label positioning. */
72
- --_start: 1.2rem;
73
- /* Computed vertical center — used to position absolutely-placed icons. */
74
- --_middle: calc(var(--_input, 0) / 2);
75
-
76
- /* Default field shape: bottom border only (BeerCSS / MD3 "filled" style). */
77
- border-radius: 0.25rem 0.25rem 0 0;
78
- min-block-size: var(--_input);
79
- display: flex;
80
- flex-direction: column;
81
- position: relative;
82
- inline-size: 100%;
83
- }
84
-
85
- /* ─── Shape overrides ────────────────────────────────────────────────────── */
86
-
87
- /* Square: removes all border-radius regardless of other modifiers.
88
- Uses !important to win specificity over .border and [class*='round']. */
89
- .field.square,
90
- .field.square.border,
91
- .field.square[class*='round'] {
92
- border-radius: 0 !important;
93
- }
94
- .field.square > :is(input, textarea, select) {
95
- border-radius: 0 !important;
96
- }
97
-
98
- /* ─── Fill variant ───────────────────────────────────────────────────────── */
99
- /* Unsets background/color on the container; the background is applied
100
- directly to the <input> so that the floating label overlaps it correctly. */
101
- .field.fill {
102
- --_background: var(--surface-container-highest);
103
- background-color: unset !important;
104
- color: unset !important;
105
- }
106
- .field.fill > :is(input, select, textarea) {
107
- background-color: var(--_background);
108
- /* z-index: 0 ensures the background renders above the ::before layer. */
109
- z-index: 0;
110
- }
111
-
112
- /* ─── Size variants ──────────────────────────────────────────────────────── */
113
- .field.small {
114
- --_input: 2.5rem;
115
- --_start: 1rem;
116
- }
117
- .field.large {
118
- --_input: 3.5rem;
119
- --_start: 1.4rem;
120
- }
121
- .field.extra {
122
- --_input: 4rem;
123
- --_start: 1.6rem;
124
- }
125
-
126
- /* ─── Border (outlined) variant ─────────────────────────────────────────── */
127
- /* Adds full border-radius and outline-variant stroke on all four sides. */
128
- .field.border {
129
- border-radius: 0.25rem;
130
- }
131
-
132
- /* ─── Round / pill variants ──────────────────────────────────────────────── */
133
- /* Applied when class matches the 'round' substring (e.g. .round, .round-sm). */
134
- .field[class*='round'].small {
135
- border-radius: 1.25rem;
136
- }
137
- .field[class*='round'] {
138
- border-radius: 1.5rem;
139
- }
140
- .field[class*='round'].large {
141
- border-radius: 1.75rem;
142
- }
143
- .field[class*='round'].extra {
144
- border-radius: 2rem;
145
- }
146
- /* Compact rounding for dense forms without falling back to square corners. */
147
- .field.small-round,
148
- .field.small-round.small,
149
- .field.small-round.large,
150
- .field.small-round.extra {
151
- border-radius: 0.5rem;
152
- }
153
-
154
- /* ─── Icon positioning ───────────────────────────────────────────────────── */
155
- /* Generic rule: absolutely positions any icon/image/svg inside the field. */
156
- .field > :is(i, img, svg) {
157
- position: absolute;
158
- inset: calc((var(--_input, 0) / 2) - 0.75rem) auto auto auto;
159
- cursor: pointer;
160
- z-index: 10;
161
- inline-size: 1.5rem;
162
- block-size: 1.5rem;
163
- margin: auto 0;
164
- pointer-events: none;
165
- }
166
- /* Leading icon: explicit class wins over :first-child heuristic. */
167
- .field > :is(i, img, svg):first-child,
168
- .field > .leading-icon {
169
- inset: calc(var(--_middle, 0) - 0.75rem) auto auto 1rem;
170
- }
171
-
172
- /* Trailing icon: BeerCSS uses :last-child:not(:first-child) which fails when
173
- an <output> follows the icon. The explicit class always wins and places
174
- the icon on the right edge regardless of sibling count. */
175
- .field > :is(i, img, svg):last-child:not(:first-child),
176
- .field > .trailing-icon {
177
- inset: calc(var(--_middle, 0) - 0.75rem) 1rem auto auto;
178
- /* Prevent the inline-start override from the generic rule above. */
179
- inset-inline-start: auto !important;
180
- }
181
-
182
- /* Error state: trailing icons inherit the error color. */
183
- .field.invalid > i {
184
- color: var(--error);
185
- }
186
-
187
- /* ─── Native form element reset ──────────────────────────────────────────── */
188
- /* 'all: unset' strips browser-default styles (appearance, border, font, etc.)
189
- so the field's visual design is fully controlled by Moni's CSS. */
190
- .field > :is(input, textarea, select) {
191
- all: unset;
192
- position: relative;
193
- display: block;
194
- box-sizing: border-box;
195
- border-radius: inherit;
196
- /* Default border is transparent; visible only in .border and focus states. */
197
- border: 0.0625rem solid transparent;
198
- padding: 0 0.9375rem;
199
- font-family: inherit;
200
- font-size: 1rem;
201
- min-block-size: var(--_input);
202
- outline: none;
203
- z-index: 1;
204
- background: none;
205
- resize: none; /* Textareas use field-sizing:content instead of manual resize. */
206
- text-align: start;
207
- cursor: text;
208
- color: var(--on-surface);
209
- }
210
-
211
- /* Ensure date/time input values align to start (browser quirk on some platforms). */
212
- input::-webkit-date-and-time-value {
213
- text-align: start;
214
- }
215
-
216
- /* Autofill: preserve text color when the browser applies its autofill highlight.
217
- -webkit-background-clip + -webkit-text-fill-color override the yellow tint. */
218
- :is(input, select, textarea):is(:-webkit-autofill, :autofill) {
219
- -webkit-background-clip: text;
220
- -webkit-text-fill-color: var(--on-surface);
221
- }
222
-
223
- /* On focus, increase border width by 1px — shift padding inward by 1px
224
- to prevent layout shift from the border width change. */
225
- .field > :is(input, textarea, select):focus {
226
- border: 0.125rem solid transparent;
227
- padding-inline: 0.875rem;
228
- }
229
-
230
- /* Textareas without explicit rows grow automatically using field-sizing:content.
231
- A max-height of 12rem (~8 lines) prevents uncontrolled page growth. */
232
- .field > textarea:not([rows]) {
233
- field-sizing: content;
234
- max-block-size: 12rem;
235
- }
236
-
237
- /* ─── Transparent native picker controls ─────────────────────────────────── */
238
- /* File and color inputs, and date/time picker indicators are hidden so the
239
- component can render its own UI. The native controls are still active for
240
- accessibility (click propagates through the transparent overlay). */
241
- input[type='file'],
242
- input[type='color'],
243
- :not(.field) > input:is([type^='date'], [type^='time'], [type='month'], [type='week']),
244
- input::-webkit-calendar-picker-indicator {
245
- opacity: 0;
246
- position: absolute;
247
- inset: 0;
248
- inline-size: 100%;
249
- block-size: 100%;
250
- margin: 0;
251
- padding: 0;
252
- border: 0;
253
- outline: 0;
254
- z-index: 2 !important;
255
- }
256
-
257
- /* On fine-pointer (mouse) devices, push the calendar picker indicator behind
258
- the field content so it doesn't interfere with other clickable elements. */
259
- @media (pointer: fine) {
260
- .field > input::-webkit-calendar-picker-indicator {
261
- z-index: -1 !important;
262
- }
263
- }
264
-
265
- /* Remove browser-native search field decorations. */
266
- input::-webkit-search-decoration,
267
- input::-webkit-search-cancel-button,
268
- input::-webkit-search-results-button,
269
- input::-webkit-search-results-decoration,
270
- input::-webkit-inner-spin-button,
271
- input::-webkit-outer-spin-button {
272
- display: none;
273
- }
274
-
275
- /* Remove the browser spinner on number inputs — use explicit stepper UI instead. */
276
- input[type='number'] {
277
- appearance: textfield;
278
- }
279
-
280
- /* ─── Border variant: field-level border colors ──────────────────────────── */
281
- .field.border > :is(input, textarea, select) {
282
- border-color: var(--outline);
283
- }
284
- .field.border > :is(input, textarea, select):focus {
285
- border-color: var(--primary);
286
- }
287
-
288
- /* Round variants add extra inline padding to clear the curved edges. */
289
- .field[class*='round'] > :is(input, textarea, select) {
290
- padding-inline: 1.4376rem;
291
- }
292
- .field[class*='round'] > :is(input, textarea, select):focus {
293
- padding-inline: 1.375rem;
294
- }
295
-
296
- /* ─── Icon padding accommodation ─────────────────────────────────────────── */
297
- /* .prefix / .suffix shift the input's inline padding to make room for icons. */
298
- .field.prefix > :is(input, textarea, select) {
299
- padding-inline-start: 2.9375rem;
300
- }
301
- .field.prefix > :is(input, textarea, select):focus {
302
- padding-inline-start: 2.875rem;
303
- }
304
- .field.suffix > :is(input, textarea, select) {
305
- padding-inline-end: 2.9375rem;
306
- }
307
- .field.suffix > :is(input, textarea, select):focus {
308
- padding-inline-end: 2.875rem;
309
- }
310
-
311
- /* ─── Underline (non-border, non-round) bottom border ─────────────────────── */
312
- /* Default M3 filled field style: only the bottom border is visible. */
313
- .field:not(.border, [class*='round']) > :is(input, textarea, select) {
314
- border-block-end-color: var(--outline);
315
- }
316
- .field:not(.border, [class*='round']) > :is(input, textarea, select):focus {
317
- border-block-end-color: var(--primary);
318
- }
319
-
320
- /* Round non-bordered fields get a subtle elevation shadow instead of a border. */
321
- .field[class*='round']:not(.border, .fill) > :is(input, textarea, select),
322
- .field[class*='round']:not(.border) > :is(input, textarea, select):focus {
323
- box-shadow: var(--elevate1);
324
- }
325
- .field[class*='round']:not(.border, .fill) > :is(input, textarea, select):focus {
326
- box-shadow: var(--elevate2);
327
- }
328
-
329
- /* ─── Invalid / error state borders ─────────────────────────────────────── */
330
- .field.invalid:not(.border, [class*='round']) > :is(input, textarea, select),
331
- .field.invalid:not(.border, [class*='round']) > :is(input, textarea, select):focus {
332
- border-block-end-color: var(--error);
333
- }
334
- .field.invalid.border > :is(input, textarea, select),
335
- .field.invalid.border > :is(input, textarea, select):focus {
336
- border-color: var(--error);
337
- }
338
-
339
- /* ─── Disabled state ─────────────────────────────────────────────────────── */
340
- /* Reduces opacity on the entire field container when the native control is
341
- disabled, rather than applying separate rules to each child. */
342
- .field:has(> :disabled) {
343
- opacity: 0.5;
344
- cursor: not-allowed;
345
- }
346
- .field > :disabled {
347
- cursor: not-allowed;
348
- }
349
-
350
- /* ─── Select element ─────────────────────────────────────────────────────── */
351
- /* Remove browser-native select appearance; the component renders its own dropdown. */
352
- .field > select {
353
- user-select: none;
354
- appearance: none;
355
- -webkit-appearance: none;
356
- background-image: none;
357
- }
358
-
359
- /* ─── Block-start padding for label accommodation ────────────────────────── */
360
- /* Inputs with a floating label need top padding to create space for the
361
- label when it lifts above the input. Selects always lift their label. */
362
- .field > :is(input, select) {
363
- padding-block-start: 1rem;
364
- }
365
- /* No-label and border+fill fields: remove the top padding offset. */
366
- .field:not(.label) > :is(input, select),
367
- .field.border:not(.fill) > :is(input, select) {
368
- padding-block-start: 0;
369
- }
370
- /* Textareas use the --_start token to align with the label baseline. */
371
- .field > textarea {
372
- padding-block-start: var(--_start) !important;
373
- }
374
- .field > textarea:focus {
375
- /* 0.01rem compensates for the border width increase on focus. */
376
- padding-block-start: calc(var(--_start, 0) - 0.01rem) !important;
377
- }
378
- .field:not(.label) > textarea,
379
- .field.border:not(.fill) > textarea {
380
- padding-block-start: calc(var(--_start, 0) - 0.5rem) !important;
381
- }
382
- .field:not(.label) > textarea:focus,
383
- .field.border:not(.fill) > textarea:focus {
384
- padding-block-start: calc(var(--_start, 0) - 0.51rem) !important;
385
- }
386
-
387
- /* ─── Floating label ─────────────────────────────────────────────────────── */
388
- /* The label starts at full font-size (1rem) vertically centered in the field.
389
- On focus or when value is present, it scales down to 0.75rem and lifts
390
- to the top of the field container. */
391
- .field.label > label {
392
- --_start: 1rem;
393
- position: absolute;
394
- inset: -0.5rem 0.9375rem 0 var(--_start);
395
- display: flex;
396
- /* Full height + 1rem (for label overhang) centers the label vertically. */
397
- block-size: calc(var(--_input, 0) + 1rem);
398
- line-height: calc(var(--_input, 0) + 1rem);
399
- font-size: 1rem;
400
- transition: all 0.2s;
401
- gap: 0.25rem;
402
- white-space: nowrap;
403
- /* The label is purely decorative from a layout perspective; it must never
404
- intercept pointer events meant for the underlying input. */
405
- pointer-events: none;
406
- color: var(--on-surface-variant);
407
- }
408
-
409
- /* Round fields: label aligns with the increased inline padding. */
410
- .field.label[class*='round'] > label {
411
- inset: -0.5rem 1.9375rem 0 var(--_start);
412
- }
413
-
414
- /* ─── Label lift selector group ──────────────────────────────────────────── */
415
- /* The label lifts (scales down + moves up) in four conditions:
416
- 1. label.active — the component sets this class directly (readonly inputs).
417
- 2. :focus + label — when the native control is focused.
418
- 3. [placeholder]:not(:placeholder-shown) + label when a value is present.
419
- 4. select + label selects always show their label lifted.
420
- 5. input.active + label for programmatically activated inputs. */
421
-
422
- /* Border + prefix + no-fill variant needs a reduced --_start offset. */
423
- .field.label.border.prefix:not(.fill)
424
- > :is(
425
- label.active,
426
- :focus + label,
427
- [placeholder]:not(:placeholder-shown) + label,
428
- select + label,
429
- input.active + label
430
- ) {
431
- --_start: 1rem;
432
- }
433
-
434
- /* Round field label and round border prefix field label override. */
435
- .field.label[class*='round'] > label,
436
- .field.label.border.prefix[class*='round']:not(.fill)
437
- > :is(
438
- label.active,
439
- :focus + label,
440
- [placeholder]:not(:placeholder-shown) + label,
441
- select + label,
442
- input.active + label
443
- ) {
444
- --_start: 1.5rem;
445
- }
446
- /* Compact rounding keeps the label closer to the edge than pill fields.
447
- This must follow the generic [class*='round'] rule. */
448
- .field.label.small-round > label {
449
- --_start: 1rem;
450
- inset: -0.5rem 0.9375rem 0 var(--_start);
451
- }
452
-
453
- /* Prefix fields: shift the label's inline-start to clear the leading icon. */
454
- .field.label.prefix > label {
455
- --_start: 3rem;
456
- }
457
-
458
- /* Lifted label: shrinks to 0.75rem and collapses to the top of the field. */
459
- .field.label
460
- > :is(
461
- label.active,
462
- :focus + label,
463
- [placeholder]:not(:placeholder-shown) + label,
464
- select + label,
465
- input.active + label
466
- ) {
467
- block-size: 2.5rem;
468
- line-height: 2.5rem;
469
- font-size: 0.75rem;
470
- }
471
-
472
- /* Border variant: label collapses to 1rem height with a notch cut effect. */
473
- .field.label.border:not(.fill)
474
- > :is(
475
- label.active,
476
- :focus + label,
477
- [placeholder]:not(:placeholder-shown) + label,
478
- select + label,
479
- input.active + label
480
- ) {
481
- block-size: 1rem;
482
- line-height: 1rem;
483
- }
484
-
485
- /* ─── Border notch (label gap in the top border) ─────────────────────────── */
486
- /* The ::after pseudo creates the horizontal line to the right of the lifted
487
- label, visually cutting a notch into the top border of .field.border. */
488
- .field.label.border:not(.fill) > label::after {
489
- content: '';
490
- display: block;
491
- margin: 0.5rem 0 0 0;
492
- border-block-start: 0.0625rem solid var(--outline);
493
- block-size: 1rem;
494
- transition: none;
495
- flex: auto;
496
- }
497
- .field.label.border:not(.fill) > :focus + label::after {
498
- /* On focus, the notch line becomes primary-colored. */
499
- border-block-start: 0.125rem solid var(--primary);
500
- }
501
-
502
- /* ─── Border notch clipping (clip-path) ──────────────────────────────────── */
503
- /* When the label is lifted, a clip-path cuts a gap in the top border of the
504
- input element itself, creating the appearance of the label floating within
505
- the border's top edge. The clip-path dimensions account for label width. */
506
- .field.label.border.square:not(.fill)
507
- > :is(input, textarea):is(:focus, [placeholder]:not(:placeholder-shown), .active),
508
- .field.label.border.square:not(.fill) > select,
509
- .field.label.border.square:not(.fill) > input.active,
510
- .field.label.border.square:not(.fill) > select.active {
511
- clip-path: polygon(-2% -2%,.75rem -2%,.75rem .5rem,calc(100% - 1rem) .5rem,calc(100% - 1rem) -2%,102% -2%,102% 102%,-2% 102%);
512
- }
513
-
514
- /* Prefix variant: clip starts further right to clear the leading icon text. */
515
- .field.label.border.prefix.square:not(.fill)
516
- > :is(input, textarea):is(:focus, [placeholder]:not(:placeholder-shown), .active),
517
- .field.label.border.prefix.square:not(.fill) > select,
518
- .field.label.border.prefix.square:not(.fill) > input.active,
519
- .field.label.border.prefix.square:not(.fill) > select.active {
520
- clip-path: polygon(-2% -2%,.75rem -2%,.75rem .5rem,calc(100% - 1rem) .5rem,calc(100% - 1rem) -2%,102% -2%,102% 102%,-2% 102%);
521
- }
522
-
523
- /* Round and square border fields use a wider notch to clear the curved border. */
524
- .field.label.border[class*='round']:not(.fill)
525
- > :is(input, textarea):is(:focus, [placeholder]:not(:placeholder-shown), .active),
526
- .field.label.border[class*='round']:not(.fill) > select,
527
- .field.label.border:not(.fill)
528
- > :is(input, textarea):is(:focus, [placeholder]:not(:placeholder-shown), .active),
529
- .field.label.border:not(.fill) > select {
530
- clip-path: polygon(-2% -2%,0.75rem -2%,0.75rem 0.5rem,calc(100% - 1rem) 0.5rem,calc(100% - 1rem) -2%,102% -2%,102% 102%,-2% 102%);
531
- }
532
-
533
- .field.label.border.prefix[class*='round']:not(.fill)
534
- > :is(input, textarea):is(:focus, [placeholder]:not(:placeholder-shown), .active),
535
- .field.label.border.prefix[class*='round']:not(.fill) > select,
536
- .field.label.border.prefix:not(.fill)
537
- > :is(input, textarea):is(:focus, [placeholder]:not(:placeholder-shown), .active),
538
- .field.label.border.prefix:not(.fill) > select {
539
- clip-path: polygon(-2% -2%,0.75rem -2%,0.75rem 0.5rem,calc(100% - 1rem) 0.5rem,calc(100% - 1rem) -2%,102% -2%,102% 102%,-2% 102%);
540
- }
541
-
542
- .field.label.border.round:not(.fill)
543
- > :is(input, textarea):is(:focus, [placeholder]:not(:placeholder-shown), .active),
544
- .field.label.border.round:not(.fill) > select,
545
- .field.label.border.round:not(.fill) > input.active,
546
- .field.label.border.round:not(.fill) > select.active {
547
- clip-path: polygon(-2% -2%,1.25rem -2%,1.25rem 0.5rem,calc(100% - 2rem) 0.5rem,calc(100% - 2rem) -2%,102% -2%,102% 102%,-2% 102%) !important;
548
- }
549
-
550
- /* The compact shape needs a narrower leading segment so it never crosses
551
- the first glyph of the floating label. */
552
- .field.label.border.small-round:not(.fill)
553
- > :is(input, textarea):is(:focus, [placeholder]:not(:placeholder-shown), .active),
554
- .field.label.border.small-round:not(.fill) > select,
555
- .field.label.border.small-round:not(.fill) > input.active,
556
- .field.label.border.small-round:not(.fill) > select.active {
557
- clip-path: polygon(-2% -2%,0.75rem -2%,0.75rem 0.5rem,calc(100% - 1rem) 0.5rem,calc(100% - 1rem) -2%,102% -2%,102% 102%,-2% 102%) !important;
558
- }
559
-
560
- /* ─── Label color changes ─────────────────────────────────────────────────── */
561
- /* On focus: label turns primary-colored to draw attention. */
562
- .field.label > :focus + label {
563
- color: var(--primary);
564
- }
565
-
566
- /* On error: label and notch line turn error-colored. */
567
- .field.label.invalid > label,
568
- .field.label.invalid > label::after {
569
- color: var(--error) !important;
570
- border-color: var(--error) !important;
571
- }
572
-
573
- /* ─── Helper / error output ──────────────────────────────────────────────── */
574
- /* The <output> element below the field shows helper text or validation errors. */
575
- .field > output {
576
- display: inline-block;
577
- font-size: 0.75rem;
578
- background: none !important;
579
- padding: 0.25rem 1rem;
580
- line-height: 1.25rem;
581
- align-self: start;
582
- color: var(--on-surface-variant);
583
- }
584
- /* Error output overrides the neutral helper color. */
585
- .field > output.invalid {
586
- color: var(--error) !important;
587
- }
588
- /* Round fields: increase horizontal padding to align with the curved edge. */
589
- .field[class*='round'] > output {
590
- padding: 0.25rem 1.5rem;
591
- }
592
- /* Show only one output at a time: helper OR error, never both. */
593
- .field.invalid > output:not(.invalid),
594
- .field:not(.invalid) > output.invalid {
595
- display: none;
596
- }
597
-
598
- /* ─── Footer wrapper (textarea & multi-line fields) ───────────────────────── */
599
- /* Lays out helper text (left) and character counter (right) on the same row,
600
- matching the M3 spec for supporting-text + character-counter pairs. */
601
- .field > .footer {
602
- display: flex;
603
- align-items: center;
604
- justify-content: space-between;
605
- gap: 1rem;
606
- padding: 0;
607
- min-block-size: 1.25rem;
608
- }
609
- .field > .footer > output {
610
- display: inline-block;
611
- font-size: 0.75rem;
612
- background: none !important;
613
- padding: 0.25rem 1rem;
614
- line-height: 1.25rem;
615
- align-self: center;
616
- color: var(--on-surface-variant);
617
- }
618
- .field > .footer > output.invalid {
619
- color: var(--error) !important;
620
- }
621
- /* Character counter — right-aligned, same typographic style as the helper. */
622
- .field > .footer > .counter {
623
- padding: 0.25rem 1rem;
624
- color: var(--on-surface-variant);
625
- }
626
- /* Spacer pushes counter to the right when there is no helper text. */
627
- .field > .footer > .spacer {
628
- flex: 1;
629
- }
630
- /* Same exclusive show logic as direct <output> elements. */
631
- .field.invalid > .footer > output:not(.invalid),
632
- .field:not(.invalid) > .footer > output.invalid {
633
- display: none;
634
- }
635
- `;
636
-
637
- export default fieldStyles;
1
+ /**
2
+ * @file components/_base/field-styles.ts
3
+ * @package @moni-labs/moni-ui
4
+ * @license MIT
5
+ * @contributors Moni Labs & Contributors
6
+ */
7
+
8
+ import { css } from "lit";
9
+
10
+ /**
11
+ * Shared visual rules for all field-like input components.
12
+ *
13
+ * This stylesheet provides the complete CSS foundation for the Moni input
14
+ * field pattern, ported and extended from the BeerCSS field system. It is
15
+ * consumed by: `moni-text-field`, `moni-textarea`, `moni-select`,
16
+ * `moni-color-field`, and `moni-file-field`.
17
+ *
18
+ * **Required DOM structure:**
19
+ * Each consumer must render this exact DOM hierarchy inside its shadow root for
20
+ * all selectors (especially the floating label) to function correctly:
21
+ *
22
+ * ```html
23
+ * <div class="field [label] [fill|border] [small|large|extra] [prefix|suffix|icon] [invalid] [round*]">
24
+ * <i class="leading-icon">...</i> <!-- optional leading icon -->
25
+ * <input | select | textarea> <!-- native form control -->
26
+ * <label>Label text</label> <!-- MUST be immediately after the control -->
27
+ * <i class="trailing-icon">...</i> <!-- optional trailing icon -->
28
+ * <span class="suffix-text">...</span> <!-- optional suffix text -->
29
+ * <slot name="trailing"></slot> <!-- optional trailing slot -->
30
+ * <output>Helper or error text</output> <!-- helper / validation message -->
31
+ * </div>
32
+ * ```
33
+ *
34
+ * **Critical ordering rule:**
35
+ * The `<label>` element MUST be the immediate next sibling of the
36
+ * `<input|select|textarea>`. The CSS adjacent sibling combinator (`+ label`)
37
+ * and the `:focus + label` selector depend on this ordering to animate the
38
+ * floating label lift. Breaking the order will prevent the label from animating.
39
+ *
40
+ * **Modifier classes:**
41
+ * - `.label` — Activates the floating label behavior.
42
+ * - `.fill` — Uses `surface-container-highest` as the input background (filled style).
43
+ * - `.border` — Applies an `outline-variant` border (outlined style).
44
+ * - `.small` / `.large` / `.extra` — Adjusts height and padding.
45
+ * - `.prefix` / `.suffix` — Shifts input padding to make room for icons.
46
+ * - `.invalid` — Applies error color to borders, label, and helper text.
47
+ * - `.round` / `.round-*` — Applies pill-shaped border radius to the field.
48
+ * - `.square` — Removes all border-radius (overrides everything via `!important`).
49
+ *
50
+ * **Internal CSS custom properties:**
51
+ * | Property | Default | Description |
52
+ * |------------|---------|------------------------------------------|
53
+ * | `--_input` | `3rem` | Height of the input area. |
54
+ * | `--_start` | `1.2rem`| Block-start padding for label alignment. |
55
+ * | `--_middle`| computed| Vertical center of the input (for icons).|
56
+ *
57
+ * @see {@link sharedStyles} — Token bridge consumed by this stylesheet.
58
+ * @see {@link interactionStyles} — State layer (not used directly in fields).
59
+ */
60
+ export const fieldStyles = css`
61
+ :host {
62
+ display: block;
63
+ /* Fields are full-width by default; the parent layout controls sizing. */
64
+ inline-size: 100%;
65
+ }
66
+
67
+ /* ─── Base field container ───────────────────────────────────────────────── */
68
+ .field {
69
+ /* Internal height token — overridden by size modifiers (.small, .large, .extra). */
70
+ --_input: 3rem;
71
+ /* Vertical start offset used for textarea padding and label positioning. */
72
+ --_start: 1.2rem;
73
+ /* Computed vertical center — used to position absolutely-placed icons. */
74
+ --_middle: calc(var(--_input, 0) / 2);
75
+
76
+ /* Default field shape: bottom border only (BeerCSS / MD3 "filled" style). */
77
+ border-radius: 0.25rem 0.25rem 0 0;
78
+ min-block-size: var(--_input);
79
+ display: flex;
80
+ flex-direction: column;
81
+ position: relative;
82
+ inline-size: 100%;
83
+ }
84
+
85
+ /* ─── Shape overrides ────────────────────────────────────────────────────── */
86
+
87
+ /* Square: removes all border-radius regardless of other modifiers.
88
+ Uses !important to win specificity over .border and [class*='round']. */
89
+ .field.square,
90
+ .field.square.border,
91
+ .field.square[class*="round"] {
92
+ border-radius: 0 !important;
93
+ }
94
+ .field.square > :is(input, textarea, select) {
95
+ border-radius: 0 !important;
96
+ }
97
+
98
+ /* ─── Fill variant ───────────────────────────────────────────────────────── */
99
+ /* Unsets background/color on the container; the background is applied
100
+ directly to the <input> so that the floating label overlaps it correctly. */
101
+ .field.fill {
102
+ --_background: var(--surface-container-highest);
103
+ background-color: unset !important;
104
+ color: unset !important;
105
+ }
106
+ .field.fill > :is(input, select, textarea) {
107
+ background-color: var(--_background);
108
+ /* z-index: 0 ensures the background renders above the ::before layer. */
109
+ z-index: 0;
110
+ }
111
+
112
+ /* ─── Size variants ──────────────────────────────────────────────────────── */
113
+ .field.small {
114
+ --_input: 2.5rem;
115
+ --_start: 1rem;
116
+ }
117
+ .field.large {
118
+ --_input: 3.5rem;
119
+ --_start: 1.4rem;
120
+ }
121
+ .field.extra {
122
+ --_input: 4rem;
123
+ --_start: 1.6rem;
124
+ }
125
+
126
+ /* ─── Border (outlined) variant ─────────────────────────────────────────── */
127
+ /* Adds full border-radius and outline-variant stroke on all four sides. */
128
+ .field.border {
129
+ border-radius: 0.25rem;
130
+ }
131
+
132
+ /* ─── Round / pill variants ──────────────────────────────────────────────── */
133
+ /* Applied when class matches the 'round' substring (e.g. .round, .round-sm). */
134
+ .field[class*="round"].small {
135
+ border-radius: 1.25rem;
136
+ }
137
+ .field[class*="round"] {
138
+ border-radius: 1.5rem;
139
+ }
140
+ .field[class*="round"].large {
141
+ border-radius: 1.75rem;
142
+ }
143
+ .field[class*="round"].extra {
144
+ border-radius: 2rem;
145
+ }
146
+ /* Compact rounding for dense forms without falling back to square corners. */
147
+ .field.small-round,
148
+ .field.small-round.small,
149
+ .field.small-round.large,
150
+ .field.small-round.extra {
151
+ border-radius: 0.5rem;
152
+ }
153
+
154
+ /* ─── Icon positioning ───────────────────────────────────────────────────── */
155
+ /* Generic rule: absolutely positions any icon/image/svg inside the field. */
156
+ .field > :is(i, img, svg) {
157
+ position: absolute;
158
+ inset: calc((var(--_input, 0) / 2) - 0.75rem) auto auto auto;
159
+ cursor: pointer;
160
+ z-index: 10;
161
+ inline-size: 1.5rem;
162
+ block-size: 1.5rem;
163
+ margin: auto 0;
164
+ pointer-events: none;
165
+ }
166
+ /* Leading icon: explicit class wins over :first-child heuristic. */
167
+ .field > :is(i, img, svg):first-child,
168
+ .field > .leading-icon {
169
+ inset: calc(var(--_middle, 0) - 0.75rem) auto auto 1rem;
170
+ }
171
+
172
+ /* Trailing icon: BeerCSS uses :last-child:not(:first-child) which fails when
173
+ an <output> follows the icon. The explicit class always wins and places
174
+ the icon on the right edge regardless of sibling count. */
175
+ .field > :is(i, img, svg):last-child:not(:first-child),
176
+ .field > .trailing-icon {
177
+ inset: calc(var(--_middle, 0) - 0.75rem) 1rem auto auto;
178
+ /* Prevent the inline-start override from the generic rule above. */
179
+ inset-inline-start: auto !important;
180
+ }
181
+
182
+ /* Error state: trailing icons inherit the error color. */
183
+ .field.invalid > i {
184
+ color: var(--error);
185
+ }
186
+
187
+ /* ─── Native form element reset ──────────────────────────────────────────── */
188
+ /* 'all: unset' strips browser-default styles (appearance, border, font, etc.)
189
+ so the field's visual design is fully controlled by Moni's CSS. */
190
+ .field > :is(input, textarea, select) {
191
+ all: unset;
192
+ position: relative;
193
+ display: block;
194
+ box-sizing: border-box;
195
+ border-radius: inherit;
196
+ /* Default border is transparent; visible only in .border and focus states. */
197
+ border: 0.0625rem solid transparent;
198
+ padding: 0 0.9375rem;
199
+ font-family: inherit;
200
+ font-size: 1rem;
201
+ min-block-size: var(--_input);
202
+ outline: none;
203
+ z-index: 1;
204
+ background: none;
205
+ resize: none; /* Textareas use field-sizing:content instead of manual resize. */
206
+ text-align: start;
207
+ cursor: text;
208
+ color: var(--on-surface);
209
+ }
210
+
211
+ /* Ensure date/time input values align to start (browser quirk on some platforms). */
212
+ input::-webkit-date-and-time-value {
213
+ text-align: start;
214
+ }
215
+
216
+ /* Autofill: preserve text color when the browser applies its autofill highlight.
217
+ -webkit-background-clip + -webkit-text-fill-color override the yellow tint. */
218
+ :is(input, select, textarea):is(:-webkit-autofill, :autofill) {
219
+ -webkit-background-clip: text;
220
+ -webkit-text-fill-color: var(--on-surface);
221
+ }
222
+
223
+ /* On focus, increase border width by 1px — shift padding inward by 1px
224
+ to prevent layout shift from the border width change. */
225
+ .field > :is(input, textarea, select):focus {
226
+ border: 0.125rem solid transparent;
227
+ padding-inline: 0.875rem;
228
+ }
229
+
230
+ /* Textareas without explicit rows grow automatically using field-sizing:content.
231
+ A max-height of 12rem (~8 lines) prevents uncontrolled page growth. */
232
+ .field > textarea:not([rows]) {
233
+ field-sizing: content;
234
+ max-block-size: 12rem;
235
+ }
236
+
237
+ /* ─── Transparent native picker controls ─────────────────────────────────── */
238
+ /* File and color inputs, and date/time picker indicators are hidden so the
239
+ component can render its own UI. The native controls are still active for
240
+ accessibility (click propagates through the transparent overlay). */
241
+ input[type="file"],
242
+ input[type="color"],
243
+ :not(.field)
244
+ > input:is([type^="date"], [type^="time"], [type="month"], [type="week"]),
245
+ input::-webkit-calendar-picker-indicator {
246
+ opacity: 0;
247
+ position: absolute;
248
+ inset: 0;
249
+ inline-size: 100%;
250
+ block-size: 100%;
251
+ margin: 0;
252
+ padding: 0;
253
+ border: 0;
254
+ outline: 0;
255
+ z-index: 2 !important;
256
+ }
257
+
258
+ /* On fine-pointer (mouse) devices, push the calendar picker indicator behind
259
+ the field content so it doesn't interfere with other clickable elements. */
260
+ @media (pointer: fine) {
261
+ .field > input::-webkit-calendar-picker-indicator {
262
+ z-index: -1 !important;
263
+ }
264
+ }
265
+
266
+ /* Remove browser-native search field decorations. */
267
+ input::-webkit-search-decoration,
268
+ input::-webkit-search-cancel-button,
269
+ input::-webkit-search-results-button,
270
+ input::-webkit-search-results-decoration,
271
+ input::-webkit-inner-spin-button,
272
+ input::-webkit-outer-spin-button {
273
+ display: none;
274
+ }
275
+
276
+ /* Remove the browser spinner on number inputs — use explicit stepper UI instead. */
277
+ input[type="number"] {
278
+ appearance: textfield;
279
+ }
280
+
281
+ /* ─── Border variant: field-level border colors ──────────────────────────── */
282
+ .field.border > :is(input, textarea, select) {
283
+ border-color: var(--outline);
284
+ }
285
+ .field.border > :is(input, textarea, select):focus {
286
+ border-color: var(--primary);
287
+ }
288
+
289
+ /* Round variants add extra inline padding to clear the curved edges. */
290
+ .field[class*="round"] > :is(input, textarea, select) {
291
+ padding-inline: 1.4376rem;
292
+ }
293
+ .field[class*="round"] > :is(input, textarea, select):focus {
294
+ padding-inline: 1.375rem;
295
+ }
296
+
297
+ /* ─── Icon padding accommodation ─────────────────────────────────────────── */
298
+ /* .prefix / .suffix shift the input's inline padding to make room for icons. */
299
+ .field.prefix > :is(input, textarea, select) {
300
+ padding-inline-start: 2.9375rem;
301
+ }
302
+ .field.prefix > :is(input, textarea, select):focus {
303
+ padding-inline-start: 2.875rem;
304
+ }
305
+ .field.suffix > :is(input, textarea, select) {
306
+ padding-inline-end: 2.9375rem;
307
+ }
308
+ .field.suffix > :is(input, textarea, select):focus {
309
+ padding-inline-end: 2.875rem;
310
+ }
311
+
312
+ /* ─── Underline (non-border, non-round) bottom border ─────────────────────── */
313
+ /* Default M3 filled field style: only the bottom border is visible. */
314
+ .field:not(.border, [class*="round"]) > :is(input, textarea, select) {
315
+ border-block-end-color: var(--outline);
316
+ }
317
+ .field:not(.border, [class*="round"]) > :is(input, textarea, select):focus {
318
+ border-block-end-color: var(--primary);
319
+ }
320
+
321
+ /* Round non-bordered fields get a subtle elevation shadow instead of a border. */
322
+ .field[class*="round"]:not(.border, .fill) > :is(input, textarea, select),
323
+ .field[class*="round"]:not(.border) > :is(input, textarea, select):focus {
324
+ box-shadow: var(--elevate1);
325
+ }
326
+ .field[class*="round"]:not(.border, .fill)
327
+ > :is(input, textarea, select):focus {
328
+ box-shadow: var(--elevate2);
329
+ }
330
+
331
+ /* ─── Invalid / error state borders ─────────────────────────────────────── */
332
+ .field.invalid:not(.border, [class*="round"]) > :is(input, textarea, select),
333
+ .field.invalid:not(.border, [class*="round"])
334
+ > :is(input, textarea, select):focus {
335
+ border-block-end-color: var(--error);
336
+ }
337
+ .field.invalid.border > :is(input, textarea, select),
338
+ .field.invalid.border > :is(input, textarea, select):focus {
339
+ border-color: var(--error);
340
+ }
341
+
342
+ /* ─── Disabled state ─────────────────────────────────────────────────────── */
343
+ /* Reduces opacity on the entire field container when the native control is
344
+ disabled, rather than applying separate rules to each child. */
345
+ .field:has(> :disabled) {
346
+ opacity: 0.5;
347
+ cursor: not-allowed;
348
+ }
349
+ .field > :disabled {
350
+ cursor: not-allowed;
351
+ }
352
+
353
+ /* ─── Select element ─────────────────────────────────────────────────────── */
354
+ /* Remove browser-native select appearance; the component renders its own dropdown. */
355
+ .field > select {
356
+ user-select: none;
357
+ appearance: none;
358
+ -webkit-appearance: none;
359
+ background-image: none;
360
+ }
361
+
362
+ /* ─── Block-start padding for label accommodation ────────────────────────── */
363
+ /* Inputs with a floating label need top padding to create space for the
364
+ label when it lifts above the input. Selects always lift their label. */
365
+ .field > :is(input, select) {
366
+ padding-block-start: 1rem;
367
+ }
368
+ /* No-label and border+fill fields: remove the top padding offset. */
369
+ .field:not(.label) > :is(input, select),
370
+ .field.border:not(.fill) > :is(input, select) {
371
+ padding-block-start: 0;
372
+ }
373
+ /* Textareas use the --_start token to align with the label baseline. */
374
+ .field > textarea {
375
+ padding-block-start: var(--_start) !important;
376
+ }
377
+ .field > textarea:focus {
378
+ /* 0.01rem compensates for the border width increase on focus. */
379
+ padding-block-start: calc(var(--_start, 0) - 0.01rem) !important;
380
+ }
381
+ .field:not(.label) > textarea,
382
+ .field.border:not(.fill) > textarea {
383
+ padding-block-start: calc(var(--_start, 0) - 0.5rem) !important;
384
+ }
385
+ .field:not(.label) > textarea:focus,
386
+ .field.border:not(.fill) > textarea:focus {
387
+ padding-block-start: calc(var(--_start, 0) - 0.51rem) !important;
388
+ }
389
+
390
+ /* ─── Floating label ─────────────────────────────────────────────────────── */
391
+ /* The label starts at full font-size (1rem) vertically centered in the field.
392
+ On focus or when value is present, it scales down to 0.75rem and lifts
393
+ to the top of the field container. */
394
+ .field.label > label {
395
+ --_start: 1rem;
396
+ position: absolute;
397
+ inset: -0.5rem 0.9375rem 0 var(--_start);
398
+ display: flex;
399
+ /* Full height + 1rem (for label overhang) centers the label vertically. */
400
+ block-size: calc(var(--_input, 0) + 1rem);
401
+ line-height: calc(var(--_input, 0) + 1rem);
402
+ font-size: 1rem;
403
+ transition: all 0.2s;
404
+ gap: 0.25rem;
405
+ white-space: nowrap;
406
+ /* The label is purely decorative from a layout perspective; it must never
407
+ intercept pointer events meant for the underlying input. */
408
+ pointer-events: none;
409
+ color: var(--on-surface-variant);
410
+ }
411
+
412
+ /* Round fields: label aligns with the increased inline padding. */
413
+ .field.label[class*="round"] > label {
414
+ inset: -0.5rem 1.9375rem 0 var(--_start);
415
+ }
416
+
417
+ /* ─── Label lift selector group ──────────────────────────────────────────── */
418
+ /* The label lifts (scales down + moves up) in four conditions:
419
+ 1. label.active the component sets this class directly (readonly inputs).
420
+ 2. :focus + label when the native control is focused.
421
+ 3. [placeholder]:not(:placeholder-shown) + label — when a value is present.
422
+ 4. select + label — selects always show their label lifted.
423
+ 5. input.active + label — for programmatically activated inputs. */
424
+
425
+ /* Border + prefix + no-fill variant needs a reduced --_start offset. */
426
+ .field.label.border.prefix:not(.fill)
427
+ > :is(
428
+ label.active,
429
+ :focus + label,
430
+ [placeholder]:not(:placeholder-shown) + label,
431
+ select + label,
432
+ input.active + label
433
+ ) {
434
+ --_start: 1rem;
435
+ }
436
+
437
+ /* Round field label and round border prefix field label override. */
438
+ .field.label[class*="round"] > label,
439
+ .field.label.border.prefix[class*="round"]:not(.fill)
440
+ > :is(
441
+ label.active,
442
+ :focus + label,
443
+ [placeholder]:not(:placeholder-shown) + label,
444
+ select + label,
445
+ input.active + label
446
+ ) {
447
+ --_start: 1.5rem;
448
+ }
449
+
450
+ .field.label.small-round > label {
451
+ --_start: 1rem;
452
+ inset: -0.5rem 0.9375rem 0 var(--_start);
453
+ }
454
+
455
+ /* Prefix fields: shift the label's inline-start to clear the leading icon. */
456
+ .field.label.prefix > label {
457
+ --_start: 3rem;
458
+ }
459
+
460
+ /* Lifted label: shrinks to 0.75rem and collapses to the top of the field. */
461
+ .field.label
462
+ > :is(
463
+ label.active,
464
+ :focus + label,
465
+ [placeholder]:not(:placeholder-shown) + label,
466
+ select + label,
467
+ input.active + label
468
+ ) {
469
+ block-size: 2.5rem;
470
+ line-height: 2.5rem;
471
+ font-size: 0.75rem;
472
+ }
473
+
474
+ /* Border variant: label collapses to 1rem height with a notch cut effect. */
475
+ .field.label.border:not(.fill)
476
+ > :is(
477
+ label.active,
478
+ :focus + label,
479
+ [placeholder]:not(:placeholder-shown) + label,
480
+ select + label,
481
+ input.active + label
482
+ ) {
483
+ block-size: 1rem;
484
+ line-height: 1rem;
485
+ }
486
+
487
+ /* ─── Border notch (label gap in the top border) ─────────────────────────── */
488
+ /* The ::after pseudo creates the horizontal line to the right of the lifted
489
+ label, visually cutting a notch into the top border of .field.border. */
490
+ .field.label.border:not(.fill) > label::after {
491
+ content: "";
492
+ display: block;
493
+ margin: 0.5rem 0 0 0;
494
+ border-block-start: 0.0625rem solid var(--outline);
495
+ block-size: 1rem;
496
+ transition: none;
497
+ flex: auto;
498
+ }
499
+ .field.label.border:not(.fill) > :focus + label::after {
500
+ /* On focus, the notch line becomes primary-colored. */
501
+ border-block-start: 0.125rem solid var(--primary);
502
+ }
503
+
504
+ /* ─── Border notch clipping (clip-path) ──────────────────────────────────── */
505
+ /* When the label is lifted, a clip-path cuts a gap in the top border of the
506
+ input element itself, creating the appearance of the label floating within
507
+ the border's top edge. The clip-path dimensions account for label width. */
508
+ .field.label.border.square:not(.fill)
509
+ > :is(input, textarea):is(
510
+ :focus,
511
+ [placeholder]:not(:placeholder-shown),
512
+ .active
513
+ ),
514
+ .field.label.border.square:not(.fill) > select,
515
+ .field.label.border.square:not(.fill) > input.active,
516
+ .field.label.border.square:not(.fill) > select.active {
517
+ clip-path: polygon(
518
+ -2% -2%,
519
+ 0.75rem -2%,
520
+ 0.75rem 0.5rem,
521
+ calc(100% - 1rem) 0.5rem,
522
+ calc(100% - 1rem) -2%,
523
+ 102% -2%,
524
+ 102% 102%,
525
+ -2% 102%
526
+ );
527
+ }
528
+
529
+ /* Prefix variant: clip starts further right to clear the leading icon text. */
530
+ .field.label.border.prefix.square:not(.fill)
531
+ > :is(input, textarea):is(
532
+ :focus,
533
+ [placeholder]:not(:placeholder-shown),
534
+ .active
535
+ ),
536
+ .field.label.border.prefix.square:not(.fill) > select,
537
+ .field.label.border.prefix.square:not(.fill) > input.active,
538
+ .field.label.border.prefix.square:not(.fill) > select.active {
539
+ clip-path: polygon(
540
+ -2% -2%,
541
+ 0.75rem -2%,
542
+ 0.75rem 0.5rem,
543
+ calc(100% - 1rem) 0.5rem,
544
+ calc(100% - 1rem) -2%,
545
+ 102% -2%,
546
+ 102% 102%,
547
+ -2% 102%
548
+ );
549
+ }
550
+
551
+ /* Round and square border fields use a wider notch to clear the curved border. */
552
+ .field.label.border[class*="round"]:not(.fill)
553
+ > :is(input, textarea):is(
554
+ :focus,
555
+ [placeholder]:not(:placeholder-shown),
556
+ .active
557
+ ),
558
+ .field.label.border[class*="round"]:not(.fill) > select,
559
+ .field.label.border:not(.fill)
560
+ > :is(input, textarea):is(
561
+ :focus,
562
+ [placeholder]:not(:placeholder-shown),
563
+ .active
564
+ ),
565
+ .field.label.border:not(.fill) > select {
566
+ clip-path: polygon(
567
+ -2% -2%,
568
+ 0.75rem -2%,
569
+ 0.75rem 0.5rem,
570
+ calc(100% - 1rem) 0.5rem,
571
+ calc(100% - 1rem) -2%,
572
+ 102% -2%,
573
+ 102% 102%,
574
+ -2% 102%
575
+ );
576
+ }
577
+
578
+ .field.label.border.prefix[class*="round"]:not(.fill)
579
+ > :is(input, textarea):is(
580
+ :focus,
581
+ [placeholder]:not(:placeholder-shown),
582
+ .active
583
+ ),
584
+ .field.label.border.prefix[class*="round"]:not(.fill) > select,
585
+ .field.label.border.prefix:not(.fill)
586
+ > :is(input, textarea):is(
587
+ :focus,
588
+ [placeholder]:not(:placeholder-shown),
589
+ .active
590
+ ),
591
+ .field.label.border.prefix:not(.fill) > select {
592
+ clip-path: polygon(
593
+ -2% -2%,
594
+ 0.75rem -2%,
595
+ 0.75rem 0.5rem,
596
+ calc(100% - 1rem) 0.5rem,
597
+ calc(100% - 1rem) -2%,
598
+ 102% -2%,
599
+ 102% 102%,
600
+ -2% 102%
601
+ );
602
+ }
603
+
604
+ .field.label.border.round:not(.fill)
605
+ > :is(input, textarea):is(
606
+ :focus,
607
+ [placeholder]:not(:placeholder-shown),
608
+ .active
609
+ ),
610
+ .field.label.border.round:not(.fill) > select,
611
+ .field.label.border.round:not(.fill) > input.active,
612
+ .field.label.border.round:not(.fill) > select.active {
613
+ clip-path: polygon(
614
+ -2% -2%,
615
+ 1.25rem -2%,
616
+ 1.25rem 0.5rem,
617
+ calc(100% - 2rem) 0.5rem,
618
+ calc(100% - 2rem) -2%,
619
+ 102% -2%,
620
+ 102% 102%,
621
+ -2% 102%
622
+ ) !important;
623
+ }
624
+
625
+ .field.label.border.small-round:not(.fill)
626
+ > :is(input, textarea):is(
627
+ :focus,
628
+ [placeholder]:not(:placeholder-shown),
629
+ .active
630
+ ),
631
+ .field.label.border.small-round:not(.fill) > select,
632
+ .field.label.border.small-round:not(.fill) > input.active,
633
+ .field.label.border.small-round:not(.fill) > select.active {
634
+ clip-path: polygon(
635
+ -2% -2%,
636
+ 0.75rem -2%,
637
+ 0.75rem 0.5rem,
638
+ calc(100% - 1rem) 0.5rem,
639
+ calc(100% - 1rem) -2%,
640
+ 102% -2%,
641
+ 102% 102%,
642
+ -2% 102%
643
+ ) !important;
644
+ }
645
+
646
+ /* ─── Label color changes ─────────────────────────────────────────────────── */
647
+ /* On focus: label turns primary-colored to draw attention. */
648
+ .field.label > :focus + label {
649
+ color: var(--primary);
650
+ }
651
+
652
+ /* On error: label and notch line turn error-colored. */
653
+ .field.label.invalid > label,
654
+ .field.label.invalid > label::after {
655
+ color: var(--error) !important;
656
+ border-color: var(--error) !important;
657
+ }
658
+
659
+ /* ─── Helper / error output ──────────────────────────────────────────────── */
660
+ /* The <output> element below the field shows helper text or validation errors. */
661
+ .field > output {
662
+ display: inline-block;
663
+ font-size: 0.75rem;
664
+ background: none !important;
665
+ padding: 0.25rem 1rem;
666
+ line-height: 1.25rem;
667
+ align-self: start;
668
+ color: var(--on-surface-variant);
669
+ }
670
+ /* Error output overrides the neutral helper color. */
671
+ .field > output.invalid {
672
+ color: var(--error) !important;
673
+ }
674
+ /* Round fields: increase horizontal padding to align with the curved edge. */
675
+ .field[class*="round"] > output {
676
+ padding: 0.25rem 1.5rem;
677
+ }
678
+ /* Show only one output at a time: helper OR error, never both. */
679
+ .field.invalid > output:not(.invalid),
680
+ .field:not(.invalid) > output.invalid {
681
+ display: none;
682
+ }
683
+
684
+ /* ─── Footer wrapper (textarea & multi-line fields) ───────────────────────── */
685
+ /* Lays out helper text (left) and character counter (right) on the same row,
686
+ matching the M3 spec for supporting-text + character-counter pairs. */
687
+ .field > .footer {
688
+ display: flex;
689
+ align-items: center;
690
+ justify-content: space-between;
691
+ gap: 1rem;
692
+ padding: 0;
693
+ min-block-size: 1.25rem;
694
+ }
695
+ .field > .footer > output {
696
+ display: inline-block;
697
+ font-size: 0.75rem;
698
+ background: none !important;
699
+ padding: 0.25rem 1rem;
700
+ line-height: 1.25rem;
701
+ align-self: center;
702
+ color: var(--on-surface-variant);
703
+ }
704
+ .field > .footer > output.invalid {
705
+ color: var(--error) !important;
706
+ }
707
+ /* Character counter — right-aligned, same typographic style as the helper. */
708
+ .field > .footer > .counter {
709
+ padding: 0.25rem 1rem;
710
+ color: var(--on-surface-variant);
711
+ }
712
+ /* Spacer pushes counter to the right when there is no helper text. */
713
+ .field > .footer > .spacer {
714
+ flex: 1;
715
+ }
716
+ /* Same exclusive show logic as direct <output> elements. */
717
+ .field.invalid > .footer > output:not(.invalid),
718
+ .field:not(.invalid) > .footer > output.invalid {
719
+ display: none;
720
+ }
721
+ `;
722
+
723
+ export default fieldStyles;