@threadlabs/looma 0.14.2 → 0.14.3

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.
@@ -11,6 +11,10 @@
11
11
  valueText or in text beside the meter too.</prop>
12
12
  <prop name="size" type="sm | md" default="md"
13
13
  >Thickness. sm is a thin bar that sits in a line of text, such as a table cell beside an amount; md stands on its own.</prop>
14
+ <prop name="segments" type="number" default="0"
15
+ >How many equal segments to draw the bar as, from 2 to 12, for a count of steps: set max to the same number and value to the steps done, so whole segments
16
+ fill, and say the step in valueText ("Shipped, step 4 of 6"). A value between steps fills part of a segment. 0 draws one continuous bar, as does any other
17
+ number.</prop>
14
18
  <prop name="label" type="string" default=""
15
19
  >What the meter measures, as its accessible name ("Collected"). Leave it empty only when aria-labelledby names the meter from visible text.</prop>
16
20
  <prop name="valueText" type="string" default=""
@@ -28,6 +32,7 @@
28
32
  :aria-valuenow="amount"
29
33
  :aria-valuetext="{ true: valueText, false: format('%s%', whole) }[format('%s', valueText != '')]"
30
34
  :aria-label="{ true: label, false: null }[format('%s', label != '')]"
35
+ :data-ui-meter-segments="{ true: segments, false: null }[format('%s', segments > 1)]"
31
36
  >
32
37
  <span class="fill" style:inline-size="format('%s%', percent)"></span>
33
38
  </span>
@@ -87,12 +92,90 @@
87
92
  --_meter-fill: var(--ui-danger-solid);
88
93
  }
89
94
 
95
+ /* Segments: the track and its fill show through a mask of equal segments with a gap between them.
96
+ A mask over the whole meter, rather than one element per segment, because the expression
97
+ language has no range to render N elements from, and one mask lines the fill up with the track
98
+ for free. Each period is a segment and the gap after it; N periods span the track plus one
99
+ trailing gap, so the segments sit symmetrically and right to left needs nothing of its own.
100
+ The count arrives as an attribute, not an inline custom property (which would add a style
101
+ attribute to every meter), so a continuous meter renders exactly as before, and the rules below
102
+ turn it into a number. That caps it at 12, until attr() with a type reads any count in every engine. */
103
+ :host[data-ui-meter-segments="2"] {
104
+ --_segments: 2;
105
+ }
106
+
107
+ :host[data-ui-meter-segments="3"] {
108
+ --_segments: 3;
109
+ }
110
+
111
+ :host[data-ui-meter-segments="4"] {
112
+ --_segments: 4;
113
+ }
114
+
115
+ :host[data-ui-meter-segments="5"] {
116
+ --_segments: 5;
117
+ }
118
+
119
+ :host[data-ui-meter-segments="6"] {
120
+ --_segments: 6;
121
+ }
122
+
123
+ :host[data-ui-meter-segments="7"] {
124
+ --_segments: 7;
125
+ }
126
+
127
+ :host[data-ui-meter-segments="8"] {
128
+ --_segments: 8;
129
+ }
130
+
131
+ :host[data-ui-meter-segments="9"] {
132
+ --_segments: 9;
133
+ }
134
+
135
+ :host[data-ui-meter-segments="10"] {
136
+ --_segments: 10;
137
+ }
138
+
139
+ :host[data-ui-meter-segments="11"] {
140
+ --_segments: 11;
141
+ }
142
+
143
+ :host[data-ui-meter-segments="12"] {
144
+ --_segments: 12;
145
+ }
146
+
147
+ :host[data-ui-meter-segments] {
148
+ --_meter-gap: var(--ui-space-1);
149
+ --_meter-period: calc((100% + var(--_meter-gap)) / var(--_segments));
150
+ --_meter-segment: calc(var(--_meter-period) - var(--_meter-gap));
151
+
152
+ mask-image: repeating-linear-gradient(to right, #000 0 var(--_meter-segment), transparent 0 var(--_meter-period));
153
+ }
154
+
155
+ :host-state([size="sm"])[data-ui-meter-segments] {
156
+ --_meter-gap: var(--ui-space-0-5);
157
+ }
158
+
90
159
  /* Forced colours drop backgrounds: draw the fill in the text colour inside the outlined track. */
91
160
  @media (forced-colors: active) {
92
161
  .fill {
93
162
  forced-color-adjust: none;
94
163
  background: CanvasText;
95
164
  }
165
+
166
+ /* The mask clips the track's outline, so each segment draws its own: the inset shadow draws the
167
+ top and bottom edges and the gradient the ends. */
168
+ :host[data-ui-meter-segments] {
169
+ forced-color-adjust: none;
170
+ background: repeating-linear-gradient(
171
+ to right,
172
+ CanvasText 0 1px,
173
+ Canvas 0 calc(var(--_meter-segment) - 1px),
174
+ CanvasText 0 var(--_meter-segment),
175
+ transparent 0 var(--_meter-period)
176
+ );
177
+ box-shadow: inset 0 0 0 1px CanvasText;
178
+ }
96
179
  }
97
180
 
98
181
  /* A component that sets its display still honours the hidden attribute on its root. */