@italia/rating 1.0.0-alpha.5

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.
@@ -0,0 +1,455 @@
1
+ import { _ as __decorate } from '../tslib.es6-Cv888lzs.js';
2
+ import { css, html } from 'lit';
3
+ import { customElement } from 'lit/decorators.js';
4
+ import { ItRadio } from '@italia/radio';
5
+ import '@italia/icon';
6
+
7
+ var styles = css`@charset "UTF-8";
8
+ /***************************** 1 ****************************************/
9
+ /***************************** 2 ****************************************/
10
+ /***************************** 1 ****************************************/
11
+ /***************************** 2 ****************************************/
12
+ /***************************** 1 ****************************************/
13
+ /***************************** 2 ****************************************/
14
+ /***************************** 3 ****************************************/
15
+ /***************************** 1 ****************************************/
16
+ /***************************** 2 ****************************************/
17
+ /***************************** 3 ****************************************/
18
+ /***************************** NEUTRAL 1 ****************************************/
19
+ /***************************** NEUTRAL 2 ****************************************/
20
+ /***************************** NEUTRAL 2 / 3 ****************************************/
21
+ *,
22
+ *::before,
23
+ *::after {
24
+ box-sizing: border-box;
25
+ }
26
+
27
+ @media (prefers-reduced-motion: no-preference) {
28
+ :root {
29
+ scroll-behavior: smooth;
30
+ }
31
+ }
32
+
33
+ body {
34
+ margin: 0;
35
+ -webkit-text-size-adjust: 100%;
36
+ -webkit-tap-highlight-color: hsla(0, 0%, 0%, 0);
37
+ }
38
+
39
+ hr {
40
+ margin: 1rem 0;
41
+ color: inherit;
42
+ border: 0;
43
+ border-top: 1px solid;
44
+ opacity: 0.25;
45
+ }
46
+
47
+ p {
48
+ margin-top: 0;
49
+ margin-bottom: var(--bsi-paragraph-spacing);
50
+ }
51
+
52
+ abbr[title] {
53
+ text-decoration: underline dotted;
54
+ cursor: help;
55
+ text-decoration-skip-ink: none;
56
+ }
57
+
58
+ address {
59
+ margin-bottom: var(--bsi-spacing-s);
60
+ font-style: normal;
61
+ line-height: inherit;
62
+ }
63
+
64
+ ol,
65
+ ul {
66
+ padding-left: var(--bsi-spacing-l);
67
+ }
68
+
69
+ ol,
70
+ ul,
71
+ dl {
72
+ margin-top: 0;
73
+ margin-bottom: var(--bsi-spacing-s);
74
+ }
75
+
76
+ ol ol,
77
+ ul ul,
78
+ ol ul,
79
+ ul ol {
80
+ margin-bottom: 0;
81
+ }
82
+
83
+ dt {
84
+ font-weight: var(--bsi-font-weight-strong);
85
+ }
86
+
87
+ dd {
88
+ margin-bottom: var(--bsi-spacing-xxs);
89
+ margin-left: 0;
90
+ }
91
+
92
+ blockquote {
93
+ margin: 0 0 var(--bsi-spacing-s);
94
+ }
95
+
96
+ sub,
97
+ sup {
98
+ position: relative;
99
+ font-size: var(--bsi-font-size-1);
100
+ line-height: 0;
101
+ vertical-align: baseline;
102
+ }
103
+
104
+ sub {
105
+ bottom: -0.25em;
106
+ }
107
+
108
+ sup {
109
+ top: -0.5em;
110
+ }
111
+
112
+ a {
113
+ color: var(--bsi-color-link);
114
+ text-decoration: underline;
115
+ text-decoration-skip-ink: auto;
116
+ text-underline-offset: 2px;
117
+ }
118
+ a:hover {
119
+ color: var(--bsi-color-link-hover);
120
+ }
121
+
122
+ pre,
123
+ code,
124
+ kbd,
125
+ samp {
126
+ font-size: 1em;
127
+ }
128
+
129
+ pre {
130
+ display: block;
131
+ margin-top: 0;
132
+ margin-bottom: var(--bsi-paragraph-spacing);
133
+ overflow: auto;
134
+ }
135
+ pre code {
136
+ word-break: normal;
137
+ }
138
+
139
+ a > code {
140
+ color: inherit;
141
+ }
142
+
143
+ figure {
144
+ margin: 0 0 1rem;
145
+ }
146
+
147
+ img,
148
+ svg {
149
+ vertical-align: middle;
150
+ }
151
+
152
+ table {
153
+ caption-side: bottom;
154
+ border-collapse: collapse;
155
+ }
156
+
157
+ caption {
158
+ padding-top: 0.5rem;
159
+ padding-bottom: 0.5rem;
160
+ color: hsl(210, 17%, 44%);
161
+ text-align: left;
162
+ }
163
+
164
+ th {
165
+ text-align: inherit;
166
+ text-align: -webkit-match-parent;
167
+ }
168
+
169
+ thead,
170
+ tbody,
171
+ tfoot,
172
+ tr,
173
+ td,
174
+ th {
175
+ border-color: inherit;
176
+ border-style: solid;
177
+ border-width: 0;
178
+ }
179
+
180
+ label {
181
+ display: inline-block;
182
+ }
183
+
184
+ button {
185
+ border-radius: 0;
186
+ }
187
+
188
+ button:focus:not(:focus-visible) {
189
+ outline: 0;
190
+ }
191
+
192
+ input,
193
+ button,
194
+ select,
195
+ optgroup,
196
+ textarea {
197
+ margin: 0;
198
+ font-family: inherit;
199
+ font-size: inherit;
200
+ line-height: inherit;
201
+ }
202
+
203
+ button,
204
+ select {
205
+ text-transform: none;
206
+ }
207
+
208
+ [role=button] {
209
+ cursor: pointer;
210
+ }
211
+
212
+ select {
213
+ word-wrap: normal;
214
+ }
215
+ select:disabled {
216
+ opacity: 1;
217
+ }
218
+
219
+ [list]:not([type=date]):not([type=datetime-local]):not([type=month]):not([type=week]):not([type=time])::-webkit-calendar-picker-indicator {
220
+ display: none !important;
221
+ }
222
+
223
+ button,
224
+ [type=button],
225
+ [type=reset],
226
+ [type=submit] {
227
+ -webkit-appearance: button;
228
+ }
229
+ button:not(:disabled),
230
+ [type=button]:not(:disabled),
231
+ [type=reset]:not(:disabled),
232
+ [type=submit]:not(:disabled) {
233
+ cursor: pointer;
234
+ }
235
+
236
+ ::-moz-focus-inner {
237
+ padding: 0;
238
+ border-style: none;
239
+ }
240
+
241
+ textarea {
242
+ resize: vertical;
243
+ }
244
+
245
+ fieldset {
246
+ min-width: 0;
247
+ padding: 0;
248
+ margin: 0;
249
+ border: 0;
250
+ }
251
+
252
+ ::-webkit-datetime-edit-fields-wrapper,
253
+ ::-webkit-datetime-edit-text,
254
+ ::-webkit-datetime-edit-minute,
255
+ ::-webkit-datetime-edit-hour-field,
256
+ ::-webkit-datetime-edit-day-field,
257
+ ::-webkit-datetime-edit-month-field,
258
+ ::-webkit-datetime-edit-year-field {
259
+ padding: 0;
260
+ }
261
+
262
+ ::-webkit-inner-spin-button {
263
+ height: auto;
264
+ }
265
+
266
+ [type=search] {
267
+ outline-offset: -2px;
268
+ -webkit-appearance: textfield;
269
+ }
270
+
271
+ /* rtl:raw:
272
+ [type="tel"],
273
+ [type="url"],
274
+ [type="email"],
275
+ [type="number"] {
276
+ direction: ltr;
277
+ }
278
+ */
279
+ ::-webkit-search-decoration {
280
+ -webkit-appearance: none;
281
+ }
282
+
283
+ ::-webkit-color-swatch-wrapper {
284
+ padding: 0;
285
+ }
286
+
287
+ ::file-selector-button {
288
+ font: inherit;
289
+ -webkit-appearance: button;
290
+ }
291
+
292
+ output {
293
+ display: inline-block;
294
+ }
295
+
296
+ iframe {
297
+ border: 0;
298
+ }
299
+
300
+ summary {
301
+ display: list-item;
302
+ cursor: pointer;
303
+ }
304
+
305
+ progress {
306
+ vertical-align: baseline;
307
+ }
308
+
309
+ [hidden] {
310
+ display: none !important;
311
+ }
312
+
313
+ .visually-hidden,
314
+ .visually-hidden-focusable:not(:focus):not(:focus-within) {
315
+ position: absolute !important;
316
+ width: 1px !important;
317
+ height: 1px !important;
318
+ padding: 0 !important;
319
+ margin: -1px !important;
320
+ overflow: hidden !important;
321
+ clip: rect(0, 0, 0, 0) !important;
322
+ white-space: nowrap !important;
323
+ border: 0 !important;
324
+ }
325
+
326
+ :host {
327
+ display: inline-flex;
328
+ padding: 0;
329
+ margin: 0;
330
+ box-shadow: none !important;
331
+ cursor: pointer;
332
+ -webkit-focus-ring-color: transparent;
333
+ outline: none !important;
334
+ }
335
+
336
+ :host([disabled]) {
337
+ cursor: not-allowed;
338
+ opacity: 0.6;
339
+ }
340
+
341
+ /* Focus ring - mostra quando l'item è focalizzato via tastiera */
342
+ :host(:focus-visible) #star {
343
+ border-radius: var(--bsi-radius-xs);
344
+ box-shadow: 0 0 0 2px hsl(0, 0%, 100%), 0 0 0 5px hsl(0, 0%, 0%) !important;
345
+ outline: none;
346
+ }
347
+
348
+ .rating-item-control {
349
+ display: inline-flex;
350
+ align-items: center;
351
+ padding: 0;
352
+ margin: 0;
353
+ }
354
+
355
+ /* Nascondi completamente l'input invisibile */
356
+ #input {
357
+ position: absolute;
358
+ overflow: hidden;
359
+ width: 1px;
360
+ height: 1px;
361
+ padding: 0;
362
+ border: 0;
363
+ margin: -1px;
364
+ clip: rect(0, 0, 0, 0);
365
+ white-space: nowrap;
366
+ }
367
+
368
+ /* Stile per l'icona stella */
369
+ #star {
370
+ display: inline-flex;
371
+ width: 1.5rem;
372
+ height: 1.5rem;
373
+ color: var(--bsi-form-control-label-color, #5c6f82);
374
+ transition: color var(--bsi-transition-instant) ease-out, transform 0.1s ease-out;
375
+ }
376
+ #star:hover {
377
+ transform: scale(1.1);
378
+ }
379
+
380
+ /* Stella vuota quando non checked */
381
+ :host(:not([checked])) #star,
382
+ :host([aria-checked=false]) #star {
383
+ color: var(--bsi-form-control-label-color, #5c6f82);
384
+ }
385
+
386
+ /* Stato disabled */
387
+ :host([disabled]) #star {
388
+ cursor: not-allowed;
389
+ opacity: 0.6;
390
+ }`;
391
+
392
+ /**
393
+ * Rating item component - extends it-radio to render a star icon
394
+ *
395
+ * @element it-rating-item
396
+ *
397
+ * @slot label - The accessibility label for the star (e.g., "Valuta 3 stelle su 5")
398
+ */
399
+ let ItRatingItem = class ItRatingItem extends ItRadio {
400
+ /**
401
+ * Override group getter to find parent it-rating instead of it-radio-group
402
+ */
403
+ get group() {
404
+ return this.closest('it-rating');
405
+ }
406
+ get icon() {
407
+ return this.group?.icon || 'it-star-outline';
408
+ }
409
+ /**
410
+ * Override _renderInput to render icon instead of radio circle
411
+ * Now that _renderInput is protected in parent, we can override it
412
+ */
413
+ _renderInput() {
414
+ // Get the parent rating to determine which items should be filled
415
+ const rating = this.closest('it-rating');
416
+ const ratingValue = rating ? parseInt(rating.value || '0', 10) : 0;
417
+ const thisValue = parseInt(this.value || '0', 10);
418
+ // Icon should be filled if its value is <= the rating value
419
+ const isFilled = thisValue <= ratingValue;
420
+ // Use primary color only for filled icons
421
+ const iconColor = isFilled ? 'primary' : 'secondary';
422
+ let renderedIcon = this.icon;
423
+ if (isFilled && this.icon === 'it-star-outline') {
424
+ renderedIcon = 'it-star-full';
425
+ }
426
+ return html `
427
+ <div id="input" part="input"></div>
428
+ <it-icon id="star" part="star" name="${renderedIcon}" size="sm" aria-hidden="true" color="${iconColor}"></it-icon>
429
+ `;
430
+ }
431
+ handleSlotChange() {
432
+ // Notify assistive technologies of label change
433
+ this.labelElements.forEach((el) => {
434
+ el.classList.add('visually-hidden');
435
+ });
436
+ }
437
+ /**
438
+ * Override render to use rating-specific structure
439
+ */
440
+ render() {
441
+ return html `
442
+ <div class="rating-item-control">
443
+ ${this._renderInput()}
444
+ <slot name="label" @slotchange=${this.handleSlotChange}></slot>
445
+ </div>
446
+ `;
447
+ }
448
+ };
449
+ ItRatingItem.styles = styles;
450
+ ItRatingItem = __decorate([
451
+ customElement('it-rating-item')
452
+ ], ItRatingItem);
453
+
454
+ export { ItRatingItem };
455
+ //# sourceMappingURL=it-rating-item.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"it-rating-item.js","sources":["../../../src/it-rating-item.ts"],"sourcesContent":["import { html } from 'lit';\nimport { customElement } from 'lit/decorators.js';\nimport { ItRadio } from '@italia/radio';\nimport '@italia/icon';\n\nimport styles from './rating-item.scss';\n\n/**\n * Rating item component - extends it-radio to render a star icon\n *\n * @element it-rating-item\n *\n * @slot label - The accessibility label for the star (e.g., \"Valuta 3 stelle su 5\")\n */\n@customElement('it-rating-item')\nexport class ItRatingItem extends ItRadio {\n static override styles = styles;\n\n /**\n * Override group getter to find parent it-rating instead of it-radio-group\n */\n override get group() {\n return this.closest('it-rating');\n }\n\n get icon(): string {\n return this.group?.icon || 'it-star-outline';\n }\n\n /**\n * Override _renderInput to render icon instead of radio circle\n * Now that _renderInput is protected in parent, we can override it\n */\n protected override _renderInput() {\n // Get the parent rating to determine which items should be filled\n const rating = this.closest('it-rating');\n const ratingValue = rating ? parseInt((rating as any).value || '0', 10) : 0;\n const thisValue = parseInt(this.value || '0', 10);\n\n // Icon should be filled if its value is <= the rating value\n const isFilled = thisValue <= ratingValue;\n\n // Use primary color only for filled icons\n const iconColor = isFilled ? 'primary' : 'secondary';\n let renderedIcon = this.icon;\n if (isFilled && this.icon === 'it-star-outline') {\n renderedIcon = 'it-star-full';\n }\n\n return html`\n <div id=\"input\" part=\"input\"></div>\n <it-icon id=\"star\" part=\"star\" name=\"${renderedIcon}\" size=\"sm\" aria-hidden=\"true\" color=\"${iconColor}\"></it-icon>\n `;\n }\n\n private handleSlotChange() {\n // Notify assistive technologies of label change\n this.labelElements.forEach((el) => {\n el.classList.add('visually-hidden');\n });\n }\n\n /**\n * Override render to use rating-specific structure\n */\n override render() {\n return html`\n <div class=\"rating-item-control\">\n ${this._renderInput()}\n <slot name=\"label\" @slotchange=${this.handleSlotChange}></slot>\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'it-rating-item': ItRatingItem;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA;;;;;;AAMG;AAEI,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,OAAO,CAAA;AAGvC;;AAEG;AACH,IAAA,IAAa,KAAK,GAAA;AAChB,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,C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+ import { type PropertyValues } from 'lit';
2
+ import { ItRadioGroup } from '@italia/radio';
3
+ import { type ItRatingItem } from '@italia/rating';
4
+ /**
5
+ * Rating component - extends it-radio-group for star rating
6
+ *
7
+ * @element it-rating
8
+ *
9
+ * @slot - Contains the `<it-rating-item>` elements
10
+ * @slot label - The label/legend text for the rating
11
+ *
12
+ * @fires {CustomEvent} change - Emitted when the rating value changes
13
+ */
14
+ export declare class ItRating extends ItRadioGroup {
15
+ static styles: import("lit").CSSResultGroup;
16
+ /**
17
+ * Get all slotted rating items
18
+ */
19
+ protected _radios: ItRatingItem[];
20
+ /**
21
+ * Maximum number of stars (to calculate "X out of Y")
22
+ */
23
+ maxElements: number;
24
+ /**
25
+ * Whether the rating is read-only (non-interactive)
26
+ */
27
+ readOnly: boolean;
28
+ /**
29
+ * The icon name to use for the rating item
30
+ * @default 'it-star-outline'
31
+ */
32
+ icon: string;
33
+ /**
34
+ * Sync read-only state to all rating items
35
+ */
36
+ private _syncReadOnlyToItems;
37
+ /**
38
+ * Get the localized rating announcement for screen readers
39
+ */
40
+ private _getRatingAnnouncement;
41
+ /**
42
+ * Override updated to refresh the rating items and announcement when value changes
43
+ */
44
+ updated(changedProperties: PropertyValues): void;
45
+ /**
46
+ * Force re-render of all rating items to update star colors
47
+ * This ensures star colors reflect the current value
48
+ */
49
+ private _updateRatingItemsDisplay;
50
+ /**
51
+ * Create or update the visually-hidden announcement element
52
+ * Following BSI pattern: announcement placed directly in the label slot
53
+ */
54
+ private _ensureAnnouncement;
55
+ }
56
+ declare global {
57
+ interface HTMLElementTagNameMap {
58
+ 'it-rating': ItRating;
59
+ }
60
+ }
61
+ //# sourceMappingURL=it-rating.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"it-rating.d.ts","sourceRoot":"","sources":["../../src/it-rating.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAOnD;;;;;;;;;GASG;AACH,qBACa,QAAS,SAAQ,YAAY;IACxC,OAAgB,MAAM,+BAAU;IAEhC;;OAEG;IAEH,SAAS,CAAC,OAAO,EAAG,YAAY,EAAE,CAAC;IAEnC;;OAEG;IAEH,WAAW,SAAK;IAEhB;;OAEG;IAEH,QAAQ,UAAS;IAEjB;;;OAGG;IAEH,IAAI,SAAqB;IAEzB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAW5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAa9B;;OAEG;IACM,OAAO,CAAC,iBAAiB,EAAE,cAAc;IA+BlD;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IAOjC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;CAyB5B;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,WAAW,EAAE,QAAQ,CAAC;KACvB;CACF"}