@italia/rating 1.0.0-alpha.10
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.
- package/AUTHORS +3 -0
- package/LICENSE +11 -0
- package/README.md +166 -0
- package/custom-elements.json +426 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/it-rating-item.d.ts +33 -0
- package/dist/src/it-rating-item.d.ts.map +1 -0
- package/dist/src/it-rating-item.js +456 -0
- package/dist/src/it-rating-item.js.map +1 -0
- package/dist/src/it-rating.d.ts +61 -0
- package/dist/src/it-rating.d.ts.map +1 -0
- package/dist/src/it-rating.js +567 -0
- package/dist/src/it-rating.js.map +1 -0
- package/dist/src/locales/it.d.ts +4 -0
- package/dist/src/locales/it.d.ts.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
import { _ as __decorate, a as __metadata } from '../tslib.es6-Cv888lzs.js';
|
|
2
|
+
import { queryAssignedElements, property, customElement } from 'lit/decorators.js';
|
|
3
|
+
import { ItRadioGroup } from '@italia/radio';
|
|
4
|
+
import { registerTranslation } from '@italia/i18n';
|
|
5
|
+
import { css } from 'lit';
|
|
6
|
+
|
|
7
|
+
const translation = {
|
|
8
|
+
$code: 'it',
|
|
9
|
+
$name: 'Italiano',
|
|
10
|
+
$dir: 'ltr',
|
|
11
|
+
noRating: 'Nessuna valutazione',
|
|
12
|
+
ratingLabelSingle: (rating, max) => `${rating} stella su ${max}`,
|
|
13
|
+
ratingLabelPlural: (rating, max) => `${rating} stelle su ${max}`,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
var styles = css`/***************************** 1 ****************************************/
|
|
17
|
+
/***************************** 2 ****************************************/
|
|
18
|
+
/***************************** 1 ****************************************/
|
|
19
|
+
/***************************** 2 ****************************************/
|
|
20
|
+
/***************************** 1 ****************************************/
|
|
21
|
+
/***************************** 2 ****************************************/
|
|
22
|
+
/***************************** 3 ****************************************/
|
|
23
|
+
/***************************** 1 ****************************************/
|
|
24
|
+
/***************************** 2 ****************************************/
|
|
25
|
+
/***************************** 3 ****************************************/
|
|
26
|
+
/***************************** NEUTRAL 1 ****************************************/
|
|
27
|
+
/***************************** NEUTRAL 2 ****************************************/
|
|
28
|
+
/***************************** NEUTRAL 2 / 3 ****************************************/
|
|
29
|
+
*,
|
|
30
|
+
*::before,
|
|
31
|
+
*::after {
|
|
32
|
+
box-sizing: border-box;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
36
|
+
:root {
|
|
37
|
+
scroll-behavior: smooth;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
body {
|
|
42
|
+
margin: 0;
|
|
43
|
+
-webkit-text-size-adjust: 100%;
|
|
44
|
+
-webkit-tap-highlight-color: hsla(0, 0%, 0%, 0);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
hr {
|
|
48
|
+
margin: 1rem 0;
|
|
49
|
+
color: inherit;
|
|
50
|
+
border: 0;
|
|
51
|
+
border-top: 1px solid;
|
|
52
|
+
opacity: 0.25;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
p {
|
|
56
|
+
margin-top: 0;
|
|
57
|
+
margin-bottom: var(--bsi-paragraph-spacing);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
abbr[title] {
|
|
61
|
+
text-decoration: underline dotted;
|
|
62
|
+
cursor: help;
|
|
63
|
+
text-decoration-skip-ink: none;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
address {
|
|
67
|
+
margin-bottom: var(--bsi-spacing-s);
|
|
68
|
+
font-style: normal;
|
|
69
|
+
line-height: inherit;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
ol,
|
|
73
|
+
ul {
|
|
74
|
+
padding-left: var(--bsi-spacing-l);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
ol,
|
|
78
|
+
ul,
|
|
79
|
+
dl {
|
|
80
|
+
margin-top: 0;
|
|
81
|
+
margin-bottom: var(--bsi-spacing-s);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
ol ol,
|
|
85
|
+
ul ul,
|
|
86
|
+
ol ul,
|
|
87
|
+
ul ol {
|
|
88
|
+
margin-bottom: 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
dt {
|
|
92
|
+
font-weight: var(--bsi-font-weight-strong);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
dd {
|
|
96
|
+
margin-bottom: var(--bsi-spacing-xxs);
|
|
97
|
+
margin-left: 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
blockquote {
|
|
101
|
+
margin: 0 0 var(--bsi-spacing-s);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
sub,
|
|
105
|
+
sup {
|
|
106
|
+
position: relative;
|
|
107
|
+
font-size: var(--bsi-font-size-1);
|
|
108
|
+
line-height: 0;
|
|
109
|
+
vertical-align: baseline;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
sub {
|
|
113
|
+
bottom: -0.25em;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
sup {
|
|
117
|
+
top: -0.5em;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
a {
|
|
121
|
+
color: var(--bsi-color-link);
|
|
122
|
+
text-decoration: underline;
|
|
123
|
+
text-decoration-skip-ink: auto;
|
|
124
|
+
text-underline-offset: 2px;
|
|
125
|
+
}
|
|
126
|
+
a:hover {
|
|
127
|
+
color: var(--bsi-color-link-hover);
|
|
128
|
+
cursor: pointer;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
pre,
|
|
132
|
+
code,
|
|
133
|
+
kbd,
|
|
134
|
+
samp {
|
|
135
|
+
font-size: 1em;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
pre {
|
|
139
|
+
display: block;
|
|
140
|
+
margin-top: 0;
|
|
141
|
+
margin-bottom: var(--bsi-paragraph-spacing);
|
|
142
|
+
overflow: auto;
|
|
143
|
+
}
|
|
144
|
+
pre code {
|
|
145
|
+
word-break: normal;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
a > code {
|
|
149
|
+
color: inherit;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
figure {
|
|
153
|
+
margin: 0 0 1rem;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
img,
|
|
157
|
+
svg {
|
|
158
|
+
vertical-align: middle;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
table {
|
|
162
|
+
caption-side: bottom;
|
|
163
|
+
border-collapse: collapse;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
caption {
|
|
167
|
+
padding-top: 0.5rem;
|
|
168
|
+
padding-bottom: 0.5rem;
|
|
169
|
+
color: hsl(210, 17%, 44%);
|
|
170
|
+
text-align: left;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
th {
|
|
174
|
+
text-align: inherit;
|
|
175
|
+
text-align: -webkit-match-parent;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
thead,
|
|
179
|
+
tbody,
|
|
180
|
+
tfoot,
|
|
181
|
+
tr,
|
|
182
|
+
td,
|
|
183
|
+
th {
|
|
184
|
+
border-color: inherit;
|
|
185
|
+
border-style: solid;
|
|
186
|
+
border-width: 0;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
label {
|
|
190
|
+
display: inline-block;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
button {
|
|
194
|
+
border-radius: 0;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
button:focus:not(:focus-visible) {
|
|
198
|
+
outline: 0;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
input,
|
|
202
|
+
button,
|
|
203
|
+
select,
|
|
204
|
+
optgroup,
|
|
205
|
+
textarea {
|
|
206
|
+
margin: 0;
|
|
207
|
+
font-family: inherit;
|
|
208
|
+
font-size: inherit;
|
|
209
|
+
line-height: inherit;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
button,
|
|
213
|
+
select {
|
|
214
|
+
text-transform: none;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
[role=button] {
|
|
218
|
+
cursor: pointer;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
select {
|
|
222
|
+
word-wrap: normal;
|
|
223
|
+
}
|
|
224
|
+
select:disabled {
|
|
225
|
+
opacity: 1;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
[list]:not([type=date]):not([type=datetime-local]):not([type=month]):not([type=week]):not([type=time])::-webkit-calendar-picker-indicator {
|
|
229
|
+
display: none !important;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
button,
|
|
233
|
+
[type=button],
|
|
234
|
+
[type=reset],
|
|
235
|
+
[type=submit] {
|
|
236
|
+
-webkit-appearance: button;
|
|
237
|
+
}
|
|
238
|
+
button:not(:disabled),
|
|
239
|
+
[type=button]:not(:disabled),
|
|
240
|
+
[type=reset]:not(:disabled),
|
|
241
|
+
[type=submit]:not(:disabled) {
|
|
242
|
+
cursor: pointer;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
::-moz-focus-inner {
|
|
246
|
+
padding: 0;
|
|
247
|
+
border-style: none;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
textarea {
|
|
251
|
+
resize: vertical;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
fieldset {
|
|
255
|
+
min-width: 0;
|
|
256
|
+
padding: 0;
|
|
257
|
+
margin: 0;
|
|
258
|
+
border: 0;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
::-webkit-datetime-edit-fields-wrapper,
|
|
262
|
+
::-webkit-datetime-edit-text,
|
|
263
|
+
::-webkit-datetime-edit-minute,
|
|
264
|
+
::-webkit-datetime-edit-hour-field,
|
|
265
|
+
::-webkit-datetime-edit-day-field,
|
|
266
|
+
::-webkit-datetime-edit-month-field,
|
|
267
|
+
::-webkit-datetime-edit-year-field {
|
|
268
|
+
padding: 0;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
::-webkit-inner-spin-button {
|
|
272
|
+
height: auto;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
[type=search] {
|
|
276
|
+
outline-offset: -2px;
|
|
277
|
+
-webkit-appearance: textfield;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/* rtl:raw:
|
|
281
|
+
[type="tel"],
|
|
282
|
+
[type="url"],
|
|
283
|
+
[type="email"],
|
|
284
|
+
[type="number"] {
|
|
285
|
+
direction: ltr;
|
|
286
|
+
}
|
|
287
|
+
*/
|
|
288
|
+
::-webkit-search-decoration {
|
|
289
|
+
-webkit-appearance: none;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
::-webkit-color-swatch-wrapper {
|
|
293
|
+
padding: 0;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
::file-selector-button {
|
|
297
|
+
font: inherit;
|
|
298
|
+
-webkit-appearance: button;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
output {
|
|
302
|
+
display: inline-block;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
iframe {
|
|
306
|
+
border: 0;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
summary {
|
|
310
|
+
display: list-item;
|
|
311
|
+
cursor: pointer;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
progress {
|
|
315
|
+
vertical-align: baseline;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
[hidden] {
|
|
319
|
+
display: none !important;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
.visually-hidden,
|
|
323
|
+
.visually-hidden-focusable:not(:focus):not(:focus-within) {
|
|
324
|
+
position: absolute !important;
|
|
325
|
+
width: 1px !important;
|
|
326
|
+
height: 1px !important;
|
|
327
|
+
padding: 0 !important;
|
|
328
|
+
margin: -1px !important;
|
|
329
|
+
overflow: hidden !important;
|
|
330
|
+
clip: rect(0, 0, 0, 0) !important;
|
|
331
|
+
white-space: nowrap !important;
|
|
332
|
+
border: 0 !important;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
.rating {
|
|
336
|
+
--bsi-rating-font-size: var(--bsi-label-font-size-s);
|
|
337
|
+
--bsi-rating-font-weight: var(--bsi-font-weight-solid);
|
|
338
|
+
--bsi-rating-icon-fill: var(--bsi-color-background-secondary-light);
|
|
339
|
+
--bsi-rating-line-height: var(--bsi-label-leading);
|
|
340
|
+
--bsi-rating-text: var(--bsi-color-text-secondary);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/* stylelint-disable-next-line no-duplicate-selectors */
|
|
344
|
+
.rating {
|
|
345
|
+
border: none;
|
|
346
|
+
display: flex;
|
|
347
|
+
flex-direction: row-reverse;
|
|
348
|
+
justify-content: flex-end;
|
|
349
|
+
align-items: center;
|
|
350
|
+
}
|
|
351
|
+
.rating > input {
|
|
352
|
+
position: absolute;
|
|
353
|
+
left: -9999px;
|
|
354
|
+
}
|
|
355
|
+
.rating > label {
|
|
356
|
+
margin: 0;
|
|
357
|
+
padding-right: 2px;
|
|
358
|
+
}
|
|
359
|
+
.rating > label:hover {
|
|
360
|
+
cursor: pointer;
|
|
361
|
+
}
|
|
362
|
+
.rating > label:hover svg {
|
|
363
|
+
transform: scale(1.2);
|
|
364
|
+
}
|
|
365
|
+
.rating > label svg {
|
|
366
|
+
fill: var(--bsi-rating-icon-fill);
|
|
367
|
+
position: relative;
|
|
368
|
+
transform-origin: center center;
|
|
369
|
+
transition: transform var(--bsi-transition-instant);
|
|
370
|
+
}
|
|
371
|
+
.rating > legend {
|
|
372
|
+
color: var(--bsi-rating-text);
|
|
373
|
+
font-size: var(--bsi-rating-font-size);
|
|
374
|
+
float: right;
|
|
375
|
+
width: auto;
|
|
376
|
+
margin-left: var(--bsi-spacing-xxs);
|
|
377
|
+
font-weight: var(--bsi-rating-font-weight);
|
|
378
|
+
line-height: var(--bsi-rating-line-height);
|
|
379
|
+
}
|
|
380
|
+
.rating.rating-read-only > input, .rating.rating-read-only > label {
|
|
381
|
+
pointer-events: none;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
.rating > input:checked ~ label,
|
|
385
|
+
.rating:not(:checked) > label:hover,
|
|
386
|
+
.rating:not(:checked) > label:hover ~ label {
|
|
387
|
+
--bsi-rating-icon-fill: var(--bsi-icon-primary);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
.rating > input:checked + label:hover svg,
|
|
391
|
+
.rating > input:checked ~ label:hover svg,
|
|
392
|
+
.rating > label:hover ~ input:checked ~ label svg,
|
|
393
|
+
.rating > input:checked ~ label:hover ~ label svg {
|
|
394
|
+
--bsi-rating-icon-fill: var(--bsi-icon-primary);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
:host {
|
|
398
|
+
display: flex;
|
|
399
|
+
flex-direction: row-reverse;
|
|
400
|
+
flex-wrap: wrap;
|
|
401
|
+
align-items: center;
|
|
402
|
+
--bsi-rating-icon-fill: var(--bsi-icon-disabled);
|
|
403
|
+
--bsi-rating-text: var(--bsi-color-text-secondary);
|
|
404
|
+
--bsi-rating-font-size: var(--bsi-label-font-size-s);
|
|
405
|
+
--bsi-rating-line-height: var(--bsi-label-leading);
|
|
406
|
+
--bsi-rating-font-weight: var(--bsi-font-weight-solid);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
div.it-radio-group {
|
|
410
|
+
display: flex;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
::slotted([slot=label]) {
|
|
414
|
+
width: auto;
|
|
415
|
+
margin-left: var(--bsi-spacing-xxs);
|
|
416
|
+
color: var(--bsi-rating-text);
|
|
417
|
+
float: right;
|
|
418
|
+
font-size: var(--bsi-rating-font-size);
|
|
419
|
+
font-weight: var(--bsi-rating-font-weight);
|
|
420
|
+
line-height: var(--bsi-rating-line-height);
|
|
421
|
+
}`;
|
|
422
|
+
|
|
423
|
+
registerTranslation(translation);
|
|
424
|
+
/**
|
|
425
|
+
* Rating component - extends it-radio-group for star rating
|
|
426
|
+
*
|
|
427
|
+
* @element it-rating
|
|
428
|
+
*
|
|
429
|
+
* @slot - Contains the `<it-rating-item>` elements
|
|
430
|
+
* @slot label - The label/legend text for the rating
|
|
431
|
+
*
|
|
432
|
+
* @fires {CustomEvent} change - Emitted when the rating value changes
|
|
433
|
+
*/
|
|
434
|
+
let ItRating = class ItRating extends ItRadioGroup {
|
|
435
|
+
constructor() {
|
|
436
|
+
super(...arguments);
|
|
437
|
+
/**
|
|
438
|
+
* Maximum number of stars (to calculate "X out of Y")
|
|
439
|
+
*/
|
|
440
|
+
this.maxElements = 5;
|
|
441
|
+
/**
|
|
442
|
+
* Whether the rating is read-only (non-interactive)
|
|
443
|
+
*/
|
|
444
|
+
this.readOnly = false;
|
|
445
|
+
/**
|
|
446
|
+
* The icon name to use for the rating item
|
|
447
|
+
* @default 'it-star-outline'
|
|
448
|
+
*/
|
|
449
|
+
this.icon = 'it-star-outline';
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Sync read-only state to all rating items
|
|
453
|
+
*/
|
|
454
|
+
_syncReadOnlyToItems() {
|
|
455
|
+
const items = this.querySelectorAll('it-rating-item');
|
|
456
|
+
items.forEach((item) => {
|
|
457
|
+
if (this.readOnly) {
|
|
458
|
+
item.setAttribute('disabled', '');
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
item.removeAttribute('disabled');
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Get the localized rating announcement for screen readers
|
|
467
|
+
*/
|
|
468
|
+
_getRatingAnnouncement() {
|
|
469
|
+
const currentValue = parseInt(this.value || '0', 10);
|
|
470
|
+
if (!currentValue || currentValue === 0) {
|
|
471
|
+
return this.localize.term('noRating');
|
|
472
|
+
}
|
|
473
|
+
// Use singular or plural form based on rating value
|
|
474
|
+
const termKey = currentValue === 1 ? 'ratingLabelSingle' : 'ratingLabelPlural';
|
|
475
|
+
// Pass parameters directly to the translation function
|
|
476
|
+
return this.localize.term(termKey, currentValue, this.maxElements);
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Override updated to refresh the rating items and announcement when value changes
|
|
480
|
+
*/
|
|
481
|
+
updated(changedProperties) {
|
|
482
|
+
super.updated(changedProperties);
|
|
483
|
+
// Sync disabled state to all rating items when readOnly changes
|
|
484
|
+
if (changedProperties.has('readOnly')) {
|
|
485
|
+
this._syncReadOnlyToItems();
|
|
486
|
+
}
|
|
487
|
+
// Update aria-readonly attribute
|
|
488
|
+
if (this.readOnly) {
|
|
489
|
+
this.setAttribute('aria-readonly', 'true');
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
this.removeAttribute('aria-readonly');
|
|
493
|
+
}
|
|
494
|
+
// When value changes, force re-render of all rating items AND update their display
|
|
495
|
+
if (changedProperties.has('value')) {
|
|
496
|
+
this._updateRadiosState();
|
|
497
|
+
this._updateRatingItemsDisplay();
|
|
498
|
+
this._ensureAnnouncement();
|
|
499
|
+
}
|
|
500
|
+
if (changedProperties.has('icon')) {
|
|
501
|
+
this._updateRatingItemsDisplay();
|
|
502
|
+
}
|
|
503
|
+
// When maxElements changes, update the announcement
|
|
504
|
+
if (changedProperties.has('maxElements')) {
|
|
505
|
+
this._ensureAnnouncement();
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Force re-render of all rating items to update star colors
|
|
510
|
+
* This ensures star colors reflect the current value
|
|
511
|
+
*/
|
|
512
|
+
_updateRatingItemsDisplay() {
|
|
513
|
+
const items = this.querySelectorAll('it-rating-item');
|
|
514
|
+
items.forEach((item) => {
|
|
515
|
+
item.requestUpdate();
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Create or update the visually-hidden announcement element
|
|
520
|
+
* Following BSI pattern: announcement placed directly in the label slot
|
|
521
|
+
*/
|
|
522
|
+
_ensureAnnouncement() {
|
|
523
|
+
// Find the label slot elements (assigned nodes)
|
|
524
|
+
const labelSlot = this.shadowRoot?.querySelector('slot[name="label"]');
|
|
525
|
+
if (!labelSlot)
|
|
526
|
+
return;
|
|
527
|
+
// Get the first element in the label slot (the legend/label container)
|
|
528
|
+
const labelElements = labelSlot.assignedElements();
|
|
529
|
+
if (labelElements.length === 0)
|
|
530
|
+
return;
|
|
531
|
+
const labelContainer = labelElements[0];
|
|
532
|
+
// Look for existing announcement span
|
|
533
|
+
let announcement = labelContainer.querySelector('.rating-announcement');
|
|
534
|
+
if (!announcement) {
|
|
535
|
+
// Create the announcement element if it doesn't exist
|
|
536
|
+
announcement = document.createElement('span');
|
|
537
|
+
announcement.className = 'visually-hidden rating-announcement';
|
|
538
|
+
// Append to the label container
|
|
539
|
+
labelContainer.appendChild(announcement);
|
|
540
|
+
}
|
|
541
|
+
// Update the text content
|
|
542
|
+
announcement.textContent = ` ${this._getRatingAnnouncement()}`;
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
ItRating.styles = styles;
|
|
546
|
+
__decorate([
|
|
547
|
+
queryAssignedElements(),
|
|
548
|
+
__metadata("design:type", Array)
|
|
549
|
+
], ItRating.prototype, "_radios", void 0);
|
|
550
|
+
__decorate([
|
|
551
|
+
property({ type: Number, attribute: 'max-elements', reflect: true }),
|
|
552
|
+
__metadata("design:type", Object)
|
|
553
|
+
], ItRating.prototype, "maxElements", void 0);
|
|
554
|
+
__decorate([
|
|
555
|
+
property({ type: Boolean, reflect: true, attribute: 'read-only' }),
|
|
556
|
+
__metadata("design:type", Object)
|
|
557
|
+
], ItRating.prototype, "readOnly", void 0);
|
|
558
|
+
__decorate([
|
|
559
|
+
property({ type: String, reflect: true }),
|
|
560
|
+
__metadata("design:type", Object)
|
|
561
|
+
], ItRating.prototype, "icon", void 0);
|
|
562
|
+
ItRating = __decorate([
|
|
563
|
+
customElement('it-rating')
|
|
564
|
+
], ItRating);
|
|
565
|
+
|
|
566
|
+
export { ItRating };
|
|
567
|
+
//# sourceMappingURL=it-rating.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"it-rating.js","sources":["../../../src/locales/it.ts","../../../src/it-rating.ts"],"sourcesContent":["import type { DefaultTranslation } from '@italia/i18n';\n\nconst translation: DefaultTranslation = {\n $code: 'it',\n $name: 'Italiano',\n $dir: 'ltr',\n\n noRating: 'Nessuna valutazione',\n ratingLabelSingle: (rating: number, max: number) => `${rating} stella su ${max}`,\n ratingLabelPlural: (rating: number, max: number) => `${rating} stelle su ${max}`,\n};\n\nexport default translation;\n","import { type PropertyValues } from 'lit';\nimport { customElement, property, queryAssignedElements } from 'lit/decorators.js';\nimport { ItRadioGroup } from '@italia/radio'; // eslint-disable-line import/no-extraneous-dependencies\nimport { registerTranslation } from '@italia/i18n';\nimport { type ItRatingItem } from '@italia/rating';\nimport it from './locales/it.js';\n\nimport styles from './rating.scss';\n\nregisterTranslation(it);\n\n/**\n * Rating component - extends it-radio-group for star rating\n *\n * @element it-rating\n *\n * @slot - Contains the `<it-rating-item>` elements\n * @slot label - The label/legend text for the rating\n *\n * @fires {CustomEvent} change - Emitted when the rating value changes\n */\n@customElement('it-rating')\nexport class ItRating extends ItRadioGroup {\n static override styles = styles;\n\n /**\n * Get all slotted rating items\n */\n @queryAssignedElements()\n protected _radios!: ItRatingItem[];\n\n /**\n * Maximum number of stars (to calculate \"X out of Y\")\n */\n @property({ type: Number, attribute: 'max-elements', reflect: true })\n maxElements = 5;\n\n /**\n * Whether the rating is read-only (non-interactive)\n */\n @property({ type: Boolean, reflect: true, attribute: 'read-only' })\n readOnly = false;\n\n /**\n * The icon name to use for the rating item\n * @default 'it-star-outline'\n */\n @property({ type: String, reflect: true })\n icon = 'it-star-outline';\n\n /**\n * Sync read-only state to all rating items\n */\n private _syncReadOnlyToItems() {\n const items = this.querySelectorAll('it-rating-item');\n items.forEach((item) => {\n if (this.readOnly) {\n item.setAttribute('disabled', '');\n } else {\n item.removeAttribute('disabled');\n }\n });\n }\n\n /**\n * Get the localized rating announcement for screen readers\n */\n private _getRatingAnnouncement(): string {\n const currentValue = parseInt(this.value || '0', 10);\n\n if (!currentValue || currentValue === 0) {\n return this.localize.term('noRating');\n }\n // Use singular or plural form based on rating value\n const termKey = currentValue === 1 ? 'ratingLabelSingle' : 'ratingLabelPlural';\n\n // Pass parameters directly to the translation function\n return this.localize.term(termKey, currentValue, this.maxElements);\n }\n\n /**\n * Override updated to refresh the rating items and announcement when value changes\n */\n override updated(changedProperties: PropertyValues) {\n super.updated(changedProperties);\n\n // Sync disabled state to all rating items when readOnly changes\n if (changedProperties.has('readOnly')) {\n this._syncReadOnlyToItems();\n }\n\n // Update aria-readonly attribute\n if (this.readOnly) {\n this.setAttribute('aria-readonly', 'true');\n } else {\n this.removeAttribute('aria-readonly');\n }\n\n // When value changes, force re-render of all rating items AND update their display\n if (changedProperties.has('value')) {\n this._updateRadiosState();\n this._updateRatingItemsDisplay();\n this._ensureAnnouncement();\n }\n if (changedProperties.has('icon')) {\n this._updateRatingItemsDisplay();\n }\n\n // When maxElements changes, update the announcement\n if (changedProperties.has('maxElements')) {\n this._ensureAnnouncement();\n }\n }\n\n /**\n * Force re-render of all rating items to update star colors\n * This ensures star colors reflect the current value\n */\n private _updateRatingItemsDisplay() {\n const items = this.querySelectorAll('it-rating-item');\n items.forEach((item) => {\n item.requestUpdate();\n });\n }\n\n /**\n * Create or update the visually-hidden announcement element\n * Following BSI pattern: announcement placed directly in the label slot\n */\n private _ensureAnnouncement() {\n // Find the label slot elements (assigned nodes)\n const labelSlot = this.shadowRoot?.querySelector('slot[name=\"label\"]') as HTMLSlotElement;\n if (!labelSlot) return;\n\n // Get the first element in the label slot (the legend/label container)\n const labelElements = labelSlot.assignedElements();\n if (labelElements.length === 0) return;\n\n const labelContainer = labelElements[0];\n\n // Look for existing announcement span\n let announcement = labelContainer.querySelector('.rating-announcement') as HTMLElement;\n\n if (!announcement) {\n // Create the announcement element if it doesn't exist\n announcement = document.createElement('span');\n announcement.className = 'visually-hidden rating-announcement';\n\n // Append to the label container\n labelContainer.appendChild(announcement);\n }\n // Update the text content\n announcement.textContent = ` ${this._getRatingAnnouncement()}`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'it-rating': ItRating;\n }\n}\n"],"names":["it"],"mappings":";;;;;;AAEA,MAAM,WAAW,GAAuB;AACtC,IAAA,KAAK,EAAE,IAAI;AACX,IAAA,KAAK,EAAE,UAAU;AACjB,IAAA,IAAI,EAAE,KAAK;AAEX,IAAA,QAAQ,EAAE,qBAAqB;AAC/B,IAAA,iBAAiB,EAAE,CAAC,MAAc,EAAE,GAAW,KAAK,CAAA,EAAG,MAAM,CAAA,WAAA,EAAc,GAAG,CAAA,CAAE;AAChF,IAAA,iBAAiB,EAAE,CAAC,MAAc,EAAE,GAAW,KAAK,CAAA,EAAG,MAAM,CAAA,WAAA,EAAc,GAAG,CAAA,CAAE;CACjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACDD,mBAAmB,CAACA,WAAE,CAAC;AAEvB;;;;;;;;;AASG;AAEI,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,YAAY,C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1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@italia/rating",
|
|
3
|
+
"description": "Web component it-rating del Design system .italia",
|
|
4
|
+
"version": "1.0.0-alpha.10",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"license": "BSD-3-Clause",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/italia/dev-kit-italia.git",
|
|
12
|
+
"directory": "packages/rating"
|
|
13
|
+
},
|
|
14
|
+
"author": "Presidenza del Consiglio dei Ministri",
|
|
15
|
+
"homepage": "https://italia.github.io/dev-kit-italia",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/italia/dev-kit-italia/issues"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/src/index.js",
|
|
21
|
+
"module": "./dist/src/index.js",
|
|
22
|
+
"types": "./dist/src/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": "./dist/src/index.js",
|
|
25
|
+
"./it-rating.js": "./dist/src/it-rating.js",
|
|
26
|
+
"./it-rating-item.js": "./dist/src/it-rating-item.js",
|
|
27
|
+
"./styles/*": "./styles/*"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/src",
|
|
31
|
+
"README.md",
|
|
32
|
+
"AUTHORS",
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"custom-elements.json"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"bootstrap-italia": "3.0.0-alpha.9",
|
|
38
|
+
"lit": "^3.3.0",
|
|
39
|
+
"@italia/globals": "^1.0.0-alpha.10",
|
|
40
|
+
"@italia/i18n": "^1.0.0-alpha.10",
|
|
41
|
+
"@italia/icon": "^1.0.0-alpha.10",
|
|
42
|
+
"@italia/radio": "^1.0.0-alpha.10"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@custom-elements-manifest/analyzer": "^0.10.3",
|
|
46
|
+
"@open-wc/testing": "^4.0.0",
|
|
47
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
48
|
+
"@rollup/plugin-typescript": "^12.1.1",
|
|
49
|
+
"@web/test-runner": "^0.19.0",
|
|
50
|
+
"rollup": "^4.42.0",
|
|
51
|
+
"rollup-plugin-scss-lit": "^2.1.0",
|
|
52
|
+
"sass": "^1.89.0",
|
|
53
|
+
"tslib": "^2.6.3",
|
|
54
|
+
"typescript": "^5.5.3",
|
|
55
|
+
"@italia/test-config": "^0.0.0",
|
|
56
|
+
"@italia/input": "^1.0.0-alpha.10",
|
|
57
|
+
"@italia/typescript-config": "^0.0.0"
|
|
58
|
+
},
|
|
59
|
+
"customElements": "custom-elements.json",
|
|
60
|
+
"scripts": {
|
|
61
|
+
"analyze": "cem analyze --litelement --exclude dist",
|
|
62
|
+
"build": "rollup --config rollup.config.js",
|
|
63
|
+
"clean": "rimraf node_modules .turbo .rollup.cache dist coverage",
|
|
64
|
+
"prepublish": "pnpm build",
|
|
65
|
+
"lint": "eslint --ext .ts \"src/**/*.ts\" \"stories/**/*.ts\" \"test/**/*.ts\" && stylelint \"styles/**/*.scss\" \"src/**/*.scss\" && prettier \"src/**/*.ts\" \"stories/**/*.ts\" \"test/**/*.ts\" --check",
|
|
66
|
+
"format": "eslint --fix --ext .ts \"src/**/*.ts\" \"stories/**/*.ts\" \"test/**/*.ts\" && stylelint --fix \"styles/**/*.scss\" \"src/**/*.scss\" && prettier --write \"src/**/*.ts\" \"stories/**/*.ts\" \"test/**/*.ts\"",
|
|
67
|
+
"test": "wtr --coverage --node-resolve --config web-test-runner.config.js",
|
|
68
|
+
"test:watch": "wtr --coverage --node-resolve --config web-test-runner.config.js --watch"
|
|
69
|
+
}
|
|
70
|
+
}
|