@canonical/react-ds-global-form 0.30.0 → 0.31.0

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 (63) hide show
  1. package/dist/esm/density.css +234 -0
  2. package/dist/esm/docs/examples/density-examples.css +20 -0
  3. package/dist/esm/index.css +66 -6
  4. package/dist/esm/lib/_work_in_progress/DensityTestbed/Testbed.js +77 -0
  5. package/dist/esm/lib/_work_in_progress/DensityTestbed/Testbed.js.map +1 -0
  6. package/dist/esm/lib/_work_in_progress/DensityTestbed/baseline-system.css +81 -0
  7. package/dist/esm/lib/_work_in_progress/DensityTestbed/density.testbed.css +153 -0
  8. package/dist/esm/lib/_work_in_progress/DensityTestbed/mocks.js +23 -0
  9. package/dist/esm/lib/_work_in_progress/DensityTestbed/mocks.js.map +1 -0
  10. package/dist/esm/lib/common/Wrapper/styles.css +3 -1
  11. package/dist/esm/lib/common/bindField/bindField.js +15 -8
  12. package/dist/esm/lib/common/bindField/bindField.js.map +1 -1
  13. package/dist/esm/lib/component/ChoicesField/common/Option/Option.js +1 -1
  14. package/dist/esm/lib/component/ChoicesField/common/Option/Option.js.map +1 -1
  15. package/dist/esm/lib/component/ChoicesField/styles.css +55 -15
  16. package/dist/esm/lib/component/DateField/DateField.js +19 -1
  17. package/dist/esm/lib/component/DateField/DateField.js.map +1 -1
  18. package/dist/esm/lib/component/FileUploadField/FileUploadField.js +40 -3
  19. package/dist/esm/lib/component/FileUploadField/FileUploadField.js.map +1 -1
  20. package/dist/esm/lib/component/NumberField/NumberField.js +1 -1
  21. package/dist/esm/lib/component/NumberField/NumberField.js.map +1 -1
  22. package/dist/esm/lib/component/RangeField/RangeField.js +1 -1
  23. package/dist/esm/lib/component/RangeField/RangeField.js.map +1 -1
  24. package/dist/esm/lib/subcomponent/CheckboxInput/styles.css +45 -16
  25. package/dist/esm/lib/subcomponent/DateInput/styles.css +12 -0
  26. package/dist/esm/lib/subcomponent/DateTimeInput/styles.css +13 -0
  27. package/dist/esm/lib/subcomponent/Field/Label/Label.js +1 -3
  28. package/dist/esm/lib/subcomponent/Field/Label/Label.js.map +1 -1
  29. package/dist/esm/lib/subcomponent/Field/Label/styles.css +2 -3
  30. package/dist/esm/lib/subcomponent/FileUploadInput/FileUploadInput.js +11 -21
  31. package/dist/esm/lib/subcomponent/FileUploadInput/FileUploadInput.js.map +1 -1
  32. package/dist/esm/lib/subcomponent/FileUploadInput/styles.css +3 -3
  33. package/dist/esm/lib/subcomponent/PasswordInput/styles.css +5 -6
  34. package/dist/esm/lib/subcomponent/RadioInput/styles.css +36 -7
  35. package/dist/esm/lib/subcomponent/RangeInput/styles.css +10 -9
  36. package/dist/esm/lib/subcomponent/SwitchInput/styles.css +27 -10
  37. package/dist/esm/lib/subcomponent/TextInput/TextInput.js +1 -1
  38. package/dist/esm/lib/subcomponent/TextInput/TextInput.js.map +1 -1
  39. package/dist/esm/lib/subcomponent/TextareaInput/TextareaInput.js +1 -3
  40. package/dist/esm/lib/subcomponent/TextareaInput/TextareaInput.js.map +1 -1
  41. package/dist/esm/lib/subcomponent/TextareaInput/styles.css +4 -9
  42. package/dist/esm/lib/subcomponent/TimeInput/styles.css +8 -0
  43. package/dist/esm/lib/utils/countries/countries.js +1 -1
  44. package/dist/esm/lib/utils/countries/countries.js.map +1 -1
  45. package/dist/esm/lib/utils/hooks/useFieldError.js +21 -24
  46. package/dist/esm/lib/utils/hooks/useFieldError.js.map +1 -1
  47. package/dist/types/lib/_work_in_progress/DensityTestbed/Testbed.d.ts +42 -0
  48. package/dist/types/lib/_work_in_progress/DensityTestbed/Testbed.d.ts.map +1 -0
  49. package/dist/types/lib/_work_in_progress/DensityTestbed/mocks.d.ts +26 -0
  50. package/dist/types/lib/_work_in_progress/DensityTestbed/mocks.d.ts.map +1 -0
  51. package/dist/types/lib/common/bindField/bindField.d.ts.map +1 -1
  52. package/dist/types/lib/common/bindField/types.d.ts +14 -5
  53. package/dist/types/lib/common/bindField/types.d.ts.map +1 -1
  54. package/dist/types/lib/component/DateField/DateField.d.ts +3 -2
  55. package/dist/types/lib/component/DateField/DateField.d.ts.map +1 -1
  56. package/dist/types/lib/component/FileUploadField/FileUploadField.d.ts +8 -5
  57. package/dist/types/lib/component/FileUploadField/FileUploadField.d.ts.map +1 -1
  58. package/dist/types/lib/subcomponent/Field/Label/Label.d.ts.map +1 -1
  59. package/dist/types/lib/subcomponent/FileUploadInput/FileUploadInput.d.ts.map +1 -1
  60. package/dist/types/lib/subcomponent/TextareaInput/TextareaInput.d.ts.map +1 -1
  61. package/dist/types/lib/utils/hooks/useFieldError.d.ts +14 -0
  62. package/dist/types/lib/utils/hooks/useFieldError.d.ts.map +1 -1
  63. package/package.json +13 -13
@@ -0,0 +1,234 @@
1
+ /* @canonical/react-ds-global-form — density & baseline alignment (FORM APPLICATION)
2
+ *
3
+ * The GENERIC density primitives — the context/density modifier families
4
+ * (.app/.site/.docs × .comfortable/.dense) and their --density-* outputs
5
+ * (--density-line-height(-effective), --density-target-baseline-px,
6
+ * --density-padding-inline, --density-space-sm/-md/-lg) — now live in
7
+ * @canonical/styles (`modifiers.density.css`), so EVERY package can read them
8
+ * (ds-global's Accordion as well as this form package). See that file for the
9
+ * 2×3 matrix and the value table.
10
+ *
11
+ * THIS file is the FORM APPLICATION layer: it applies those primitives to the
12
+ * form's own controls (`.ds.input`, `.ds.field-label/description/error`, the
13
+ * textarea) — sizing their boxes to the density cell and seating their text on the
14
+ * 4px grid. The --form-* token mapping lives in index.css.
15
+ *
16
+ * NB the BUTTON is a ds-global component, so its density seat lives in ds-global
17
+ * (Button/styles.css), reading the same shared --density-* primitives — an app
18
+ * that ships ds-global without the form package still gets a seated button.
19
+ *
20
+ * Text baseline sits round(up, height × 2/3) down the box, so every control shares
21
+ * one baseline. Zero-JS (cap-unit approximation); holds to the cap tolerance.
22
+ */
23
+
24
+ /* ── Controls consume the density box ───────────────────────────────────────
25
+ * A control is a FIXED grid-multiple height with border-box so its border is
26
+ * absorbed into that height (not added past it) — so a bordered and a borderless
27
+ * control of the same density are the same height. Top-referenced so the
28
+ * space-before below (not flex centre/stretch) governs the text.
29
+ *
30
+ * Controls no longer carry `.p` — the density system supplies the body font tier
31
+ * (font-size / weight / family) here, and the baseline placement below. */
32
+ /* NB `.ds.input.textarea` is EXCLUDED: a textarea is a multi-line control whose
33
+ * height is intrinsic (its `min-height: 5lh`), not a single density line — the
34
+ * single-line crush below would flatten it. It gets its own placement further
35
+ * down (grid-multiple line-height so every row sits on the grid). */
36
+ :is(.comfortable, .dense, .app, .site, .docs) .ds.input:not(.textarea) {
37
+ box-sizing: border-box;
38
+ /* Same effective line-height the target-baseline uses (single source of the
39
+ fallback chain), so a bare context class keeps a valid box height too. */
40
+ --density-box-height: var(--density-line-height-effective);
41
+ block-size: var(--density-box-height);
42
+ min-block-size: var(--density-box-height);
43
+ align-items: flex-start;
44
+ justify-content: flex-start;
45
+ /* Kill the UA BOTTOM padding only. Do NOT zero padding-block-start here: this
46
+ selector is more specific (0,4,0) than the placement rule below (0,2,0), so a
47
+ `padding-block: 0` shorthand would out-specify and WIPE the placement's
48
+ `padding-block-start: var(--space-before)` — leaving the label pinned to the
49
+ box top (off the baseline). The placement rule owns the start. */
50
+ padding-block-end: 0;
51
+
52
+ /* Body font tier — what `.p` used to supply. */
53
+ font-size: var(--typography-text-primary-font-size);
54
+ font-family: var(--typography-text-primary-font-family);
55
+ }
56
+
57
+ /* The input WRAPPER is the box (like the button element): don't stretch its
58
+ * child, top-reference it so the input's own space-before governs. Needs to beat
59
+ * the TextInput's `.ds.input.text { align-items: stretch }` (0,3,0). */
60
+ :is(.comfortable, .dense, .app, .site, .docs) .ds.input.text,
61
+ :is(.comfortable, .dense, .app, .site, .docs) .ds.input {
62
+ align-items: flex-start;
63
+ }
64
+
65
+ /* The <input> is the text carrier — treat it exactly like the button label:
66
+ * same body font tier, and normalised so only the space-before (below) positions
67
+ * its text. (It's content-box with an intrinsic height, so reset that.) */
68
+ :is(.comfortable, .dense, .app, .site, .docs) .ds.input > input {
69
+ box-sizing: border-box;
70
+ min-block-size: 0;
71
+ block-size: auto;
72
+ margin-block: 0;
73
+ font-size: var(--typography-text-primary-font-size);
74
+ font-family: var(--typography-text-primary-font-family);
75
+ }
76
+
77
+ /* ── Baseline placement: `.baseline` nudge + `--space-before` ───────────────
78
+ * Two parts, the combination that put controls ON the grid:
79
+ *
80
+ * 1. NUDGE (the DS.01 `.baseline` mechanism): --bl-start-nudge snaps the text's
81
+ * first baseline onto the NEAREST grid line, computed from the element's own
82
+ * font (1cap + line-height) — font-relative, so it's exact at any size and
83
+ * needs no per-element fudge. This is what lands text exactly on a line.
84
+ *
85
+ * 2. --space-before: whole baselines added to move that snapped baseline DOWN to
86
+ * the density TARGET line (round-up of the remaining distance), less the box's
87
+ * own top border.
88
+ *
89
+ * padding-block-start = bl-start-nudge + space-before − border-top
90
+ * space-before = round(up, target − bl-start-nudge − border-top, baseline)
91
+ *
92
+ * Applies to the button, the input, and the field label/description/error — i.e.
93
+ * CONTROL-like text only. Bare prose (p / .p / h1–h6) is DELIBERATELY NOT here:
94
+ * running text belongs to the typography engine, which already seats it on the
95
+ * grid (snapped --computed-line-height + --start/--end-nudge) and lets `.editorial`
96
+ * add its inter-block margins. Density crushing prose to line-height:1 fought that
97
+ * engine (and only ever put the FIRST line on-grid — wrapped lines drifted). By
98
+ * partitioning prose OUT, density and the engine write to disjoint element sets,
99
+ * so `.editorial` composes with density with no specificity war. `:is()` (not
100
+ * `:where()`) still gives the control seat the specificity to beat a control's own
101
+ * centring (e.g. the Button's `align-items: center`). */
102
+ /* Body font tier for the field label/description/error, which lost `.p`. Scoped
103
+ to just these (NOT the headings, which keep their own tier). */
104
+ :is(.comfortable, .dense, .app, .site, .docs)
105
+ :is(.ds.field-label, .ds.field-description, .ds.field-error) {
106
+ font-size: var(--typography-text-primary-font-size);
107
+ font-family: var(--typography-text-primary-font-family);
108
+ }
109
+
110
+ :is(.comfortable, .dense, .app, .site, .docs) .ds.input > input,
111
+ :is(.comfortable, .dense, .app, .site, .docs)
112
+ :is(.ds.field-label, .ds.field-description, .ds.field-error) {
113
+ line-height: 1;
114
+ /* Baseline within a line-height:1 box (font-relative cap approximation). */
115
+ --natural-baseline: calc((1em + 1cap) / 2);
116
+ /* Pad the top so the baseline lands at the density target, less the box's own
117
+ top border. */
118
+ --space-before: max(
119
+ 0px,
120
+ calc(
121
+ var(--density-target-baseline-px, 0px) -
122
+ var(--natural-baseline) -
123
+ var(--border-top-width, 0px)
124
+ )
125
+ );
126
+ padding-block-start: var(--space-before);
127
+ padding-block-end: 0;
128
+ }
129
+
130
+ /* ── Textarea: a multi-line control on the grid ──────────────────────────────
131
+ * Unlike the single-line input, a textarea has MANY text rows, so it needs a
132
+ * line-height that is itself a whole baseline multiple — then EVERY row sits on
133
+ * a grid line, not just the first. It's excluded from the single-line box crush
134
+ * (keeps its intrinsic `5lh` height) and from the `line-height: 1` placement
135
+ * above; here it gets its own placement:
136
+ * · line-height = the density line-height (a whole baseline multiple), so rows
137
+ * advance one grid interval each.
138
+ * · the FIRST row is seated on the density target the same way as everything
139
+ * else: nudge onto the nearest grid line, then space-before to the target,
140
+ * less the border (0 — border is on the chrome box) and the drift knob.
141
+ * The chrome supplies the box's own block padding; we ADD the seating on top. */
142
+ :is(.comfortable, .dense, .app, .site, .docs) .ds.input.textarea {
143
+ --td-line-height: var(
144
+ --density-line-height,
145
+ var(--density-lh-comfy, calc(var(--baseline-height) * 8))
146
+ );
147
+ line-height: var(--td-line-height);
148
+ font-size: var(--typography-text-primary-font-size);
149
+ font-family: var(--typography-text-primary-font-family);
150
+
151
+ /* Same form-control drift as the single-line input (see the knob's KLAXON note
152
+ below). Set locally so this stays self-contained — the button path is never
153
+ touched. */
154
+ --control-text-drift-AVOID-USAGE: 2px;
155
+ /* First row's baseline within its own line-box, then lift to the target. */
156
+ --natural-baseline: calc((var(--td-line-height) + 1cap) / 2);
157
+ /* Unlike the single-line input (a borderless inner <input> inside a bordered
158
+ wrapper), the textarea IS the chrome: it carries `.ds.input.chrome`, whose
159
+ top border-width occupies layout space above the text even when the top
160
+ border colour is transparent. So subtract that top border — exactly as the
161
+ button subtracts its own — or the first row seats ~1px low versus the
162
+ button/input target. */
163
+ --td-border-top: var(
164
+ --form-input-border-width-top,
165
+ var(--form-input-border-width, 0px)
166
+ );
167
+ --td-space-before: max(
168
+ 0px,
169
+ calc(
170
+ var(--density-target-baseline-px, 0px) -
171
+ var(--natural-baseline) -
172
+ var(--td-border-top) -
173
+ var(--control-text-drift-AVOID-USAGE, 0px)
174
+ )
175
+ );
176
+ /* Seat the first row ON TOP OF the chrome's block padding (don't replace it —
177
+ that padding is the box inset; this is the grid seating). */
178
+ padding-block-start: calc(
179
+ var(--form-input-padding-block, 0px) +
180
+ var(--td-space-before)
181
+ );
182
+ }
183
+
184
+ /* ── Bottom rhythm: density-seated flow text only (NOT prose) ─────────────────
185
+ * A BORDERED control (button, input wrapper) has a fixed `block-size` that is
186
+ * already a whole baseline multiple, so its bottom rhythm is the box height —
187
+ * no bottom padding needed (and it would be inert against the fixed height).
188
+ *
189
+ * The field label/description/error are density-seated with line-height:1, so
190
+ * their box ends at the text descender; with `padding-block-end: 0` a following
191
+ * grid/flow sibling (e.g. the textarea below a field label) resumes off-grid.
192
+ * Fill the box out to a whole density line-height so its bottom lands on a grid
193
+ * line. The `- 1em` term is correct precisely because these are line-height:1.
194
+ *
195
+ * Bare prose (p / .p / h1–h6) is NOT here: it is no longer density-seated (see the
196
+ * partition above), so its box is its OWN snapped line-height and the engine's
197
+ * --end-nudge already lands its bottom on the grid. Adding a density fill on top
198
+ * would double-pad. Prose bottom rhythm belongs to the engine / `.editorial`. */
199
+ :is(.comfortable, .dense, .app, .site, .docs)
200
+ :is(.ds.field-label, .ds.field-description, .ds.field-error) {
201
+ padding-block-end: max(
202
+ 0px,
203
+ calc(
204
+ var(
205
+ --density-line-height,
206
+ var(--density-lh-comfy, calc(var(--baseline-height) * 8))
207
+ ) -
208
+ var(--space-before) -
209
+ 1em
210
+ )
211
+ );
212
+ }
213
+
214
+ /* ── --control-text-drift-AVOID-USAGE — the one honest patch ──────────────────
215
+ * A native form control (<input>, <textarea>) renders its text a couple of px
216
+ * LOWER than a <span>/<button> label at byte-identical CSS — a UA metrics quirk
217
+ * of editable controls, NOT a border and NOT captured by the cap-unit maths. The
218
+ * cap approximation is exact for real text runs but optimistic for a form
219
+ * control's internal text box, so the leaf needs a small lift to share the grid
220
+ * line with the button/label.
221
+ *
222
+ * The name is a deliberate KLAXON: this is empirical (calibrated by eye, may vary
223
+ * by browser/font), never a knob to reach for in app code. 🔴 TODO(#15): find the
224
+ * structural cause (line-box rounding? UA control metrics?) and delete it.
225
+ *
226
+ * It feeds the SAME `--border-top-width` term the shared placement formula reads
227
+ * (a larger subtraction ⇒ less space-before ⇒ text lifts UP). Doing it this way —
228
+ * rather than adding a separate term to the shared formula — keeps the BUTTON's
229
+ * placement byte-identical to its known-good state: the button never sets this
230
+ * knob, so its `--border-top-width` stays the pure border calc above. */
231
+ :where(.comfortable, .dense, .app, .site, .docs) .ds.input > input {
232
+ --control-text-drift-AVOID-USAGE: 2px;
233
+ --border-top-width: var(--control-text-drift-AVOID-USAGE);
234
+ }
@@ -0,0 +1,20 @@
1
+ /* Layout for the density/baseline doc examples. Minimal: an inline row of
2
+ * controls (so their baselines can be read against the overlay together) and a
3
+ * vertical stack for comparing two cells. No overrides that would shift text off
4
+ * the grid — the examples must show the real seating. */
5
+
6
+ .density-example__row {
7
+ display: flex;
8
+ flex-wrap: nowrap;
9
+ align-items: flex-start; /* controls are top-referenced; the seat is internal */
10
+ gap: calc(var(--baseline-height, 0.25rem) * 3); /* 12px */
11
+ overflow-x: auto;
12
+ }
13
+
14
+ .density-example__stack {
15
+ display: flex;
16
+ flex-direction: column;
17
+ /* One field-block gap between the compared cells, so the stack itself stays on
18
+ the grid. */
19
+ gap: calc(var(--baseline-height, 0.25rem) * 6); /* 24px */
20
+ }
@@ -9,6 +9,9 @@
9
9
  * inline = horizontal axis (inline-start = left in LTR, right in RTL)
10
10
  */
11
11
 
12
+ /* Density & baseline alignment (context × density → control height + baseline). */
13
+ @import url("./density.css");
14
+
12
15
  :root {
13
16
  /* ── Form grid layout ───────────────────────────────────────────── */
14
17
  /* Forms are subgrids: they inherit columns from a parent .grid */
@@ -32,15 +35,22 @@
32
35
  /* ── Field layout spacing ───────────────────────────────────────── */
33
36
  /* Container-owned: the form/field wrapper controls all spacing. */
34
37
 
38
+ /* Gaps are split by AXIS so no token spans both directions (a density tier can
39
+ then tune each axis independently, and the names stay honest):
40
+ BLOCK (vertical): field-block-gap · field-label-gap · group-gap
41
+ INLINE (horizontal): field-inline-gap */
35
42
  --form-field-block-gap: var(
36
43
  --container-gap-loose
37
- ); /* 24px — block-direction (vertical) gap between fields */
38
- --form-field-inline-gap: var(
44
+ ); /* 24px — block: gap BETWEEN fields */
45
+ --form-field-label-gap: var(
39
46
  --container-gap-default
40
- ); /* 16px — inline-direction (horizontal) gap: label ↔ input */
47
+ ); /* 16px — block: gap from a field's LABEL down to its control */
41
48
  --form-group-gap: var(
42
49
  --space-100
43
- ); /* 8px — block-direction gap: desc/error ↔ input */
50
+ ); /* 8px — block: gap from desc/error to the input */
51
+ --form-field-inline-gap: var(
52
+ --container-gap-default
53
+ ); /* 16px — inline: label↔input, prefix/suffix (HORIZONTAL only) */
44
54
 
45
55
  /* ── Input chrome ───────────────────────────────────────────────── */
46
56
  /* Component-owned: internal padding regardless of context. */
@@ -99,7 +109,8 @@
99
109
 
100
110
  /* ── Label ──────────────────────────────────────────────────────── */
101
111
 
102
- --form-label-font-weight: var(--typography-text-primary-bold-font-weight);
112
+ /* Field labels use regular paragraph weight, not bold (per design review). */
113
+ --form-label-font-weight: var(--typography-text-primary-font-weight);
103
114
  --form-label-font-size: var(--typography-text-primary-font-size);
104
115
  --form-label-color: var(--color-text);
105
116
  /* --form-label-padding-block: … ; */ /* block padding for label */
@@ -136,6 +147,37 @@
136
147
  /* --form-focus-ring-offset: … ; */ /* focus ring offset from border */
137
148
  }
138
149
 
150
+ /* ── Density → form channel mapping ──────────────────────────────────────────
151
+ * The FORM layer decides which generic density primitive (density.css exposes
152
+ * --density-line-height, --density-padding-inline, and the neutral vertical rungs
153
+ * --density-space-sm/-md/-lg) each of its own tokens follows. Density knows
154
+ * nothing about "field"; this is where the form makes that choice.
155
+ *
156
+ * Scoped to the density classes so a plain form (no density class) keeps the
157
+ * :root defaults above. The var() fallbacks keep values sane if only a CONTEXT
158
+ * class (.app/.site/.docs) is present without a density class.
159
+ *
160
+ * INLINE (horizontal): control padding + label↔input / prefix-suffix gap
161
+ * → --density-padding-inline
162
+ * BLOCK (vertical), by magnitude:
163
+ * between-fields → --density-space-lg (widest structural gap)
164
+ * label → control → --density-space-md (label to its own control)
165
+ * desc/error → input → --density-space-sm (tight annotation gap)
166
+ * All rungs are whole baseline multiples, so vertical rhythm holds. */
167
+ :where(.comfortable, .dense, .app, .site, .docs) {
168
+ --form-input-padding-inline: var(--density-padding-inline, var(--space-200));
169
+ --form-field-inline-gap: var(--density-padding-inline, var(--space-200));
170
+ --form-field-block-gap: var(
171
+ --density-space-lg,
172
+ calc(var(--baseline-height) * 6)
173
+ );
174
+ --form-field-label-gap: var(
175
+ --density-space-md,
176
+ calc(var(--baseline-height) * 4)
177
+ );
178
+ --form-group-gap: var(--density-space-sm, calc(var(--baseline-height) * 2));
179
+ }
180
+
139
181
  /* ── .ds.input.chrome — shared input chrome ─────────────────────────
140
182
  * Applied on native <textarea>/<select> directly, and on the
141
183
  * composite .ds.input.text wrapper for <input> + prefix/suffix.
@@ -236,7 +278,25 @@
236
278
  }
237
279
  }
238
280
 
239
- /* ── Danger — bottom border only (matches normal theme); focus shows all four */
281
+ /* ── Danger ──────────────────────────────────────────────────────────
282
+ * The field label recolours to the error token on any invalid field. This is
283
+ * the group-level affordance for controls whose payload has no single border to
284
+ * paint — notably the borderless `.ds.form-choices` fieldset, where the
285
+ * `<legend>` (a `.ds.field-label`) carries the error alongside the FieldError
286
+ * message, rather than lighting up every option box. */
287
+ .danger > .ds.field-label {
288
+ color: var(--form-error-color);
289
+
290
+ /* The required "*" marker recolours WITH the label (it pins its own colour to
291
+ * `--form-label-color` by default, so it must be overridden here). The
292
+ * "(optional)" hint keeps its muted colour — it is subordinate, not an error
293
+ * signal — via its own explicit `color` in the Label styles. */
294
+ &[data-required]::before {
295
+ color: var(--form-error-color);
296
+ }
297
+ }
298
+
299
+ /* Input chrome: bottom border only (matches normal theme); focus shows all four */
240
300
  .danger > .payload .ds.input.chrome {
241
301
  border-color: var(--form-input-border-color-error);
242
302
  }
@@ -0,0 +1,77 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button } from "@canonical/react-ds-global";
3
+ import { Label } from "../../subcomponent/Field/Label/index.js";
4
+ import { TextInput } from "../../subcomponent/TextInput/index.js";
5
+ import { SpikeBox, SpikeRows } from "./mocks.js";
6
+ import "./density.testbed.css";
7
+ import "./baseline-system.css";
8
+ /**
9
+ * Baseline-alignment spike harness (WORK IN PROGRESS)
10
+ *
11
+ * Line-based: each bucket renders as ONE horizontal line (its own story), with
12
+ * a few letters of paragraph-style text at the start (the baseline reference)
13
+ * followed by the components inline. No cards, no labels. The 4px baseline grid
14
+ * is supplied by the styles-debug plugin (story parameter).
15
+ */
16
+ /**
17
+ * A bucket = a short prose prefix + the components, laid out inline with the
18
+ * NORMAL component structure (no flattening, no overrides) so what we see is what
19
+ * ships. `align-items: baseline` lines them up; nothing else is customised.
20
+ */
21
+ const Line = ({ lead, children }) => (_jsx("div", { className: "density-testbed", children: _jsxs("div", { className: "density-testbed__row", children: [_jsx("p", { className: "p density-testbed__lead", children: lead }), children] }) }));
22
+ /** Controls bucket — real Button + a standalone Label and TextInput (used
23
+ * separately, so there's no stacked Field grid to flatten). */
24
+ export const ControlsLine = () => (_jsxs(Line, { lead: "Sample", children: [_jsx(Button, { importance: "primary", children: "Re" }), _jsx(Button, { importance: "secondary", children: "Se" }), _jsx(Label, { name: "n", children: "Label" }), _jsx(TextInput, { name: "n", placeholder: "In" })] }));
25
+ /** Navigation bucket — tab / side-nav item stand-ins on one line. */
26
+ export const NavigationLine = () => (_jsxs(Line, { lead: "Ov", children: [_jsx(SpikeBox, { children: "Ov" }), _jsx(SpikeBox, { children: "In" }), _jsx(SpikeBox, { children: "St" }), _jsx(SpikeBox, { children: "Ne" })] }));
27
+ /** Lists bucket — list/table rows (shared border) on one line. */
28
+ export const ListsLine = () => (_jsx(Line, { lead: "Ro", children: _jsx(SpikeRows, { rows: ["n1", "n2", "n3"] }) }));
29
+ const PROSE = "The quick brown fox jumps over the lazy dog. Pack my box with five dozen " +
30
+ "liquor jugs, and watch how each line of real prose seats itself on the 4px " +
31
+ "baseline grid as the size changes.";
32
+ /** The real typography tiers the engine styles — h1..h6 + p (mapper.css). No
33
+ * custom size classes: each tag IS its tier. */
34
+ const TIERS = ["h1", "h2", "h3", "h4", "h5", "h6", "p"];
35
+ /**
36
+ * Typography bucket — pure engine output, using the package's own tags (h1..h6,
37
+ * p). First an inline row of each tier side by side (to compare their baselines),
38
+ * then full stacked paragraphs of each tier (to witness how a real prose block
39
+ * of each tier sits on the 4px grid).
40
+ */
41
+ export const TypographyLine = () => (_jsxs("div", { className: "density-testbed", children: [_jsx("div", { className: "density-testbed__type", children: TIERS.map((Tag) => (_jsx(Tag, { children: "The quick brown fox" }, Tag))) }), _jsx("div", { className: "density-testbed__prose", children: TIERS.map((Tag) => (_jsx(Tag, { children: PROSE }, Tag))) })] }));
42
+ const EDITORIAL_BODY = "Running prose belongs to the typography engine, not the density system. Each " +
43
+ "line keeps its tier's snapped line-height, so every baseline lands on the 4px " +
44
+ "grid — and, unlike a line-height:1 crush, WRAPPED lines stay on the grid too.";
45
+ /**
46
+ * Editorial bucket — a real `.editorial` prose document (mixed headings + body)
47
+ * rendered INSIDE the density scope the story toolbar applies. This witnesses the
48
+ * DS.04 composition: density seats controls, but leaves prose to the engine, so
49
+ * `.editorial` here keeps its natural multi-line leading, seats every line on the
50
+ * grid, AND gets its whole-baseline inter-block margins (--space-after) — with no
51
+ * density override fighting it. Flip context/density in the toolbar: the prose
52
+ * rhythm must NOT change (it is engine-owned), proving density and editorial
53
+ * compose rather than collide.
54
+ */
55
+ export const EditorialLine = () => (_jsx("div", { className: "density-testbed", children: _jsxs("article", { className: "editorial density-testbed__prose", children: [_jsx("h2", { children: "Editorial composes with density" }), _jsx("p", { children: EDITORIAL_BODY }), _jsx("h3", { children: "Inter-block rhythm" }), _jsx("p", { children: PROSE }), _jsx("p", { children: "A second paragraph, so the `--space-after` margin between blocks is visible: each block still opens and closes on a grid line." })] }) }));
56
+ /** Deliberately off-scale sizes — none is a tier. Each is only a `.baseline`
57
+ * element with an inline font-size; if they all seat on the grid, `.baseline`
58
+ * is genuinely size-agnostic (DS.01). */
59
+ const OFF_SCALE = [19, 27, 35, 43, 53, 61];
60
+ /**
61
+ * DS.01 proof — the size-agnostic `.baseline` class. A row of arbitrary,
62
+ * off-scale font sizes, each snapped to the 4px grid by `.baseline` alone (no
63
+ * tier, no engine size class). The tags h1..h6/p are untouched and still nudge
64
+ * by default — this is additive.
65
+ */
66
+ export const BaselineProofLine = () => (_jsx("div", { className: "density-testbed", children: _jsx("div", { className: "baseline-proof", children: OFF_SCALE.map((px) => (_jsxs("span", { className: "baseline", style: { fontSize: `${px}px` }, children: [px, "px"] }, px))) }) }));
67
+ /** Mixed sizes in the density box, at both densities. Kept within what a dense
68
+ * (24px) / comfortable (32px) line-height can hold without clipping. */
69
+ const BOXED_SIZES = [16, 18, 20, 22];
70
+ /**
71
+ * DS.02 proof — `.spike-baseline-boxed` (PROTOTYPE, not core API). Two density
72
+ * line-heights: dense (24px) and comfortable (32px). Each box snaps to the grid
73
+ * via the existing start/end nudge; top-referenced, so the boxes share the top
74
+ * rhythm (a fixed baseline-from-bottom is NOT what the existing calc produces).
75
+ */
76
+ export const BoxedProofLine = () => (_jsx("div", { className: "density-testbed", children: ["is-dense", "is-comfortable"].map((density) => (_jsx("div", { className: `boxed-proof ${density}`, children: BOXED_SIZES.map((px) => (_jsx("span", { className: "baseline spike-baseline-boxed", style: { fontSize: `${px}px` }, children: px }, px))) }, density))) }));
77
+ //# sourceMappingURL=Testbed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Testbed.js","sourceRoot":"","sources":["../../../../../src/lib/_work_in_progress/DensityTestbed/Testbed.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,yCAAyC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,uBAAuB,CAAC;AAC/B,OAAO,uBAAuB,CAAC;AAE/B;;;;;;;GAOG;AAEH;;;;GAIG;AACH,MAAM,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAyC,EAAE,EAAE,CAAC,CAC1E,cAAK,SAAS,EAAC,iBAAiB,YAC9B,eAAK,SAAS,EAAC,sBAAsB,aAOnC,YAAG,SAAS,EAAC,yBAAyB,YAAE,IAAI,GAAK,EAChD,QAAQ,IACL,GACF,CACP,CAAC;AAEF;gEACgE;AAChE,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,CAChC,MAAC,IAAI,IAAC,IAAI,EAAC,QAAQ,aACjB,KAAC,MAAM,IAAC,UAAU,EAAC,SAAS,mBAAY,EACxC,KAAC,MAAM,IAAC,UAAU,EAAC,WAAW,mBAAY,EAC1C,KAAC,KAAK,IAAC,IAAI,EAAC,GAAG,sBAAc,EAC7B,KAAC,SAAS,IAAC,IAAI,EAAC,GAAG,EAAC,WAAW,EAAC,IAAI,GAAG,IAClC,CACR,CAAC;AAEF,qEAAqE;AACrE,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,CAClC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baseline MODEL now lives in the package: src/density.css
5
+ * (imported by src/index.css), so real components consume it by default. This
6
+ * file keeps only the TESTBED-ONLY helpers: the size-agnostic `.baseline` proof
7
+ * class and the `.spike-baseline-boxed` prototype + their proof surfaces.
8
+ */
9
+
10
+ /* ── DS.01 — .baseline: snap any element to the grid, whatever its size ──────
11
+ * Reads whatever --font-size / --line-height is present and computes the same
12
+ * cap-unit nudges the engine uses on h1..h6/p, without assigning a tier. The
13
+ * maths is font-relative, so it holds at any size. */
14
+ .baseline {
15
+ --bl-line-height-ratio: var(--line-height-ratio, 1.4);
16
+ --bl-computed-line-height: var(
17
+ --line-height,
18
+ round(up, calc(1em * var(--bl-line-height-ratio)), var(--baseline-height))
19
+ );
20
+ line-height: var(--bl-computed-line-height);
21
+
22
+ --bl-baseline-position: calc((var(--bl-computed-line-height) + 1cap) / 2);
23
+ --bl-start-nudge: calc(
24
+ var(--baseline-height) -
25
+ mod(var(--bl-baseline-position), var(--baseline-height))
26
+ );
27
+ --bl-end-nudge: calc(var(--baseline-height) - var(--bl-start-nudge));
28
+
29
+ padding-block-start: var(--bl-start-nudge);
30
+ padding-block-end: var(--bl-end-nudge);
31
+ margin-block: 0;
32
+ }
33
+
34
+ /* ── DS.02 — .spike-baseline-boxed: PROTOTYPE ONLY, NOT CORE API ─────────────
35
+ * `.baseline` with a density-chosen line-height; the box height is snapped to the
36
+ * grid (intrinsic snap via calc-size where supported, fixed grid-multiple
37
+ * fallback). Testbed only; never export. */
38
+ .spike-baseline-boxed {
39
+ --line-height: var(--density-line-height, calc(var(--baseline-height) * 6));
40
+ box-sizing: border-box;
41
+ block-size: var(--density-line-height, calc(var(--baseline-height) * 6));
42
+ }
43
+ @supports (block-size: calc-size(min-content, size)) {
44
+ .spike-baseline-boxed {
45
+ block-size: calc-size(min-content, round(up, size, var(--baseline-height)));
46
+ }
47
+ }
48
+
49
+ /* ── Proof surface for .baseline (DS.01) — off-scale sizes on one line ─────── */
50
+ .baseline-proof {
51
+ display: flex;
52
+ align-items: flex-start;
53
+ gap: calc(var(--baseline-height) * 4);
54
+ overflow-x: auto;
55
+ white-space: nowrap;
56
+ }
57
+ .baseline-proof > .baseline {
58
+ font-family: inherit;
59
+ }
60
+
61
+ /* ── Proof surface for .spike-baseline-boxed (DS.02) — mixed sizes, 2 densities ── */
62
+ .boxed-proof {
63
+ display: flex;
64
+ align-items: flex-start;
65
+ gap: calc(var(--baseline-height) * 3);
66
+ overflow-x: auto;
67
+ white-space: nowrap;
68
+ margin-block: calc(var(--baseline-height) * 2);
69
+ }
70
+ .boxed-proof > .spike-baseline-boxed {
71
+ border: 1px solid var(--color-border, #b3b3b3);
72
+ border-radius: var(--dimension-radius-100, 0.25rem);
73
+ padding-inline: calc(var(--baseline-height) * 2);
74
+ background: transparent; /* let the grid overlay show through */
75
+ }
76
+ .boxed-proof.is-dense {
77
+ --density-line-height: calc(var(--baseline-height) * 6); /* 24px */
78
+ }
79
+ .boxed-proof.is-comfortable {
80
+ --density-line-height: calc(var(--baseline-height) * 8); /* 32px */
81
+ }