@canonical/react-ds-global-form 0.36.0 → 0.38.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 (126) hide show
  1. package/README.md +40 -0
  2. package/dist/esm/density.css +320 -302
  3. package/dist/esm/docs/examples/density-examples.css +19 -14
  4. package/dist/esm/index.css +361 -335
  5. package/dist/esm/lib/_work_in_progress/DensityTestbed/baseline-system.css +71 -64
  6. package/dist/esm/lib/_work_in_progress/DensityTestbed/density.testbed.css +127 -123
  7. package/dist/esm/lib/common/Wrapper/ToggleWrapper.css +73 -54
  8. package/dist/esm/lib/common/Wrapper/styles.css +35 -31
  9. package/dist/esm/lib/component/ChoicesField/common/Option/Option.js +4 -1
  10. package/dist/esm/lib/component/ChoicesField/common/Option/Option.js.map +1 -1
  11. package/dist/esm/lib/component/ChoicesField/styles.css +195 -163
  12. package/dist/esm/lib/component/RangeField/common/RangeControl/styles.css +39 -35
  13. package/dist/esm/lib/component/RichChoicesField/styles.css +93 -89
  14. package/dist/esm/lib/index.js +2 -0
  15. package/dist/esm/lib/index.js.map +1 -1
  16. package/dist/esm/lib/subcomponent/CheckboxInput/styles.css +115 -111
  17. package/dist/esm/lib/subcomponent/ColorInput/styles.css +177 -173
  18. package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js +2 -1
  19. package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js.map +1 -1
  20. package/dist/esm/lib/subcomponent/ComboboxInput/common/List/List.js +1 -1
  21. package/dist/esm/lib/subcomponent/ComboboxInput/common/List/List.js.map +1 -1
  22. package/dist/esm/lib/subcomponent/ComboboxInput/common/List/styles.css +33 -29
  23. package/dist/esm/lib/subcomponent/ComboboxInput/common/ResetButton/styles.css +21 -17
  24. package/dist/esm/lib/subcomponent/ComboboxInput/styles.css +59 -55
  25. package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js +0 -1
  26. package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js.map +1 -1
  27. package/dist/esm/lib/subcomponent/DateInput/styles.css +23 -19
  28. package/dist/esm/lib/subcomponent/DateTimeInput/styles.css +24 -20
  29. package/dist/esm/lib/subcomponent/Field/Description/styles.css +9 -5
  30. package/dist/esm/lib/subcomponent/Field/Error/styles.css +9 -5
  31. package/dist/esm/lib/subcomponent/Field/Label/Label.js +2 -2
  32. package/dist/esm/lib/subcomponent/Field/Label/Label.js.map +1 -1
  33. package/dist/esm/lib/subcomponent/Field/Label/styles.css +25 -21
  34. package/dist/esm/lib/subcomponent/FileUploadInput/styles.css +125 -119
  35. package/dist/esm/lib/subcomponent/NumberInput/styles.css +32 -28
  36. package/dist/esm/lib/subcomponent/PasswordInput/styles.css +58 -54
  37. package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js +44 -20
  38. package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js.map +1 -1
  39. package/dist/esm/lib/subcomponent/PhoneInput/styles.css +53 -49
  40. package/dist/esm/lib/subcomponent/RadioInput/styles.css +70 -66
  41. package/dist/esm/lib/subcomponent/RangeInput/styles.css +74 -70
  42. package/dist/esm/lib/subcomponent/RatingInput/styles.css +132 -128
  43. package/dist/esm/lib/subcomponent/SelectInput/styles.css +44 -40
  44. package/dist/esm/lib/subcomponent/SwitchInput/styles.css +90 -86
  45. package/dist/esm/lib/subcomponent/TextInput/styles.css +30 -26
  46. package/dist/esm/lib/subcomponent/TextareaInput/styles.css +14 -10
  47. package/dist/esm/lib/subcomponent/TimeInput/styles.css +19 -15
  48. package/dist/esm/lib/utils/countries/index.js +3 -3
  49. package/dist/esm/lib/utils/countries/index.js.map +1 -1
  50. package/dist/esm/lib/utils/formatter/applyPattern.js +38 -0
  51. package/dist/esm/lib/utils/formatter/applyPattern.js.map +1 -0
  52. package/dist/esm/lib/utils/formatter/createFormatterRegisterOptions.js +22 -0
  53. package/dist/esm/lib/utils/formatter/createFormatterRegisterOptions.js.map +1 -0
  54. package/dist/esm/lib/utils/formatter/createPatternFormatter.js +25 -0
  55. package/dist/esm/lib/utils/formatter/createPatternFormatter.js.map +1 -0
  56. package/dist/esm/lib/utils/formatter/index.js +8 -0
  57. package/dist/esm/lib/utils/formatter/index.js.map +1 -0
  58. package/dist/esm/lib/utils/formatter/stripToDigits.js +12 -0
  59. package/dist/esm/lib/utils/formatter/stripToDigits.js.map +1 -0
  60. package/dist/esm/lib/utils/formatter/types.js +2 -0
  61. package/dist/esm/lib/utils/formatter/types.js.map +1 -0
  62. package/dist/esm/lib/utils/hooks/index.js +1 -0
  63. package/dist/esm/lib/utils/hooks/index.js.map +1 -1
  64. package/dist/esm/lib/utils/hooks/types.js +2 -0
  65. package/dist/esm/lib/utils/hooks/types.js.map +1 -0
  66. package/dist/esm/lib/utils/hooks/useFormattedValue.js +195 -0
  67. package/dist/esm/lib/utils/hooks/useFormattedValue.js.map +1 -0
  68. package/dist/esm/lib/utils/index.js +6 -2
  69. package/dist/esm/lib/utils/index.js.map +1 -1
  70. package/dist/esm/lib/utils/mergeRefs.js +25 -0
  71. package/dist/esm/lib/utils/mergeRefs.js.map +1 -0
  72. package/dist/esm/lib/utils/middleware/addRESTValidation.js +1 -1
  73. package/dist/esm/lib/utils/middleware/addRESTValidation.js.map +1 -1
  74. package/dist/types/lib/component/ChoicesField/common/Option/Option.d.ts.map +1 -1
  75. package/dist/types/lib/component/PhoneField/PhoneField.d.ts +2 -1
  76. package/dist/types/lib/component/PhoneField/PhoneField.d.ts.map +1 -1
  77. package/dist/types/lib/index.d.ts +4 -0
  78. package/dist/types/lib/index.d.ts.map +1 -1
  79. package/dist/types/lib/subcomponent/ComboboxInput/SingleCombobox.d.ts.map +1 -1
  80. package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts +0 -1
  81. package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts.map +1 -1
  82. package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts +19 -2
  83. package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts.map +1 -1
  84. package/dist/types/lib/subcomponent/PhoneInput/types.d.ts +20 -7
  85. package/dist/types/lib/subcomponent/PhoneInput/types.d.ts.map +1 -1
  86. package/dist/types/lib/utils/countries/index.d.ts +0 -3
  87. package/dist/types/lib/utils/countries/index.d.ts.map +1 -1
  88. package/dist/types/lib/utils/formatter/applyPattern.d.ts +17 -0
  89. package/dist/types/lib/utils/formatter/applyPattern.d.ts.map +1 -0
  90. package/dist/types/lib/utils/formatter/createFormatterRegisterOptions.d.ts +20 -0
  91. package/dist/types/lib/utils/formatter/createFormatterRegisterOptions.d.ts.map +1 -0
  92. package/dist/types/lib/utils/formatter/createPatternFormatter.d.ts +19 -0
  93. package/dist/types/lib/utils/formatter/createPatternFormatter.d.ts.map +1 -0
  94. package/dist/types/lib/utils/formatter/index.d.ts +6 -0
  95. package/dist/types/lib/utils/formatter/index.d.ts.map +1 -0
  96. package/dist/types/lib/utils/formatter/stripToDigits.d.ts +10 -0
  97. package/dist/types/lib/utils/formatter/stripToDigits.d.ts.map +1 -0
  98. package/dist/types/lib/utils/formatter/types.d.ts +30 -0
  99. package/dist/types/lib/utils/formatter/types.d.ts.map +1 -0
  100. package/dist/types/lib/utils/hooks/index.d.ts +2 -0
  101. package/dist/types/lib/utils/hooks/index.d.ts.map +1 -1
  102. package/dist/types/lib/utils/hooks/types.d.ts +33 -0
  103. package/dist/types/lib/utils/hooks/types.d.ts.map +1 -0
  104. package/dist/types/lib/utils/hooks/useFormattedValue.d.ts +30 -0
  105. package/dist/types/lib/utils/hooks/useFormattedValue.d.ts.map +1 -0
  106. package/dist/types/lib/utils/index.d.ts +2 -0
  107. package/dist/types/lib/utils/index.d.ts.map +1 -1
  108. package/dist/types/lib/utils/mergeRefs.d.ts +14 -0
  109. package/dist/types/lib/utils/mergeRefs.d.ts.map +1 -0
  110. package/package.json +17 -16
  111. package/dist/esm/lib/subcomponent/ComboboxInput/utils/mergeRefs.js +0 -12
  112. package/dist/esm/lib/subcomponent/ComboboxInput/utils/mergeRefs.js.map +0 -1
  113. package/dist/esm/lib/utils/countries/applyPhoneMask.js +0 -35
  114. package/dist/esm/lib/utils/countries/applyPhoneMask.js.map +0 -1
  115. package/dist/esm/lib/utils/countries/phoneRegisterOptions.js +0 -18
  116. package/dist/esm/lib/utils/countries/phoneRegisterOptions.js.map +0 -1
  117. package/dist/esm/lib/utils/countries/removePhoneMask.js +0 -12
  118. package/dist/esm/lib/utils/countries/removePhoneMask.js.map +0 -1
  119. package/dist/types/lib/subcomponent/ComboboxInput/utils/mergeRefs.d.ts +0 -3
  120. package/dist/types/lib/subcomponent/ComboboxInput/utils/mergeRefs.d.ts.map +0 -1
  121. package/dist/types/lib/utils/countries/applyPhoneMask.d.ts +0 -14
  122. package/dist/types/lib/utils/countries/applyPhoneMask.d.ts.map +0 -1
  123. package/dist/types/lib/utils/countries/phoneRegisterOptions.d.ts +0 -14
  124. package/dist/types/lib/utils/countries/phoneRegisterOptions.d.ts.map +0 -1
  125. package/dist/types/lib/utils/countries/removePhoneMask.d.ts +0 -10
  126. package/dist/types/lib/utils/countries/removePhoneMask.d.ts.map +0 -1
@@ -5,77 +5,84 @@
5
5
  * (imported by src/index.css), so real components consume it by default. This
6
6
  * file keeps only the TESTBED-ONLY helpers: the size-agnostic `.baseline` proof
7
7
  * class and the `.spike-baseline-boxed` prototype + their proof surfaces.
8
+ *
9
+ * Layer: ds.components.global (@canonical/styles README, "Cascade layers").
8
10
  */
9
11
 
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);
12
+ @layer ds.components.global {
13
+ /* ── DS.01 — .baseline: snap any element to the grid, whatever its size ──────
14
+ * Reads whatever --font-size / --line-height is present and computes the same
15
+ * cap-unit nudges the engine uses on h1..h6/p, without assigning a tier. The
16
+ * maths is font-relative, so it holds at any size. */
17
+ .baseline {
18
+ --bl-line-height-ratio: var(--line-height-ratio, 1.4);
19
+ --bl-computed-line-height: var(
20
+ --line-height,
21
+ round(up, calc(1em * var(--bl-line-height-ratio)), var(--baseline-height))
22
+ );
23
+ line-height: var(--bl-computed-line-height);
21
24
 
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));
25
+ --bl-baseline-position: calc((var(--bl-computed-line-height) + 1cap) / 2);
26
+ --bl-start-nudge: calc(
27
+ var(--baseline-height) -
28
+ mod(var(--bl-baseline-position), var(--baseline-height))
29
+ );
30
+ --bl-end-nudge: calc(var(--baseline-height) - var(--bl-start-nudge));
28
31
 
29
- padding-block-start: var(--bl-start-nudge);
30
- padding-block-end: var(--bl-end-nudge);
31
- margin-block: 0;
32
- }
32
+ padding-block-start: var(--bl-start-nudge);
33
+ padding-block-end: var(--bl-end-nudge);
34
+ margin-block: 0;
35
+ }
33
36
 
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)) {
37
+ /* ── DS.02 — .spike-baseline-boxed: PROTOTYPE ONLY, NOT CORE API ─────────────
38
+ * `.baseline` with a density-chosen line-height; the box height is snapped to the
39
+ * grid (intrinsic snap via calc-size where supported, fixed grid-multiple
40
+ * fallback). Testbed only; never export. */
44
41
  .spike-baseline-boxed {
45
- block-size: calc-size(min-content, round(up, size, var(--baseline-height)));
42
+ --line-height: var(--density-line-height, calc(var(--baseline-height) * 6));
43
+ box-sizing: border-box;
44
+ block-size: var(--density-line-height, calc(var(--baseline-height) * 6));
45
+ }
46
+ @supports (block-size: calc-size(min-content, size)) {
47
+ .spike-baseline-boxed {
48
+ block-size: calc-size(
49
+ min-content,
50
+ round(up, size, var(--baseline-height))
51
+ );
52
+ }
46
53
  }
47
- }
48
54
 
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
- }
55
+ /* ── Proof surface for .baseline (DS.01) — off-scale sizes on one line ─────── */
56
+ .baseline-proof {
57
+ display: flex;
58
+ align-items: flex-start;
59
+ gap: calc(var(--baseline-height) * 4);
60
+ overflow-x: auto;
61
+ white-space: nowrap;
62
+ }
63
+ .baseline-proof > .baseline {
64
+ font-family: inherit;
65
+ }
60
66
 
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 */
67
+ /* ── Proof surface for .spike-baseline-boxed (DS.02) — mixed sizes, 2 densities ── */
68
+ .boxed-proof {
69
+ display: flex;
70
+ align-items: flex-start;
71
+ gap: calc(var(--baseline-height) * 3);
72
+ overflow-x: auto;
73
+ white-space: nowrap;
74
+ margin-block: calc(var(--baseline-height) * 2);
75
+ }
76
+ .boxed-proof > .spike-baseline-boxed {
77
+ border: 1px solid var(--color-border, #b3b3b3);
78
+ border-radius: var(--dimension-radius-100, 0.25rem);
79
+ padding-inline: calc(var(--baseline-height) * 2);
80
+ background: transparent; /* let the grid overlay show through */
81
+ }
82
+ .boxed-proof.is-dense {
83
+ --density-line-height: calc(var(--baseline-height) * 6); /* 24px */
84
+ }
85
+ .boxed-proof.is-comfortable {
86
+ --density-line-height: calc(var(--baseline-height) * 8); /* 32px */
87
+ }
81
88
  }
@@ -14,140 +14,144 @@
14
14
  * The baseline grid overlay comes from the styles-debug plugin (story
15
15
  * `parameters.baseline`); the box seat uses the shipped engine model (the
16
16
  * alternative top-align + external-margin model lives in SPIKE.md).
17
+ *
18
+ * Layer: ds.components.global (@canonical/styles README, "Cascade layers").
17
19
  */
18
20
 
19
- /* ── The testbed root ── */
20
- .density-testbed {
21
- /* --baseline-height is 4px. Source of truth, in order:
22
- 1. @canonical/styles-typography's baseline-shim.css registers it via
23
- `@property … initial-value: 0.25rem`, so the engine ALWAYS has 4px even
24
- if styles-main did not load (order-independent — learned from the
25
- typography example, which loads an engine standalone). Then
26
- 2. @canonical/styles' spacing.css sets it explicitly to 0.25rem when present.
27
- The literal fallback below is belt-and-suspenders; the @property makes it
28
- redundant. Nothing to override here. */
29
- padding: 0 var(--baseline-height, 0.25rem);
30
- color: var(--color-text, #1a1a1a);
31
- }
21
+ @layer ds.components.global {
22
+ /* ── The testbed root ── */
23
+ .density-testbed {
24
+ /* --baseline-height is 4px. Source of truth, in order:
25
+ 1. @canonical/styles-typography's baseline-shim.css registers it via
26
+ `@property … initial-value: 0.25rem`, so the engine ALWAYS has 4px even
27
+ if styles-main did not load (order-independent — learned from the
28
+ typography example, which loads an engine standalone). Then
29
+ 2. @canonical/styles' spacing.css sets it explicitly to 0.25rem when present.
30
+ The literal fallback below is belt-and-suspenders; the @property makes it
31
+ redundant. Nothing to override here. */
32
+ padding: 0 var(--baseline-height, 0.25rem);
33
+ color: var(--color-text, #1a1a1a);
34
+ }
32
35
 
33
- /* ───────────────────────────────────────────────────────────────────────────
34
- * Bucket row — REGULAR component layout, no flattening or overrides
35
- *
36
- * A simple inline row: a short prose lead, then the components in their NORMAL
37
- * structure laid inline. Controls are top-referenced density boxes (the density
38
- * system seats each one's text on the grid INTERNALLY), so the row aligns the
39
- * boxes by their TOPS. No block padding — the row must sit at the canvas origin
40
- * so what we read is the density system's own grid registration, not a nudge. */
41
- .density-testbed__row {
42
- display: flex;
43
- flex-wrap: nowrap; /* one horizontal line — overflow scrolls, never wraps */
44
- align-items: flex-start;
45
- gap: calc(var(--baseline-height) * 3); /* 12px */
46
- overflow-x: auto;
47
- }
48
- .density-testbed__row > * {
49
- flex: 0 0 auto; /* natural width, don't grow/shrink; the row scrolls instead */
50
- }
51
- .density-testbed__row > .p {
52
- margin: 0;
53
- }
36
+ /* ───────────────────────────────────────────────────────────────────────────
37
+ * Bucket row — REGULAR component layout, no flattening or overrides
38
+ *
39
+ * A simple inline row: a short prose lead, then the components in their NORMAL
40
+ * structure laid inline. Controls are top-referenced density boxes (the density
41
+ * system seats each one's text on the grid INTERNALLY), so the row aligns the
42
+ * boxes by their TOPS. No block padding — the row must sit at the canvas origin
43
+ * so what we read is the density system's own grid registration, not a nudge. */
44
+ .density-testbed__row {
45
+ display: flex;
46
+ flex-wrap: nowrap; /* one horizontal line — overflow scrolls, never wraps */
47
+ align-items: flex-start;
48
+ gap: calc(var(--baseline-height) * 3); /* 12px */
49
+ overflow-x: auto;
50
+ }
51
+ .density-testbed__row > * {
52
+ flex: 0 0 auto; /* natural width, don't grow/shrink; the row scrolls instead */
53
+ }
54
+ .density-testbed__row > .p {
55
+ margin: 0;
56
+ }
54
57
 
55
- /* Re-seat the reference LEAD to the density target (TESTBED ONLY) ──────────────
56
- * Prose is engine-seated now (Stage A), which lands it on the NEAREST grid line —
57
- * one baseline off from the controls' density TARGET line. The lead only exists to
58
- * be read against the controls, so here (and only here) we opt it back into the
59
- * exact density seat the controls use: crush to line-height 1, then pad the top by
60
- * the same `target − (1em+1cap)/2` the shipping controls use. This is calibration
61
- * of a measuring stick, NOT a change to how prose ships. */
62
- .density-testbed__row > .density-testbed__lead.p {
63
- line-height: 1;
64
- padding-block-start: max(
65
- 0px,
66
- calc(var(--density-target-baseline-px, 0px) - calc((1em + 1cap) / 2))
67
- );
68
- padding-block-end: 0;
69
- }
58
+ /* Re-seat the reference LEAD to the density target (TESTBED ONLY) ──────────────
59
+ * Prose is engine-seated now (Stage A), which lands it on the NEAREST grid line —
60
+ * one baseline off from the controls' density TARGET line. The lead only exists to
61
+ * be read against the controls, so here (and only here) we opt it back into the
62
+ * exact density seat the controls use: crush to line-height 1, then pad the top by
63
+ * the same `target − (1em+1cap)/2` the shipping controls use. This is calibration
64
+ * of a measuring stick, NOT a change to how prose ships. */
65
+ .density-testbed__row > .density-testbed__lead.p {
66
+ line-height: 1;
67
+ padding-block-start: max(
68
+ 0px,
69
+ calc(var(--density-target-baseline-px, 0px) - calc((1em + 1cap) / 2))
70
+ );
71
+ padding-block-end: 0;
72
+ }
70
73
 
71
- /* ───────────────────────────────────────────────────────────────────────────
72
- * Boxed controls — the two alignment models
73
- *
74
- * `.spike-box` is a bordered box whose interior is a single line of `.p` text
75
- * (button label, input value, nav item, table cell). Inline-block so it sits on
76
- * the line. The text seat reads the engine's --start-nudge / --end-nudge.
77
- * ─────────────────────────────────────────────────────────────────────────── */
78
- .density-testbed .spike-box {
79
- --box-border-width: 1px;
80
- --box-padding-inline: var(--density-padding-inline, 0.75rem);
74
+ /* ───────────────────────────────────────────────────────────────────────────
75
+ * Boxed controls — the two alignment models
76
+ *
77
+ * `.spike-box` is a bordered box whose interior is a single line of `.p` text
78
+ * (button label, input value, nav item, table cell). Inline-block so it sits on
79
+ * the line. The text seat reads the engine's --start-nudge / --end-nudge.
80
+ * ─────────────────────────────────────────────────────────────────────────── */
81
+ .density-testbed .spike-box {
82
+ --box-border-width: 1px;
83
+ --box-padding-inline: var(--density-padding-inline, 0.75rem);
81
84
 
82
- display: inline-flex;
83
- align-items: stretch;
84
- box-sizing: border-box;
85
- vertical-align: baseline;
86
- border: var(--box-border-width) solid var(--color-border, #b3b3b3);
87
- border-radius: var(--dimension-radius-100, 0.25rem);
88
- padding-inline: var(--box-padding-inline);
89
- background: var(--color-background, #fff);
90
- }
85
+ display: inline-flex;
86
+ align-items: stretch;
87
+ box-sizing: border-box;
88
+ vertical-align: baseline;
89
+ border: var(--box-border-width) solid var(--color-border, #b3b3b3);
90
+ border-radius: var(--dimension-radius-100, 0.25rem);
91
+ padding-inline: var(--box-padding-inline);
92
+ background: var(--color-background, #fff);
93
+ }
91
94
 
92
- .density-testbed .spike-box > .seat {
93
- display: block;
94
- white-space: nowrap;
95
- }
95
+ .density-testbed .spike-box > .seat {
96
+ display: block;
97
+ white-space: nowrap;
98
+ }
96
99
 
97
- /* Shared-border stack (list/table rows) — laid horizontally on the line here,
98
- each cell a box; the shared-border collapse is between inline siblings. */
99
- .density-testbed .spike-rows {
100
- display: inline-flex;
101
- vertical-align: baseline;
102
- }
103
- .density-testbed .spike-rows > .spike-box {
104
- border-radius: 0;
105
- }
106
- .density-testbed .spike-rows > .spike-box + .spike-box {
107
- border-inline-start: none;
108
- }
100
+ /* Shared-border stack (list/table rows) — laid horizontally on the line here,
101
+ each cell a box; the shared-border collapse is between inline siblings. */
102
+ .density-testbed .spike-rows {
103
+ display: inline-flex;
104
+ vertical-align: baseline;
105
+ }
106
+ .density-testbed .spike-rows > .spike-box {
107
+ border-radius: 0;
108
+ }
109
+ .density-testbed .spike-rows > .spike-box + .spike-box {
110
+ border-inline-start: none;
111
+ }
109
112
 
110
- /* Box seat — the shipped engine model: engine's asymmetric nudges, both borders
111
- * on the grid. (The current/proposed model toggle was removed; the alternative
112
- * top-align + external-margin model is documented in SPIKE.md.) */
113
- .density-testbed .spike-box > .seat {
114
- padding-block-start: var(--start-nudge);
115
- padding-block-end: var(--end-nudge);
116
- }
113
+ /* Box seat — the shipped engine model: engine's asymmetric nudges, both borders
114
+ * on the grid. (The current/proposed model toggle was removed; the alternative
115
+ * top-align + external-margin model is documented in SPIKE.md.) */
116
+ .density-testbed .spike-box > .seat {
117
+ padding-block-start: var(--start-nudge);
118
+ padding-block-end: var(--end-nudge);
119
+ }
117
120
 
118
- /* ───────────────────────────────────────────────────────────────────────────
119
- * Typography bucket (TODO 5) — real paragraph text at several sizes on one line,
120
- * to witness how the 4px baseline affects cap-based nudges (TODO 6). Inline so
121
- * the sizes sit next to each other and can be read against the grid together.
122
- * ─────────────────────────────────────────────────────────────────────────── */
123
- .density-testbed__type {
124
- display: flex;
125
- align-items: flex-start;
126
- gap: calc(var(--baseline-height) * 4);
127
- overflow-x: auto;
128
- white-space: nowrap;
129
- padding-block: calc(var(--baseline-height) * 2);
130
- }
121
+ /* ───────────────────────────────────────────────────────────────────────────
122
+ * Typography bucket (TODO 5) — real paragraph text at several sizes on one line,
123
+ * to witness how the 4px baseline affects cap-based nudges (TODO 6). Inline so
124
+ * the sizes sit next to each other and can be read against the grid together.
125
+ * ─────────────────────────────────────────────────────────────────────────── */
126
+ .density-testbed__type {
127
+ display: flex;
128
+ align-items: flex-start;
129
+ gap: calc(var(--baseline-height) * 4);
130
+ overflow-x: auto;
131
+ white-space: nowrap;
132
+ padding-block: calc(var(--baseline-height) * 2);
133
+ }
131
134
 
132
- /* Stacked full paragraphs of each tier, one after another, below the inline
133
- row — so a real prose BLOCK of each tier can be read against the grid. */
134
- .density-testbed__prose {
135
- max-width: 40rem;
136
- margin-top: calc(var(--baseline-height) * 4);
137
- }
135
+ /* Stacked full paragraphs of each tier, one after another, below the inline
136
+ row — so a real prose BLOCK of each tier can be read against the grid. */
137
+ .density-testbed__prose {
138
+ max-width: 40rem;
139
+ margin-top: calc(var(--baseline-height) * 4);
140
+ }
138
141
 
139
- /* Both sections use the package's own tags (h1..h6, p). The engine sizes each
140
- tier; we only reset the demo margins so the grid reading is clean. No custom
141
- size classes — each tag IS its tier. */
142
- .density-testbed__type > :where(h1, h2, h3, h4, h5, h6, p),
143
- .density-testbed__prose > :where(h1, h2, h3, h4, h5, h6, p) {
144
- margin: 0;
145
- }
142
+ /* Both sections use the package's own tags (h1..h6, p). The engine sizes each
143
+ tier; we only reset the demo margins so the grid reading is clean. No custom
144
+ size classes — each tag IS its tier. */
145
+ .density-testbed__type > :where(h1, h2, h3, h4, h5, h6, p),
146
+ .density-testbed__prose > :where(h1, h2, h3, h4, h5, h6, p) {
147
+ margin: 0;
148
+ }
146
149
 
147
- /* ── Density inline lever (retained) ── */
148
- .density-comfortable {
149
- --density-padding-inline: 0.75rem;
150
- }
151
- .density-dense {
152
- --density-padding-inline: 0.5rem;
150
+ /* ── Density inline lever (retained) ── */
151
+ .density-comfortable {
152
+ --density-padding-inline: 0.75rem;
153
+ }
154
+ .density-dense {
155
+ --density-padding-inline: 0.5rem;
156
+ }
153
157
  }
@@ -1,64 +1,83 @@
1
- /* Toggle field layout, top to bottom: an optional heading, a control row where
2
- * the input sits inline with its label, then the description and any error. */
3
- .ds.field.field-toggle {
4
- display: flex;
5
- flex-direction: column;
6
- row-gap: var(--form-group-gap);
7
-
8
- /* The heading is a mock label (a <legend>): reset the fieldset default so it
9
- flows like the other block children. */
10
- & > .field-toggle-heading {
11
- padding: 0;
12
- }
13
-
14
- /* Control row: the control centres on the label's FIRST line, and a multi-line
15
- (sentence) label wraps below — never centring the box on the whole paragraph
16
- (AV-325). `align-items: start` tops the row so wrapped lines flow under the
17
- first; the control is then nudged down half a line-box to sit centred on the
18
- first line (see the control rule below). The first-line box is one density
19
- line-height (`--density-line-height-effective`, set on the density scope;
20
- falls back to `1lh` outside a density context). */
21
- & > .field-toggle-control {
22
- --toggle-control-line: var(--density-line-height-effective, 1lh);
1
+ /* Layer: ds.components.global (@canonical/styles README, "Cascade layers"). */
23
2
 
3
+ @layer ds.components.global {
4
+ /* Toggle field layout, top to bottom: an optional heading, a control row where
5
+ * the input sits inline with its label, then the description and any error. */
6
+ .ds.field.field-toggle {
24
7
  display: flex;
25
- flex-direction: row;
26
- align-items: start;
27
- column-gap: var(--form-field-inline-gap);
8
+ flex-direction: column;
9
+ row-gap: var(--form-group-gap);
28
10
 
29
- /* Every direct child that ISN'T the label is the control (checkbox / switch
30
- input): a fixed 16px-tall box (--dimension-200 — checkbox 16×16, switch
31
- track 16 high). Centre it on the first line by pushing it down half the
32
- leftover between the line-box and the control's own height. The control
33
- keeps its intrinsic size — only its vertical offset changes, so the click
34
- target is untouched. */
35
- & > :not(.ds.field-label) {
36
- --toggle-control-size: var(--dimension-200);
37
- align-self: start;
38
- margin-block-start: max(
39
- 0px,
40
- calc((var(--toggle-control-line) - var(--toggle-control-size)) / 2)
41
- );
11
+ /* The heading is a mock label (a <legend>): reset the fieldset default so it
12
+ flows like the other block children. */
13
+ & > .field-toggle-heading {
14
+ padding: 0;
42
15
  }
43
16
 
44
- /* The control label is often a full clickable sentence, so it reads as
45
- regular body prose (not the bold heading weight the field label uses by
46
- default): normal weight, left-aligned, pointer cursor, and it takes the
47
- remaining width so it wraps beside the control instead of pushing it. */
48
- & > .ds.field-label {
49
- flex: 1;
50
- min-width: 0;
51
- font-weight: var(--typography-text-primary-font-weight);
52
- text-align: start;
53
- cursor: pointer;
17
+ /* Control row: `align-items: center` centres the control on the row, and a
18
+ multi-line (sentence) label wraps below it (AV-325). Spacing belongs to
19
+ the FIELD, not the label or control: the row's column-gap separates
20
+ control and label, the field's row-gap separates the row from the
21
+ description/error, and neither label nor control carries any padding or
22
+ margin — so spacing changes never shift the control off-centre. */
23
+ & > .field-toggle-control {
24
+ --toggle-control-line: var(--density-line-height-effective, 1lh);
25
+
26
+ display: flex;
27
+ flex-direction: row;
28
+ align-items: center;
29
+ column-gap: var(--form-field-inline-gap);
30
+
31
+ /* Every direct child that ISN'T the label is the control (checkbox / switch
32
+ input): a fixed 16px-tall box (--dimension-200 — checkbox 16×16, switch
33
+ track 16 high). The row's `align-items: center` does the centring; the
34
+ control itself carries no offset, margin or padding, so its intrinsic
35
+ size and click target are unchanged. */
36
+ & > :not(.ds.field-label) {
37
+ --toggle-control-size: var(--dimension-200);
38
+ }
39
+
40
+ /* The control label is often a full clickable sentence, so it reads as
41
+ regular body prose (not the bold heading weight the field label uses by
42
+ default): normal weight, left-aligned, pointer cursor, and it takes the
43
+ remaining width so it wraps beside the control instead of pushing it.
44
+ `padding: 0` keeps the label flush with the control — spacing between
45
+ blocks is the field's row-gap, never label geometry. */
46
+ & > .ds.field-label {
47
+ flex: 1;
48
+ min-width: 0;
49
+ font-weight: var(--typography-text-primary-font-weight);
50
+ text-align: start;
51
+ cursor: pointer;
52
+ padding: 0;
53
+ }
54
+
55
+ /* Label BEFORE the control (switch convention): the DOM stays
56
+ control-then-label for accessibility, so `row-reverse` moves the control
57
+ to the trailing (right) edge and the label to the leading (left) edge.
58
+ Logical `row-reverse` mirrors correctly in RTL. */
59
+ &.label-before {
60
+ flex-direction: row-reverse;
61
+ }
54
62
  }
55
63
 
56
- /* Label BEFORE the control (switch convention): the DOM stays
57
- control-then-label for accessibility, so `row-reverse` moves the control
58
- to the trailing (right) edge and the label to the leading (left) edge.
59
- Logical `row-reverse` mirrors correctly in RTL. */
60
- &.label-before {
61
- flex-direction: row-reverse;
64
+ /* Disabled control: the row stops signalling clickable and the control
65
+ label takes the disabled text token (color.text.disabled) — color, not
66
+ an opacity dim of the whole row. State-driven via :has so no disabled
67
+ plumbing is needed on the wrapper (same idiom as the choices Option's
68
+ `.disabled` and RatingInput). */
69
+ &:has(> .field-toggle-control input:disabled) {
70
+ cursor: not-allowed;
71
+
72
+ & > .field-toggle-control > .ds.field-label {
73
+ color: var(--form-label-color-disabled, var(--color-text-disabled));
74
+ &[data-required]::after {
75
+ color: var(
76
+ --form-required-marker-color-disabled,
77
+ var(--form-label-color-disabled, var(--color-text-disabled))
78
+ );
79
+ }
80
+ }
62
81
  }
63
82
  }
64
83
  }
@@ -1,37 +1,41 @@
1
- .ds.field {
2
- display: grid;
3
- grid-template-columns: subgrid;
4
- grid-column: var(--form-field-columns, 1 / -1);
5
- /* Vertical gap from the label row down to the payload row. Uses the block-axis
6
- label-gap token — NOT --form-field-inline-gap (that is horizontal-only now).
7
- Default is the label→control gap (--form-field-label-gap, 8px); when a
8
- description LEADS the payload the row below tightens it to the label→
9
- description gap (--form-field-label-description-gap, 4px), per the 15/07
10
- review's field-spacing spec. */
11
- row-gap: var(--form-field-label-gap);
12
- align-items: baseline;
1
+ /* Layer: ds.components.global (@canonical/styles README, "Cascade layers"). */
13
2
 
14
- /* Label sits closer to a leading description than to a bare control. */
15
- &:has(> .payload > .ds.field-description:first-child) {
16
- row-gap: var(
17
- --form-field-label-description-gap,
18
- var(--form-field-label-gap)
19
- );
20
- }
21
-
22
- & > .ds.field-label {
23
- grid-column: var(--form-label-columns, 1 / -1);
24
- }
25
-
26
- & > .payload {
27
- grid-column: var(--form-payload-columns, 1 / -1);
3
+ @layer ds.components.global {
4
+ .ds.field {
28
5
  display: grid;
29
6
  grid-template-columns: subgrid;
30
- row-gap: var(--form-group-gap);
31
- }
7
+ grid-column: var(--form-field-columns, 1 / -1);
8
+ /* Vertical gap from the label row down to the payload row. Uses the block-axis
9
+ label-gap token — NOT --form-field-inline-gap (that is horizontal-only now).
10
+ Default is the label→control gap (--form-field-label-gap, 8px); when a
11
+ description LEADS the payload the row below tightens it to the label→
12
+ description gap (--form-field-label-description-gap, 4px), per the 15/07
13
+ review's field-spacing spec. */
14
+ row-gap: var(--form-field-label-gap);
15
+ align-items: baseline;
16
+
17
+ /* Label sits closer to a leading description than to a bare control. */
18
+ &:has(> .payload > .ds.field-description:first-child) {
19
+ row-gap: var(
20
+ --form-field-label-description-gap,
21
+ var(--form-field-label-gap)
22
+ );
23
+ }
24
+
25
+ & > .ds.field-label {
26
+ grid-column: var(--form-label-columns, 1 / -1);
27
+ }
28
+
29
+ & > .payload {
30
+ grid-column: var(--form-payload-columns, 1 / -1);
31
+ display: grid;
32
+ grid-template-columns: subgrid;
33
+ row-gap: var(--form-group-gap);
34
+ }
32
35
 
33
- /* Inputs that don't need columns span the full payload width */
34
- & > .payload > * {
35
- grid-column: 1 / -1;
36
+ /* Inputs that don't need columns span the full payload width */
37
+ & > .payload > * {
38
+ grid-column: 1 / -1;
39
+ }
36
40
  }
37
41
  }