@italia/rating 1.0.0-beta.0 → 1.0.0-beta.2
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/README.md +6 -161
- package/custom-elements.json +2 -2
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -1,166 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# <it-rating>
|
|
2
2
|
|
|
3
|
-
[
|
|
3
|
+
This package is part of [dev-kit-italia](https://italia.github.io/dev-kit-italia), a Web Components kit for the **.italia** design-system.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Installation and usage
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Most users want to install the full kit by installing [`@italia/dev-kit-italia`](https://npmjs.com/package/@italia/dev-kit-italia), but you have the option of installing this single Web Component separately if needed. Please find detailed installation and usage instructions in the [official documentation](https://italia.github.io/dev-kit-italia/?path=/docs/introduzione--documentazione).
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
npm install @italia/rating
|
|
11
|
-
```
|
|
9
|
+
## Documentation
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
```html
|
|
16
|
-
<script type="module">
|
|
17
|
-
import '@italia/rating';
|
|
18
|
-
</script>
|
|
19
|
-
|
|
20
|
-
<it-rating name="rating" value="3">
|
|
21
|
-
<span slot="legend">Valuta questo servizio</span>
|
|
22
|
-
</it-rating>
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Con Label
|
|
26
|
-
|
|
27
|
-
```html
|
|
28
|
-
<it-rating name="rating" value="4" label="Valutazione">
|
|
29
|
-
</it-rating>
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Sola Lettura
|
|
33
|
-
|
|
34
|
-
```html
|
|
35
|
-
<it-rating name="rating" value="4" read-only>
|
|
36
|
-
</it-rating>
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Disabilitato
|
|
40
|
-
|
|
41
|
-
```html
|
|
42
|
-
<it-rating name="rating" value="3" disabled>
|
|
43
|
-
<span slot="legend">Valutazione</span>
|
|
44
|
-
</it-rating>
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Obbligatorio
|
|
48
|
-
|
|
49
|
-
```html
|
|
50
|
-
<form>
|
|
51
|
-
<it-rating name="rating" required>
|
|
52
|
-
<span slot="legend">Valuta questo contenuto (obbligatorio)</span>
|
|
53
|
-
</it-rating>
|
|
54
|
-
<button type="submit">Invia</button>
|
|
55
|
-
</form>
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
## Proprietà
|
|
59
|
-
|
|
60
|
-
| Proprietà | Tipo | Default | Descrizione |
|
|
61
|
-
|-----------|------|---------|-------------|
|
|
62
|
-
| `name` | `string` | `''` | Nome del campo per l'invio del form |
|
|
63
|
-
| `value` | `number` | `0` | Valore corrente della valutazione (1-5) |
|
|
64
|
-
| `label` | `string` | `''` | Etichetta del rating |
|
|
65
|
-
| `disabled` | `boolean` | `false` | Se il rating è disabilitato |
|
|
66
|
-
| `read-only` | `boolean` | `false` | Se il rating è in sola lettura (non interattivo) |
|
|
67
|
-
| `required` | `boolean` | `false` | Se la selezione è obbligatoria |
|
|
68
|
-
| `max-stars` | `number` | `5` | Numero massimo di stelle |
|
|
69
|
-
|
|
70
|
-
## Eventi
|
|
71
|
-
|
|
72
|
-
### `change`
|
|
73
|
-
|
|
74
|
-
Emesso quando cambia il valore della valutazione.
|
|
75
|
-
|
|
76
|
-
```javascript
|
|
77
|
-
const rating = document.querySelector('it-rating');
|
|
78
|
-
rating.addEventListener('change', (event) => {
|
|
79
|
-
console.log('Nuovo valore:', event.detail.value);
|
|
80
|
-
});
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Slot
|
|
84
|
-
|
|
85
|
-
### `legend`
|
|
86
|
-
|
|
87
|
-
Contenuto della legend del fieldset (label del rating).
|
|
88
|
-
|
|
89
|
-
```html
|
|
90
|
-
<it-rating name="rating">
|
|
91
|
-
<span slot="legend">Valuta questo servizio</span>
|
|
92
|
-
</it-rating>
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
## Accessibilità
|
|
96
|
-
|
|
97
|
-
Il componente implementa le best practice di accessibilità:
|
|
98
|
-
|
|
99
|
-
- Utilizza `role="radiogroup"` per il gruppo di stelle
|
|
100
|
-
- Ogni stella ha `role="radio"` (quando interattivo) o `role="img"` (quando read-only)
|
|
101
|
-
- Supporto completo per la navigazione da tastiera:
|
|
102
|
-
- `Tab`: entra/esce dal rating
|
|
103
|
-
- `Frecce`: naviga tra le stelle
|
|
104
|
-
- `Home`: vai alla prima stella
|
|
105
|
-
- `End`: vai all'ultima stella
|
|
106
|
-
- `Spazio/Enter`: seleziona la stella corrente
|
|
107
|
-
- Etichette aria-label appropriate per ogni stella
|
|
108
|
-
- Supporto per screen reader con testo nascosto visualmente
|
|
109
|
-
|
|
110
|
-
## Integrazione con Form
|
|
111
|
-
|
|
112
|
-
Il componente si integra nativamente con i form HTML:
|
|
113
|
-
|
|
114
|
-
```html
|
|
115
|
-
<form id="reviewForm">
|
|
116
|
-
<it-rating name="rating" value="3" required>
|
|
117
|
-
<span slot="legend">Valutazione</span>
|
|
118
|
-
</it-rating>
|
|
119
|
-
|
|
120
|
-
<button type="submit">Invia recensione</button>
|
|
121
|
-
</form>
|
|
122
|
-
|
|
123
|
-
<script>
|
|
124
|
-
document.getElementById('reviewForm').addEventListener('submit', (e) => {
|
|
125
|
-
e.preventDefault();
|
|
126
|
-
const formData = new FormData(e.target);
|
|
127
|
-
console.log('Rating:', formData.get('rating'));
|
|
128
|
-
});
|
|
129
|
-
</script>
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## Validazione
|
|
133
|
-
|
|
134
|
-
Il componente supporta la validazione HTML5:
|
|
135
|
-
|
|
136
|
-
```javascript
|
|
137
|
-
const rating = document.querySelector('it-rating');
|
|
138
|
-
|
|
139
|
-
// Verifica validità
|
|
140
|
-
if (rating.checkValidity()) {
|
|
141
|
-
console.log('Rating valido');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Mostra errori di validazione
|
|
145
|
-
rating.reportValidity();
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
## Personalizzazione CSS
|
|
149
|
-
|
|
150
|
-
```css
|
|
151
|
-
it-rating {
|
|
152
|
-
--rating-star-size: 1.5rem;
|
|
153
|
-
--rating-star-color: #ffc107;
|
|
154
|
-
--rating-star-empty-color: #e0e0e0;
|
|
155
|
-
}
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
## Browser Support
|
|
159
|
-
|
|
160
|
-
- Chrome/Edge (ultimo + 1 versione precedente)
|
|
161
|
-
- Firefox (ultimo + 1 versione precedente)
|
|
162
|
-
- Safari (ultimo + 1 versione precedente)
|
|
163
|
-
|
|
164
|
-
## Licenza
|
|
165
|
-
|
|
166
|
-
BSD-3-Clause © Presidenza del Consiglio dei Ministri
|
|
11
|
+
Find the usage instructions for this specific component in its [dedicated documentation page](https://italia.github.io/dev-kit-italia/?path=/docs/componenti-rating--documentazione).
|
package/custom-elements.json
CHANGED
|
@@ -256,7 +256,7 @@
|
|
|
256
256
|
{
|
|
257
257
|
"kind": "variable",
|
|
258
258
|
"name": "meta",
|
|
259
|
-
"default": "{ title: 'Componenti/Rating', tags: ['web-component', 'a11y-ok'], component: 'it-rating', args: { name: 'rating', value: 0, disabled: false, readOnly: false, required: false, icon: 'it-star-outline', maxElements: 5, }, argTypes: { name: { control: 'text', description: \"Nome del campo per l'invio del form\", }, value: { control: { type: 'number', min: 0, max: 5, step: 1 }, description: 'Valore corrente della valutazione (0-5, 0 = nessuna stella selezionata)', }, icon: { control: 'text', description: \"Nome dell'icona da utilizzare per gli item del rating\", table: { defaultValue: { summary: 'it-star-outline' } }, }, disabled: { control: 'boolean', type: 'boolean', description: 'Se il rating è disabilitato', table: { defaultValue: { summary: 'false' } }, }, readOnly: { name: 'read-only', control: 'boolean', type: 'boolean', description: 'Se il rating è in sola lettura (non interattivo)', table: { defaultValue: { summary: 'false' } }, }, required: { control: 'boolean', type: 'boolean', description: 'Se la selezione è obbligatoria', table: { defaultValue: { summary: 'false' } }, }, maxElements: { name: 'max-elements', control: { type: 'number', min: 1, step: 1 }, description: 'Numero massimo di elementi nel rating, per messaggi di supporto e accessibilità, modificare rispetto al default solo se si cambia il numero di elementi visualizzati rispetto al default di 5', table: { defaultValue: { summary: '5' } }, }, }, } satisfies Meta<RatingProps>"
|
|
259
|
+
"default": "{ title: 'Componenti/Rating', tags: ['web-component', 'a11y-ok'], component: 'it-rating', args: { name: 'rating', value: 0, disabled: false, readOnly: false, required: false, icon: 'it-star-outline', maxElements: 5, form: '', customValidation: false, validityMessage: '', }, argTypes: { name: { control: 'text', description: \"Nome del campo per l'invio del form\", }, value: { control: { type: 'number', min: 0, max: 5, step: 1 }, description: 'Valore corrente della valutazione (0-5, 0 = nessuna stella selezionata)', }, icon: { control: 'text', description: \"Nome dell'icona da utilizzare per gli item del rating\", table: { defaultValue: { summary: 'it-star-outline' } }, }, disabled: { control: 'boolean', type: 'boolean', description: 'Se il rating è disabilitato', table: { defaultValue: { summary: 'false' } }, }, readOnly: { name: 'read-only', control: 'boolean', type: 'boolean', description: 'Se il rating è in sola lettura (non interattivo)', table: { defaultValue: { summary: 'false' } }, }, required: { control: 'boolean', type: 'boolean', description: 'Se la selezione è obbligatoria', table: { defaultValue: { summary: 'false' } }, }, maxElements: { name: 'max-elements', control: { type: 'number', min: 1, step: 1 }, description: 'Numero massimo di elementi nel rating, per messaggi di supporto e accessibilità, modificare rispetto al default solo se si cambia il numero di elementi visualizzati rispetto al default di 5', table: { defaultValue: { summary: '5' } }, }, form: { control: 'text', description: \"ID html del form a cui è associato il componente it-radio-group, se non si trova all'interno di una form \", }, customValidation: { name: 'custom-validation', control: 'boolean', type: 'boolean', table: { defaultValue: { summary: 'false' } }, description: 'Se la validazione del radio group è fatta esternamente (lato server o con plugin js - validazione custom), impostare questo attributo a `true`.', }, validityMessage: { name: 'validity-message', control: 'text', description: \"Messaggio da mostrare quando il radio group è invalido nel caso di validazione esterna (validazione custom). Se impostato a '' (stringa vuota) il campo viene considerato valido.\", }, }, } satisfies Meta<RatingProps>"
|
|
260
260
|
},
|
|
261
261
|
{
|
|
262
262
|
"kind": "variable",
|
|
@@ -264,7 +264,7 @@
|
|
|
264
264
|
"type": {
|
|
265
265
|
"text": "Story"
|
|
266
266
|
},
|
|
267
|
-
"default": "{ ...meta, name: 'Esempio interattivo', tags: ['!autodocs', '!dev'], parameters: { docs: { canvas: { sourceState: 'shown', }, }, }, render: (args) => html` <it-rating name=${ifDefined(args.name || undefined)} value=${args.value.toString()} ?disabled=${args.disabled} ?read-only=${args.readOnly} ?required=${args.required} @change=${(e: CustomEvent) => { console.log('Rating changed:', (e.target as HTMLElement).getAttribute('value')); }} icon=${ifDefined(args.icon || undefined)} max-elements=${args.maxElements.toString()} > <span slot=\"label\">Valuta questo contenuto</span> <it-rating-item value=\"1\" ?checked=${args.value === 1}> <span slot=\"label\">1 stella</span> </it-rating-item> <it-rating-item value=\"2\" ?checked=${args.value === 2}> <span slot=\"label\">2 stelle</span> </it-rating-item> <it-rating-item value=\"3\" ?checked=${args.value === 3}> <span slot=\"label\">3 stelle</span> </it-rating-item> <it-rating-item value=\"4\" ?checked=${args.value === 4}> <span slot=\"label\">4 stelle</span> </it-rating-item> <it-rating-item value=\"5\" ?checked=${args.value === 5}> <span slot=\"label\">5 stelle</span> </it-rating-item> </it-rating> `, }"
|
|
267
|
+
"default": "{ ...meta, name: 'Esempio interattivo', tags: ['!autodocs', '!dev'], parameters: { docs: { canvas: { sourceState: 'shown', }, }, }, render: (args) => html` <it-rating name=${ifDefined(args.name || undefined)} value=${args.value.toString()} ?disabled=${args.disabled} ?read-only=${args.readOnly} ?required=${args.required} @change=${(e: CustomEvent) => { console.log('Rating changed:', (e.target as HTMLElement).getAttribute('value')); }} icon=${ifDefined(args.icon || undefined)} max-elements=${args.maxElements.toString()} form=\"${ifDefined(args.form || undefined)}\" ?custom-validation=\"${args.customValidation}\" validity-message=\"${ifDefined(args.validityMessage || undefined)}\" > <span slot=\"label\">Valuta questo contenuto</span> <it-rating-item value=\"1\" ?checked=${args.value === 1}> <span slot=\"label\">1 stella</span> </it-rating-item> <it-rating-item value=\"2\" ?checked=${args.value === 2}> <span slot=\"label\">2 stelle</span> </it-rating-item> <it-rating-item value=\"3\" ?checked=${args.value === 3}> <span slot=\"label\">3 stelle</span> </it-rating-item> <it-rating-item value=\"4\" ?checked=${args.value === 4}> <span slot=\"label\">4 stelle</span> </it-rating-item> <it-rating-item value=\"5\" ?checked=${args.value === 5}> <span slot=\"label\">5 stelle</span> </it-rating-item> </it-rating> `, }"
|
|
268
268
|
},
|
|
269
269
|
{
|
|
270
270
|
"kind": "variable",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@italia/rating",
|
|
3
3
|
"description": "Web component it-rating del Design system .italia",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"custom-elements.json"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"bootstrap-italia": "3.0.0-beta.
|
|
37
|
+
"bootstrap-italia": "3.0.0-beta.5",
|
|
38
38
|
"lit": "^3.3.0",
|
|
39
|
-
"@italia/globals": "^1.0.0-beta.
|
|
40
|
-
"@italia/i18n": "^1.0.0-beta.
|
|
41
|
-
"@italia/icon": "^1.0.0-beta.
|
|
42
|
-
"@italia/radio": "^1.0.0-beta.
|
|
39
|
+
"@italia/globals": "^1.0.0-beta.2",
|
|
40
|
+
"@italia/i18n": "^1.0.0-beta.2",
|
|
41
|
+
"@italia/icon": "^1.0.0-beta.2",
|
|
42
|
+
"@italia/radio": "^1.0.0-beta.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@custom-elements-manifest/analyzer": "^0.10.3",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"sass": "^1.89.0",
|
|
53
53
|
"tslib": "^2.6.3",
|
|
54
54
|
"typescript": "^5.5.3",
|
|
55
|
-
"@italia/test-config": "^1.0.0-beta.
|
|
56
|
-
"@italia/input": "^1.0.0-beta.
|
|
57
|
-
"@italia/typescript-config": "^1.0.0-beta.
|
|
55
|
+
"@italia/test-config": "^1.0.0-beta.2",
|
|
56
|
+
"@italia/input": "^1.0.0-beta.2",
|
|
57
|
+
"@italia/typescript-config": "^1.0.0-beta.1"
|
|
58
58
|
},
|
|
59
59
|
"customElements": "custom-elements.json",
|
|
60
60
|
"scripts": {
|