@italia/toggle 1.0.0-alpha.7

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 ADDED
@@ -0,0 +1,3 @@
1
+ Copyright (c) 2025 Dipartimento per la trasformazione digitale - Presidenza del Consiglio dei Ministri
2
+
3
+ The version control system provides attribution for specific lines of code.
package/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Copyright (c) 2025, the respective contributors, as shown by the AUTHORS file.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # \<it-toggle>
2
+
3
+ This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i @italia/toggle
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```html
14
+ <script type="module">
15
+ import '@italia/toggle';
16
+ </script>
17
+
18
+ <it-toggle>
19
+ <span slot="label">Toggle label</span>
20
+ </it-toggle>
21
+ ```
22
+
23
+ ## Linting and formatting
24
+
25
+ To scan the project for linting and formatting errors, run
26
+
27
+ ```bash
28
+ npm run lint
29
+ ```
30
+
31
+ To automatically fix linting and formatting errors, run
32
+
33
+ ```bash
34
+ npm run format
35
+ ```
36
+
37
+ ## Testing with Web Test Runner
38
+
39
+ To execute a single test run:
40
+
41
+ ```bash
42
+ npm run test
43
+ ```
44
+
45
+ To run the tests in interactive watch mode run:
46
+
47
+ ```bash
48
+ npm run test:watch
49
+ ```
50
+
51
+ ## Demoing with Storybook
52
+
53
+ To run a local instance of Storybook for your component, run
54
+
55
+ ```bash
56
+ npm run storybook
57
+ ```
58
+
59
+ To build a production version of Storybook, run
60
+
61
+ ```bash
62
+ npm run storybook:build
63
+ ```
64
+
65
+ ## Tooling configs
66
+
67
+ For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
68
+
69
+ If you customize the configuration a lot, you can consider moving them to individual files.
70
+
71
+ ## Local Demo with `web-dev-server`
72
+
73
+ ```bash
74
+ npm start
75
+ ```
76
+
77
+ To run a local development server that serves the basic demo located in `demo/index.html`
@@ -0,0 +1,251 @@
1
+ {
2
+ "schemaVersion": "1.0.0",
3
+ "readme": "",
4
+ "modules": [
5
+ {
6
+ "kind": "javascript-module",
7
+ "path": "src/index.ts",
8
+ "declarations": [],
9
+ "exports": [
10
+ {
11
+ "kind": "js",
12
+ "name": "ItToggle",
13
+ "declaration": {
14
+ "name": "ItToggle",
15
+ "module": "./it-toggle.js"
16
+ }
17
+ },
18
+ {
19
+ "kind": "js",
20
+ "name": "ItToggleGroup",
21
+ "declaration": {
22
+ "name": "ItToggleGroup",
23
+ "module": "./it-toggle-group.js"
24
+ }
25
+ }
26
+ ]
27
+ },
28
+ {
29
+ "kind": "javascript-module",
30
+ "path": "src/it-toggle-group.ts",
31
+ "declarations": [
32
+ {
33
+ "kind": "class",
34
+ "description": "",
35
+ "name": "ItToggleGroup",
36
+ "members": [
37
+ {
38
+ "kind": "field",
39
+ "name": "checkboxes",
40
+ "type": {
41
+ "text": "ItToggle[]"
42
+ }
43
+ }
44
+ ],
45
+ "superclass": {
46
+ "name": "ItCheckboxGroupBase",
47
+ "package": "@italia/checkbox/it-checkbox-group-base.js"
48
+ },
49
+ "tagName": "it-toggle",
50
+ "customElement": true
51
+ }
52
+ ],
53
+ "exports": [
54
+ {
55
+ "kind": "js",
56
+ "name": "ItToggleGroup",
57
+ "declaration": {
58
+ "name": "ItToggleGroup",
59
+ "module": "src/it-toggle-group.ts"
60
+ }
61
+ },
62
+ {
63
+ "kind": "custom-element-definition",
64
+ "name": "it-toggle-group",
65
+ "declaration": {
66
+ "name": "ItToggleGroup",
67
+ "module": "src/it-toggle-group.ts"
68
+ }
69
+ }
70
+ ]
71
+ },
72
+ {
73
+ "kind": "javascript-module",
74
+ "path": "src/it-toggle.ts",
75
+ "declarations": [
76
+ {
77
+ "kind": "class",
78
+ "description": "",
79
+ "name": "ItToggle",
80
+ "members": [
81
+ {
82
+ "kind": "field",
83
+ "name": "type",
84
+ "type": {
85
+ "text": "string"
86
+ },
87
+ "default": "'checkbox'"
88
+ }
89
+ ],
90
+ "superclass": {
91
+ "name": "ItCheckboxBase",
92
+ "package": "@italia/checkbox/it-checkbox-base.js"
93
+ },
94
+ "tagName": "it-toggle",
95
+ "customElement": true
96
+ }
97
+ ],
98
+ "exports": [
99
+ {
100
+ "kind": "js",
101
+ "name": "ItToggle",
102
+ "declaration": {
103
+ "name": "ItToggle",
104
+ "module": "src/it-toggle.ts"
105
+ }
106
+ },
107
+ {
108
+ "kind": "custom-element-definition",
109
+ "name": "it-toggle",
110
+ "declaration": {
111
+ "name": "ItToggle",
112
+ "module": "src/it-toggle.ts"
113
+ }
114
+ }
115
+ ]
116
+ },
117
+ {
118
+ "kind": "javascript-module",
119
+ "path": "stories/it-toggle.stories.ts",
120
+ "declarations": [
121
+ {
122
+ "kind": "variable",
123
+ "name": "meta",
124
+ "default": "{ title: 'Componenti/Form/Toggle', tags: ['alpha', 'a11y-ok', 'web-component'], component: 'it-toggle', args: { id: '', label: \"Label dell'interruttore\", name: 'toggle-esempio', value: undefined, checked: false, disabled: false, form: undefined, customValidation: false, validityMessage: '', required: false, inline: false, group: false, supportText: '', }, argTypes: { id: { control: 'text', description: 'ID del campo', type: 'string', }, label: { control: 'text', description: 'Etichetta del campo', type: 'string', }, name: { control: 'text', description: 'Nome del campo nel form', type: 'string', }, value: { control: 'text', description: 'Valore del campo', type: 'string', }, checked: { control: 'boolean', type: 'boolean', table: { defaultValue: { summary: 'false' } }, }, disabled: { control: 'boolean', type: 'boolean', table: { defaultValue: { summary: 'false' } }, }, form: { control: 'text', type: 'string', description: \"ID html del form a cui è associato il campo, se il campo 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 campo è fatta esternamente (lato server o con plugin js - validazione custom), impostare questo attributo a `true`.', }, validityMessage: { name: 'validity-message', control: 'text', type: 'string', description: \"Messaggio da mostrare quando il campo è invalido nel caso di validazione esterna (validazione custom). Se impostato a '' (stringa vuota) il campo viene considerato valido.\", }, required: { control: 'boolean', type: 'boolean', table: { defaultValue: { summary: 'false' } }, }, inline: { control: 'boolean', type: 'boolean', description: 'Allinea i toggle orizzontalmente', table: { defaultValue: { summary: 'false' } }, }, group: { control: 'boolean', type: 'boolean', description: 'Raggruppa visivamente i toggle', table: { defaultValue: { summary: 'false' } }, }, supportText: { name: 'support-text', control: 'text', description: 'Testo di supporto/aiuto sotto il toggle', type: 'string', }, }, } satisfies Meta<ToggleProps>"
125
+ },
126
+ {
127
+ "kind": "variable",
128
+ "name": "EsempioInterattivo",
129
+ "type": {
130
+ "text": "Story"
131
+ },
132
+ "default": "{ ...meta, name: 'Esempio interattivo', tags: ['!dev'], parameters: { docs: { canvas: { sourceState: 'shown', }, }, }, render: (params) => html`${renderComponent({ ...params, })} `, }"
133
+ },
134
+ {
135
+ "kind": "variable",
136
+ "name": "Attivo",
137
+ "type": {
138
+ "text": "Story"
139
+ },
140
+ "default": "{ name: 'Attivo (checked)', args: { checked: true }, render: (params) => html`${renderComponent({ ...params, label: 'Interruttore attivo', })} `, }"
141
+ },
142
+ {
143
+ "kind": "variable",
144
+ "name": "Disabilitato",
145
+ "type": {
146
+ "text": "Story"
147
+ },
148
+ "default": "{ args: { disabled: true }, render: (params) => html` <div class=\"mb-3\"> <h6 class=\"mb-2\">Disabilitati</h6> ${renderComponent({ ...params, label: 'Interruttore disabilitato (spento)', })} </div> <div class=\"mb-3\"> ${renderComponent({ ...params, label: 'Interruttore disabilitato (acceso)', checked: true, })} </div> `, }"
149
+ },
150
+ {
151
+ "kind": "variable",
152
+ "name": "Inline",
153
+ "type": {
154
+ "text": "Story"
155
+ },
156
+ "default": "{ args: { inline: true, name: 'toggle-inline' }, render: (params) => html` <it-toggle-group name=${params.name} ?required=${params.required} ?group=${params.group} ?inline=${params.inline}> <span slot=\"legend\">Gruppo di toggle</span> ${renderComponent({ ...params, label: 'Interruttore 1', value: 'option1', required: undefined, name: undefined, group: undefined, inline: undefined, })} ${renderComponent({ ...params, label: 'Interruttore 2', value: 'option2', checked: true, required: undefined, name: undefined, group: undefined, inline: undefined, })} ${renderComponent({ ...params, label: 'Interruttore 3', value: 'option3', required: undefined, name: undefined, group: undefined, inline: undefined, })} </it-toggle-group> `, }"
157
+ },
158
+ {
159
+ "kind": "variable",
160
+ "name": "Raggruppati",
161
+ "type": {
162
+ "text": "Story"
163
+ },
164
+ "default": "{ name: 'Raggruppati visivamente', args: { group: true }, parameters: { pageLayout: 'w-100' }, render: (params) => html` <it-toggle-group name=${params.name} ?required=${params.required} ?group=${params.group} ?inline=${params.inline} ?disabled=${params.disabled} > <span slot=\"legend\">Gruppo di toggle</span> ${renderComponent({ ...params, label: 'Interruttore acceso', value: 'option1', checked: true, required: undefined, name: undefined, group: undefined, inline: undefined, })} ${renderComponent({ ...params, label: 'Interruttore spento', value: 'option2', required: undefined, name: undefined, group: undefined, inline: undefined, })} ${renderComponent({ ...params, label: 'Interruttore disabilitato', value: 'option3', disabled: true, required: undefined, name: undefined, group: undefined, inline: undefined, })} </it-toggle-group> <it-toggle-group name=${`${params.name}-1`} ?required=${params.required} ?group=${params.group} ?inline=${params.inline} ?disabled=${params.disabled} style=\"margin-top: 24px;\" > <span slot=\"legend\">Gruppo di toggle</span> ${renderComponent({ ...params, required: undefined, name: undefined, group: undefined, inline: undefined, label: 'Interruttore acceso', value: 'option1', checked: true, supportText: \"Testo descrittivo di supporto per l'opzione selezionabile\", })} ${renderComponent({ ...params, required: undefined, name: undefined, group: undefined, inline: undefined, label: 'Interruttore spento', value: 'option2', supportText: \"Testo descrittivo di supporto per l'opzione selezionabile\", })} ${renderComponent({ ...params, required: undefined, name: undefined, group: undefined, inline: undefined, disabled: true, label: 'Interruttore disabilitato', value: 'option3', supportText: \"Testo descrittivo di supporto per l'opzione selezionabile\", })} </it-toggle-group> `, }"
165
+ },
166
+ {
167
+ "kind": "variable",
168
+ "name": "ConTestoSupporto",
169
+ "type": {
170
+ "text": "Story"
171
+ },
172
+ "default": "{ name: 'Con testo di supporto', args: { supportText: 'Abilita questa funzionalità per migliorare le prestazioni' }, render: (params) => html`${renderComponent({ ...params, label: 'Abilita modalità prestazioni', })} `, }"
173
+ },
174
+ {
175
+ "kind": "variable",
176
+ "name": "StatoDefault",
177
+ "type": {
178
+ "text": "Story"
179
+ },
180
+ "default": "{ name: 'Stato default', render: (params) => html`${renderComponent({ ...params, label: \"Label dell'interruttore\", })} `, }"
181
+ }
182
+ ],
183
+ "exports": [
184
+ {
185
+ "kind": "js",
186
+ "name": "default",
187
+ "declaration": {
188
+ "name": "meta",
189
+ "module": "stories/it-toggle.stories.ts"
190
+ }
191
+ },
192
+ {
193
+ "kind": "js",
194
+ "name": "EsempioInterattivo",
195
+ "declaration": {
196
+ "name": "EsempioInterattivo",
197
+ "module": "stories/it-toggle.stories.ts"
198
+ }
199
+ },
200
+ {
201
+ "kind": "js",
202
+ "name": "Attivo",
203
+ "declaration": {
204
+ "name": "Attivo",
205
+ "module": "stories/it-toggle.stories.ts"
206
+ }
207
+ },
208
+ {
209
+ "kind": "js",
210
+ "name": "Disabilitato",
211
+ "declaration": {
212
+ "name": "Disabilitato",
213
+ "module": "stories/it-toggle.stories.ts"
214
+ }
215
+ },
216
+ {
217
+ "kind": "js",
218
+ "name": "Inline",
219
+ "declaration": {
220
+ "name": "Inline",
221
+ "module": "stories/it-toggle.stories.ts"
222
+ }
223
+ },
224
+ {
225
+ "kind": "js",
226
+ "name": "Raggruppati",
227
+ "declaration": {
228
+ "name": "Raggruppati",
229
+ "module": "stories/it-toggle.stories.ts"
230
+ }
231
+ },
232
+ {
233
+ "kind": "js",
234
+ "name": "ConTestoSupporto",
235
+ "declaration": {
236
+ "name": "ConTestoSupporto",
237
+ "module": "stories/it-toggle.stories.ts"
238
+ }
239
+ },
240
+ {
241
+ "kind": "js",
242
+ "name": "StatoDefault",
243
+ "declaration": {
244
+ "name": "StatoDefault",
245
+ "module": "stories/it-toggle.stories.ts"
246
+ }
247
+ }
248
+ ]
249
+ }
250
+ ]
251
+ }
@@ -0,0 +1,3 @@
1
+ export { ItToggle } from './it-toggle.js';
2
+ export { ItToggleGroup } from './it-toggle-group.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { ItToggle } from './it-toggle.js';
2
+ export { ItToggleGroup } from './it-toggle-group.js';
3
+ import '../tslib.es6-Cv888lzs.js';
4
+ import 'lit/decorators.js';
5
+ import 'lit';
6
+ import '@italia/checkbox/it-checkbox-base.js';
7
+ import '@italia/checkbox/it-checkbox-group-base.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -0,0 +1,11 @@
1
+ import { ItCheckboxGroupBase } from '@italia/checkbox/it-checkbox-group-base.js';
2
+ import { ItToggle } from '@italia/toggle';
3
+ export declare class ItToggleGroup extends ItCheckboxGroupBase {
4
+ checkboxes: ItToggle[];
5
+ }
6
+ declare global {
7
+ interface HTMLElementTagNameMap {
8
+ 'it-toggle-group': ItToggleGroup;
9
+ }
10
+ }
11
+ //# sourceMappingURL=it-toggle-group.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"it-toggle-group.d.ts","sourceRoot":"","sources":["../../src/it-toggle-group.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAO1C,qBACa,aAAc,SAAQ,mBAAmB;IAKpD,UAAU,EAAG,QAAQ,EAAE,CAAC;CACzB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,iBAAiB,EAAE,aAAa,CAAC;KAClC;CACF"}
@@ -0,0 +1,16 @@
1
+ import { _ as __decorate, a as __metadata } from '../tslib.es6-Cv888lzs.js';
2
+ import { queryAssignedElements, customElement } from 'lit/decorators.js';
3
+ import { ItCheckboxGroupBase } from '@italia/checkbox/it-checkbox-group-base.js';
4
+
5
+ let ItToggleGroup = class ItToggleGroup extends ItCheckboxGroupBase {
6
+ };
7
+ __decorate([
8
+ queryAssignedElements({ selector: 'it-toggle' }),
9
+ __metadata("design:type", Array)
10
+ ], ItToggleGroup.prototype, "checkboxes", void 0);
11
+ ItToggleGroup = __decorate([
12
+ customElement('it-toggle-group')
13
+ ], ItToggleGroup);
14
+
15
+ export { ItToggleGroup };
16
+ //# sourceMappingURL=it-toggle-group.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"it-toggle-group.js","sources":["../../../src/it-toggle-group.ts"],"sourcesContent":["import { customElement, queryAssignedElements } from 'lit/decorators.js';\nimport { ItCheckboxGroupBase } from '@italia/checkbox/it-checkbox-group-base.js';\nimport { ItToggle } from '@italia/toggle';\n\n// import styles from './toggle.scss';\n\n/**\n * @element it-toggle\n */\n@customElement('it-toggle-group')\nexport class ItToggleGroup extends ItCheckboxGroupBase {\n // static override styles = [ItCheckboxGroupBase.styles, styles];\n\n // Query per le checkbox assegnate nello slot\n @queryAssignedElements({ selector: 'it-toggle' })\n checkboxes!: ItToggle[];\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'it-toggle-group': ItToggleGroup;\n }\n}\n"],"names":[],"mappings":";;;;AAUO,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,mBAAmB,CAAA;;AAKpD,UAAA,CAAA;AADC,IAAA,qBAAqB,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;;AACzB,CAAA,EAAA,aAAA,CAAA,SAAA,EAAA,YAAA,EAAA,MAAA,CAAA;AALb,aAAa,GAAA,UAAA,CAAA;IADzB,aAAa,CAAC,iBAAiB;AACnB,CAAA,EAAA,aAAa,CAMzB;;;;"}
@@ -0,0 +1,12 @@
1
+ import { ItCheckboxBase } from '@italia/checkbox/it-checkbox-base.js';
2
+ export declare class ItToggle extends ItCheckboxBase {
3
+ static styles: import("lit").CSSResultGroup[];
4
+ type: string;
5
+ render(): import("lit").TemplateResult<1>;
6
+ }
7
+ declare global {
8
+ interface HTMLElementTagNameMap {
9
+ 'it-toggle': ItToggle;
10
+ }
11
+ }
12
+ //# sourceMappingURL=it-toggle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"it-toggle.d.ts","sourceRoot":"","sources":["../../src/it-toggle.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAOtE,qBACa,QAAS,SAAQ,cAAc;IAC1C,OAAgB,MAAM,iCAAmC;IAEzD,IAAI,SAAc;IAET,MAAM;CA2BhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,WAAW,EAAE,QAAQ,CAAC;KACvB;CACF"}