@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
@@ -1,93 +1,97 @@
1
- .ds.range {
2
- appearance: none;
3
- width: 100%;
4
- /* Element box is as tall as the THUMB (16px), so the thumb and its focus
5
- * ring are never clipped in a flex row; the visible 8px track is painted by
6
- * the track pseudo-elements below, vertically centred within this box. */
7
- height: var(--dimension-200); /* 16px */
8
- background: transparent;
9
- border: none;
10
- outline: none;
11
- cursor: pointer;
1
+ /* Layer: ds.components.global (@canonical/styles README, "Cascade layers"). */
12
2
 
13
- /* WebKit/Chromium paints the bar via this pseudo-element, which keeps a UA
14
- * border even after `appearance: none` on the element — THIS is the visible
15
- * border. Style the track here: flat, no border, 8px tall. */
16
- &::-webkit-slider-runnable-track {
17
- height: var(--dimension-100); /* 8px */
18
- background: var(--color-foreground-slider-track);
19
- border: none;
20
- border-radius: var(--dimension-radius-small);
21
- }
22
-
23
- /* Firefox draws the track via its own pseudo-element with its own UA border —
24
- * zero it and paint the flat track here to match WebKit. */
25
- &::-moz-range-track {
26
- height: var(--dimension-100); /* 8px */
27
- background: var(--color-foreground-slider-track);
28
- border: none;
29
- border-radius: var(--dimension-radius-small);
30
- }
31
-
32
- &::-webkit-slider-thumb {
3
+ @layer ds.components.global {
4
+ .ds.range {
33
5
  appearance: none;
34
- width: var(--dimension-200); /* 16px */
6
+ width: 100%;
7
+ /* Element box is as tall as the THUMB (16px), so the thumb and its focus
8
+ * ring are never clipped in a flex row; the visible 8px track is painted by
9
+ * the track pseudo-elements below, vertically centred within this box. */
35
10
  height: var(--dimension-200); /* 16px */
36
- /* Re-centre the 16px thumb on the 8px runnable-track: (8 − 16) / 2 = −4px.
37
- Derived from the actual track/thumb dimension tokens, not the baseline unit. */
38
- margin-top: calc((var(--dimension-100) - var(--dimension-200)) / 2);
39
- border-radius: 50%;
40
- background: var(--color-foreground-slider-progress);
11
+ background: transparent;
41
12
  border: none;
13
+ outline: none;
42
14
  cursor: pointer;
43
- }
44
15
 
45
- &::-moz-range-thumb {
46
- width: var(--dimension-200); /* 16px */
47
- height: var(--dimension-200); /* 16px */
48
- border-radius: 50%;
49
- background: var(--color-foreground-slider-progress);
50
- border: none;
51
- cursor: pointer;
52
- }
16
+ /* WebKit/Chromium paints the bar via this pseudo-element, which keeps a UA
17
+ * border even after `appearance: none` on the element — THIS is the visible
18
+ * border. Style the track here: flat, no border, 8px tall. */
19
+ &::-webkit-slider-runnable-track {
20
+ height: var(--dimension-100); /* 8px */
21
+ background: var(--color-foreground-slider-track);
22
+ border: none;
23
+ border-radius: var(--dimension-radius-small);
24
+ }
53
25
 
54
- &:focus-visible {
55
- outline: none;
26
+ /* Firefox draws the track via its own pseudo-element with its own UA border —
27
+ * zero it and paint the flat track here to match WebKit. */
28
+ &::-moz-range-track {
29
+ height: var(--dimension-100); /* 8px */
30
+ background: var(--color-foreground-slider-track);
31
+ border: none;
32
+ border-radius: var(--dimension-radius-small);
33
+ }
56
34
 
57
35
  &::-webkit-slider-thumb {
58
- box-shadow: 0 0 0 2px var(--color-focusRing);
36
+ appearance: none;
37
+ width: var(--dimension-200); /* 16px */
38
+ height: var(--dimension-200); /* 16px */
39
+ /* Re-centre the 16px thumb on the 8px runnable-track: (8 − 16) / 2 = −4px.
40
+ Derived from the actual track/thumb dimension tokens, not the baseline unit. */
41
+ margin-top: calc((var(--dimension-100) - var(--dimension-200)) / 2);
42
+ border-radius: 50%;
43
+ background: var(--color-foreground-slider-progress);
44
+ border: none;
45
+ cursor: pointer;
59
46
  }
60
47
 
61
48
  &::-moz-range-thumb {
62
- box-shadow: 0 0 0 2px var(--color-focusRing);
49
+ width: var(--dimension-200); /* 16px */
50
+ height: var(--dimension-200); /* 16px */
51
+ border-radius: 50%;
52
+ background: var(--color-foreground-slider-progress);
53
+ border: none;
54
+ cursor: pointer;
63
55
  }
64
- }
65
56
 
66
- &:disabled {
67
- cursor: not-allowed;
57
+ &:focus-visible {
58
+ outline: none;
68
59
 
69
- /* Track colour lives on the pseudo-elements (the element box is transparent). */
70
- &::-webkit-slider-runnable-track {
71
- background: var(--color-foreground-slider-track-disabled);
72
- }
60
+ &::-webkit-slider-thumb {
61
+ box-shadow: 0 0 0 2px var(--color-focus-ring);
62
+ }
73
63
 
74
- &::-moz-range-track {
75
- background: var(--color-foreground-slider-track-disabled);
64
+ &::-moz-range-thumb {
65
+ box-shadow: 0 0 0 2px var(--color-focus-ring);
66
+ }
76
67
  }
77
68
 
78
- &::-webkit-slider-thumb {
79
- background: var(--color-foreground-slider-progress-disabled);
80
- }
69
+ &:disabled {
70
+ cursor: not-allowed;
81
71
 
82
- &::-moz-range-thumb {
83
- background: var(--color-foreground-slider-progress-disabled);
72
+ /* Track colour lives on the pseudo-elements (the element box is transparent). */
73
+ &::-webkit-slider-runnable-track {
74
+ background: var(--color-foreground-slider-track-disabled);
75
+ }
76
+
77
+ &::-moz-range-track {
78
+ background: var(--color-foreground-slider-track-disabled);
79
+ }
80
+
81
+ &::-webkit-slider-thumb {
82
+ background: var(--color-foreground-slider-progress-disabled);
83
+ }
84
+
85
+ &::-moz-range-thumb {
86
+ background: var(--color-foreground-slider-progress-disabled);
87
+ }
84
88
  }
85
89
  }
86
- }
87
90
 
88
- .ds.range-output {
89
- display: block;
90
- text-align: center;
91
- /* .p class provides font-size, line-height, baseline nudges */
92
- color: var(--color-text-muted);
91
+ .ds.range-output {
92
+ display: block;
93
+ text-align: center;
94
+ /* .p class provides font-size, line-height, baseline nudges */
95
+ color: var(--color-text-muted);
96
+ }
93
97
  }
@@ -9,151 +9,155 @@
9
9
  * `starred` glyph is layered over it (`.star::after`) and its width is clipped
10
10
  * to 0%, 50% or 100% to show empty, half or full — so half-fill is one masked
11
11
  * shape rather than a separate half-width star.
12
+ *
13
+ * Layer: ds.components.global (@canonical/styles README, "Cascade layers").
12
14
  */
13
15
 
14
- .ds.form-rating {
15
- display: inline-flex;
16
- gap: var(--dimension-025, 0.125rem);
17
-
18
- --rating-color-empty: var(--color-text-muted, #b0b0b0);
19
- --rating-color-filled: var(--color-foreground-primary-warning, #f5a623);
20
- --rating-size: var(--rating-size-default, 1.5rem);
21
- }
22
-
23
- .ds.form-rating > .star {
24
- position: relative;
25
- display: inline-block;
26
- width: var(--rating-size);
27
- height: var(--rating-size);
28
- cursor: pointer;
29
- }
16
+ @layer ds.components.global {
17
+ .ds.form-rating {
18
+ display: inline-flex;
19
+ gap: var(--dimension-025, 0.125rem);
30
20
 
31
- /* Outline star (empty base). */
32
- .ds.form-rating > .star > .star-glyph {
33
- display: block;
34
- width: 100%;
35
- height: 100%;
36
- background-color: var(--rating-color-empty);
37
- mask: url("/icons/starred-off.svg#starred-off") no-repeat center / contain;
38
- -webkit-mask:
39
- url("/icons/starred-off.svg#starred-off") no-repeat center / contain;
40
- }
41
-
42
- /* Solid star (fill overlay), clipped to a fill amount that defaults to 0. */
43
- .ds.form-rating > .star::after {
44
- content: "";
45
- position: absolute;
46
- inset: 0;
47
- width: var(--star-fill, 0%);
48
- overflow: hidden;
49
- background-color: var(--rating-color-filled);
50
- mask: url("/icons/starred.svg#starred") no-repeat left center / auto 100%;
51
- -webkit-mask:
52
- url("/icons/starred.svg#starred") no-repeat left center / auto 100%;
53
- /* The mask must stay the full star width so clipping the box reveals a left
54
- slice of the star, not a squashed star. */
55
- mask-size: var(--rating-size) 100%;
56
- -webkit-mask-size: var(--rating-size) 100%;
57
- pointer-events: none;
58
- }
21
+ --rating-color-empty: var(--color-text-muted, #b0b0b0);
22
+ --rating-color-filled: var(--color-foreground-primary-warning, #f5a623);
23
+ --rating-size: var(--rating-size-default, 1.5rem);
24
+ }
59
25
 
60
- /* Radios are visually hidden but keep a11y semantics and keyboard focus. */
61
- .ds.form-rating .star-input {
62
- position: absolute;
63
- width: 1px;
64
- height: 1px;
65
- margin: -1px;
66
- padding: 0;
67
- border: 0;
68
- clip-path: inset(50%);
69
- overflow: hidden;
70
- white-space: nowrap;
71
- }
26
+ .ds.form-rating > .star {
27
+ position: relative;
28
+ display: inline-block;
29
+ width: var(--rating-size);
30
+ height: var(--rating-size);
31
+ cursor: pointer;
32
+ }
72
33
 
73
- /* Click targets. Full mode: one target covering the star. Half mode: a left
74
- half and a right half, each an absolutely-positioned 50%-wide hit area. */
75
- .ds.form-rating > .star > .star-target {
76
- position: absolute;
77
- inset: 0;
78
- z-index: 1;
79
- }
80
- .ds.form-rating.half > .star > .star-target.left {
81
- right: 50%;
82
- }
83
- .ds.form-rating.half > .star > .star-target.right {
84
- left: 50%;
85
- }
34
+ /* Outline star (empty base). */
35
+ .ds.form-rating > .star > .star-glyph {
36
+ display: block;
37
+ width: 100%;
38
+ height: 100%;
39
+ background-color: var(--rating-color-empty);
40
+ mask: url("/icons/starred-off.svg#starred-off") no-repeat center / contain;
41
+ -webkit-mask:
42
+ url("/icons/starred-off.svg#starred-off") no-repeat center / contain;
43
+ }
86
44
 
87
- /* --- Fill amount -------------------------------------------------------------
88
- A star is FULL when its full radio is checked, or when any later star has a
89
- radio checked. It is HALF when its half radio is checked (and no later star
90
- is). CSS custom property `--star-fill` drives the ::after width. */
45
+ /* Solid star (fill overlay), clipped to a fill amount that defaults to 0. */
46
+ .ds.form-rating > .star::after {
47
+ content: "";
48
+ position: absolute;
49
+ inset: 0;
50
+ width: var(--star-fill, 0%);
51
+ overflow: hidden;
52
+ background-color: var(--rating-color-filled);
53
+ mask: url("/icons/starred.svg#starred") no-repeat left center / auto 100%;
54
+ -webkit-mask:
55
+ url("/icons/starred.svg#starred") no-repeat left center / auto 100%;
56
+ /* The mask must stay the full star width so clipping the box reveals a left
57
+ slice of the star, not a squashed star. */
58
+ mask-size: var(--rating-size) 100%;
59
+ -webkit-mask-size: var(--rating-size) 100%;
60
+ pointer-events: none;
61
+ }
91
62
 
92
- /* Full: this star's whole-number radio is checked. */
93
- .ds.form-rating
94
- > .star:has(
95
- > .star-input[data-rating$="0"]:checked,
96
- > .star-input:not([data-rating*="."]):checked
97
- ) {
98
- --star-fill: 100%;
99
- }
63
+ /* Radios are visually hidden but keep a11y semantics and keyboard focus. */
64
+ .ds.form-rating .star-input {
65
+ position: absolute;
66
+ width: 1px;
67
+ height: 1px;
68
+ margin: -1px;
69
+ padding: 0;
70
+ border: 0;
71
+ clip-path: inset(50%);
72
+ overflow: hidden;
73
+ white-space: nowrap;
74
+ }
100
75
 
101
- /* Full: any later star has a checked radio → this star is fully filled. */
102
- .ds.form-rating > .star:has(~ .star .star-input:checked) {
103
- --star-fill: 100%;
104
- }
76
+ /* Click targets. Full mode: one target covering the star. Half mode: a left
77
+ half and a right half, each an absolutely-positioned 50%-wide hit area. */
78
+ .ds.form-rating > .star > .star-target {
79
+ position: absolute;
80
+ inset: 0;
81
+ z-index: 1;
82
+ }
83
+ .ds.form-rating.half > .star > .star-target.left {
84
+ right: 50%;
85
+ }
86
+ .ds.form-rating.half > .star > .star-target.right {
87
+ left: 50%;
88
+ }
105
89
 
106
- /* Half: this star's half radio (a `.5` value) is checked. Comes after the full
107
- rules so, when both apply to different stars, each resolves independently. */
108
- .ds.form-rating.half
109
- > .star:has(> .star-input[data-rating$=".5"]:checked):not(
110
- :has(~ .star .star-input:checked)
111
- ) {
112
- --star-fill: 50%;
113
- }
90
+ /* --- Fill amount -------------------------------------------------------------
91
+ A star is FULL when its full radio is checked, or when any later star has a
92
+ radio checked. It is HALF when its half radio is checked (and no later star
93
+ is). CSS custom property `--star-fill` drives the ::after width. */
114
94
 
115
- /* Hover preview overrides the checked fill until the pointer leaves. */
116
- @media (hover: hover) {
117
- .ds.form-rating:hover > .star {
118
- --star-fill: 0%;
95
+ /* Full: this star's whole-number radio is checked. */
96
+ .ds.form-rating
97
+ > .star:has(
98
+ > .star-input[data-rating$="0"]:checked,
99
+ > .star-input:not([data-rating*="."]):checked
100
+ ) {
101
+ --star-fill: 100%;
119
102
  }
120
- /* Hovering a right (or full) target fills that star and every earlier one. */
121
- .ds.form-rating > .star:hover,
122
- .ds.form-rating > .star:has(~ .star:hover) {
103
+
104
+ /* Full: any later star has a checked radio → this star is fully filled. */
105
+ .ds.form-rating > .star:has(~ .star .star-input:checked) {
123
106
  --star-fill: 100%;
124
107
  }
125
- /* Hovering a left half-target fills earlier stars fully and this one to 50%. */
126
- .ds.form-rating.half > .star:has(> .star-target.left:hover) {
108
+
109
+ /* Half: this star's half radio (a `.5` value) is checked. Comes after the full
110
+ rules so, when both apply to different stars, each resolves independently. */
111
+ .ds.form-rating.half
112
+ > .star:has(> .star-input[data-rating$=".5"]:checked):not(
113
+ :has(~ .star .star-input:checked)
114
+ ) {
127
115
  --star-fill: 50%;
128
116
  }
129
- .ds.form-rating.half > .star:has(~ .star > .star-target.left:hover) {
130
- --star-fill: 100%;
117
+
118
+ /* Hover preview overrides the checked fill until the pointer leaves. */
119
+ @media (hover: hover) {
120
+ .ds.form-rating:hover > .star {
121
+ --star-fill: 0%;
122
+ }
123
+ /* Hovering a right (or full) target fills that star and every earlier one. */
124
+ .ds.form-rating > .star:hover,
125
+ .ds.form-rating > .star:has(~ .star:hover) {
126
+ --star-fill: 100%;
127
+ }
128
+ /* Hovering a left half-target fills earlier stars fully and this one to 50%. */
129
+ .ds.form-rating.half > .star:has(> .star-target.left:hover) {
130
+ --star-fill: 50%;
131
+ }
132
+ .ds.form-rating.half > .star:has(~ .star > .star-target.left:hover) {
133
+ --star-fill: 100%;
134
+ }
131
135
  }
132
- }
133
136
 
134
- /* Keyboard focus ring on the star whose radio is focused. */
135
- .ds.form-rating > .star:has(> .star-input:focus-visible) {
136
- outline: var(--focus-outline-width, 2px) solid
137
- var(--color-focusRing, currentColor);
138
- outline-offset: 2px;
139
- border-radius: var(--dimension-radius-small, 2px);
140
- }
137
+ /* Keyboard focus ring on the star whose radio is focused. */
138
+ .ds.form-rating > .star:has(> .star-input:focus-visible) {
139
+ outline: var(--focus-outline-width, 2px) solid
140
+ var(--color-focus-ring, currentColor);
141
+ outline-offset: 2px;
142
+ border-radius: var(--dimension-radius-small, 2px);
143
+ }
141
144
 
142
- /* Disabled. */
143
- .ds.form-rating:has(.star-input:disabled) > .star {
144
- cursor: not-allowed;
145
- opacity: 0.5;
146
- }
145
+ /* Disabled. */
146
+ .ds.form-rating:has(.star-input:disabled) > .star {
147
+ cursor: not-allowed;
148
+ opacity: 0.5;
149
+ }
147
150
 
148
- /* Local visually-hidden helper for the per-target text label. */
149
- .ds.form-rating .ds-visually-hidden {
150
- position: absolute;
151
- width: 1px;
152
- height: 1px;
153
- margin: -1px;
154
- padding: 0;
155
- border: 0;
156
- clip-path: inset(50%);
157
- overflow: hidden;
158
- white-space: nowrap;
151
+ /* Local visually-hidden helper for the per-target text label. */
152
+ .ds.form-rating .ds-visually-hidden {
153
+ position: absolute;
154
+ width: 1px;
155
+ height: 1px;
156
+ margin: -1px;
157
+ padding: 0;
158
+ border: 0;
159
+ clip-path: inset(50%);
160
+ overflow: hidden;
161
+ white-space: nowrap;
162
+ }
159
163
  }
@@ -1,41 +1,45 @@
1
- /* Chevron indicator, painted with CSS gradients so it takes the theme colour.
2
- * A `background-image` SVG cannot be recoloured by CSS (no inheritance into
3
- * the image document), which left the caret black on dark themes — the same
4
- * reason the checkbox/accordion glyphs are masks. A <select> is a replaced
5
- * element with no ::before/::after to mask, so the chevron is drawn instead:
6
- * two diagonally-striped gradient squares butted together form a down-chevron
7
- * STROKE (transparent → colour → transparent along each diagonal), coloured by
8
- * --color-icon like every other control glyph. */
9
- .ds.input.select {
10
- appearance: none;
11
- --select-caret-color: var(--color-icon, currentColor);
12
- --select-caret-half: 0.4em; /* each square; the chevron is two halves wide */
13
- /* left half: rising stroke ╱ */
14
- background-image:
15
- linear-gradient(
16
- 45deg,
17
- transparent 42%,
18
- var(--select-caret-color) 42%,
19
- var(--select-caret-color) 58%,
20
- transparent 58%
21
- ),
22
- /* right half: falling stroke ╲ */
23
- linear-gradient(
24
- 135deg,
25
- transparent 42%,
26
- var(--select-caret-color) 42%,
27
- var(--select-caret-color) 58%,
28
- transparent 58%
29
- );
30
- background-repeat: no-repeat;
31
- background-position:
32
- right calc(var(--form-input-padding-inline) + var(--select-caret-half))
33
- center,
34
- right var(--form-input-padding-inline) center;
35
- background-size: var(--select-caret-half) var(--select-caret-half);
36
- /* This element IS the text-bearing leaf, so it carries the inline padding
37
- * (`.ds.input.chrome` provides only the block padding). The end side leaves
38
- * room for the chevron. */
39
- padding-inline-start: var(--form-input-padding-inline);
40
- padding-inline-end: calc(var(--form-input-padding-inline) * 2 + 1em);
1
+ /* Layer: ds.components.global (@canonical/styles README, "Cascade layers"). */
2
+
3
+ @layer ds.components.global {
4
+ /* Chevron indicator, painted with CSS gradients so it takes the theme colour.
5
+ * A `background-image` SVG cannot be recoloured by CSS (no inheritance into
6
+ * the image document), which left the caret black on dark themes — the same
7
+ * reason the checkbox/accordion glyphs are masks. A <select> is a replaced
8
+ * element with no ::before/::after to mask, so the chevron is drawn instead:
9
+ * two diagonally-striped gradient squares butted together form a down-chevron
10
+ * STROKE (transparent → colour → transparent along each diagonal), coloured by
11
+ * --color-icon like every other control glyph. */
12
+ .ds.input.select {
13
+ appearance: none;
14
+ --select-caret-color: var(--color-icon, currentColor);
15
+ --select-caret-half: 0.4em; /* each square; the chevron is two halves wide */
16
+ /* left half: rising stroke ╱ */
17
+ background-image:
18
+ linear-gradient(
19
+ 45deg,
20
+ transparent 42%,
21
+ var(--select-caret-color) 42%,
22
+ var(--select-caret-color) 58%,
23
+ transparent 58%
24
+ ),
25
+ /* right half: falling stroke ╲ */
26
+ linear-gradient(
27
+ 135deg,
28
+ transparent 42%,
29
+ var(--select-caret-color) 42%,
30
+ var(--select-caret-color) 58%,
31
+ transparent 58%
32
+ );
33
+ background-repeat: no-repeat;
34
+ background-position:
35
+ right calc(var(--form-input-padding-inline) + var(--select-caret-half))
36
+ center,
37
+ right var(--form-input-padding-inline) center;
38
+ background-size: var(--select-caret-half) var(--select-caret-half);
39
+ /* This element IS the text-bearing leaf, so it carries the inline padding
40
+ * (`.ds.input.chrome` provides only the block padding). The end side leaves
41
+ * room for the chevron. */
42
+ padding-inline-start: var(--form-input-padding-inline);
43
+ padding-inline-end: calc(var(--form-input-padding-inline) * 2 + 1em);
44
+ }
41
45
  }