desy-html 8.10.2 → 8.11.0

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/docs/index.html CHANGED
@@ -38,6 +38,13 @@
38
38
 
39
39
  <h2>Changelog (English)</h2>
40
40
  <p>What's new in the latest version of desy-html</p>
41
+ <h3>v.8.11.0</h3>
42
+ <ul class="text-sm">
43
+ <li>Added. global funcion to Accordion and Accordion history to open/close all items.</li>
44
+ <li>Added global function to check/uncheck Toggle.</li>
45
+ <li>Bug fixes.</li>
46
+ <li>Improvements in docs.</li>
47
+ </ul>
41
48
  <h3>v.8.10.2</h3>
42
49
  <ul class="text-sm">
43
50
  <li>Updated Tailwind CSS form and typography plugins.</li>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "desy-html",
3
- "version": "8.10.2",
3
+ "version": "8.11.0",
4
4
  "description": "desy-html contains the code you need to start building a user interface for Gobierno de Aragón government webapps.",
5
5
  "author": {
6
6
  "name": "Desy (SDA Servicios Digitales de Aragón)",
@@ -37,6 +37,7 @@
37
37
  @import "../templates/components/skip-link/_styles.skip-link.css";
38
38
  @import "../templates/components/table-advanced/_styles.table-advanced.css";
39
39
  @import "../templates/components/tabs/_styles.tabs.css";
40
+ @import "../templates/components/toggle/_styles.toggle.css";
40
41
  @import "../templates/components/tree/_styles.tree.css";
41
42
  @import "./component.form-group.css";
42
43
  @import "./component.tippy-box.css";
@@ -24,39 +24,7 @@ export function accordion(aria) {
24
24
  var target = event.target;
25
25
 
26
26
  if(target.classList.contains('c-accordion__toggle-all')) {
27
- const getAllElementsShow = target.parentElement.parentElement.querySelectorAll('.c-accordion__show')
28
- const getAllElementsHide = target.parentElement.parentElement.querySelectorAll('.c-accordion__hide')
29
- const getAllPanels = target.parentElement.parentElement.querySelectorAll('.c-accordion__panel')
30
- const getAllTriggers = target.parentElement.parentElement.querySelectorAll('.c-accordion__trigger')
31
- if(target.textContent.includes('Mostrar todo')) {
32
- getAllElementsShow.forEach(element => {
33
- element.classList.add('hidden')
34
- })
35
- getAllElementsHide.forEach(element => {
36
- element.classList.remove('hidden')
37
- })
38
- getAllPanels.forEach(element => {
39
- element.removeAttribute('hidden')
40
- })
41
- getAllTriggers.forEach(element => {
42
- element.setAttribute('aria-expanded', 'true');
43
- })
44
- target.textContent = 'Ocultar todo'
45
- } else {
46
- getAllElementsShow.forEach(element => {
47
- element.classList.remove('hidden')
48
- })
49
- getAllElementsHide.forEach(element => {
50
- element.classList.add('hidden')
51
- })
52
- getAllPanels.forEach(element => {
53
- element.setAttribute('hidden', "")
54
- })
55
- getAllTriggers.forEach(element => {
56
- element.setAttribute('aria-expanded', 'false');
57
- })
58
- target.textContent = 'Mostrar todo'
59
- }
27
+ toggleAllAccordion(target)
60
28
  }
61
29
 
62
30
  if (target.classList.contains('c-accordion__trigger')) {
@@ -109,6 +77,10 @@ export function accordion(aria) {
109
77
 
110
78
  event.preventDefault();
111
79
  }
80
+
81
+ if(accordion.querySelector('.c-accordion__toggle-all') && !target.classList.contains('c-accordion__toggle-all')) {
82
+ checkIfAllPanelAreOpenOrClosed()
83
+ }
112
84
  });
113
85
 
114
86
  // Bind keyboard behaviors on the main accordion container
@@ -182,6 +154,55 @@ export function accordion(aria) {
182
154
  }
183
155
  }
184
156
 
157
+ function toggleAllAccordion(target, show = null) {
158
+ const getAllElementsShow = target.parentElement.parentElement.querySelectorAll('.c-accordion__show')
159
+ const getAllElementsHide = target.parentElement.parentElement.querySelectorAll('.c-accordion__hide')
160
+ const getAllPanels = target.parentElement.parentElement.querySelectorAll('.c-accordion__panel')
161
+ const getAllTriggers = target.parentElement.parentElement.querySelectorAll('.c-accordion__trigger')
162
+ if(target.textContent.includes('Mostrar todo') || show === true) {
163
+ getAllElementsShow.forEach(element => {
164
+ element.classList.add('hidden')
165
+ })
166
+ getAllElementsHide.forEach(element => {
167
+ element.classList.remove('hidden')
168
+ })
169
+ getAllPanels.forEach(element => {
170
+ element.removeAttribute('hidden')
171
+ })
172
+ getAllTriggers.forEach(element => {
173
+ element.setAttribute('aria-expanded', 'true');
174
+ })
175
+ target.textContent = 'Ocultar todo'
176
+ } else {
177
+ getAllElementsShow.forEach(element => {
178
+ element.classList.remove('hidden')
179
+ })
180
+ getAllElementsHide.forEach(element => {
181
+ element.classList.add('hidden')
182
+ })
183
+ getAllPanels.forEach(element => {
184
+ element.setAttribute('hidden', "")
185
+ })
186
+ getAllTriggers.forEach(element => {
187
+ element.setAttribute('aria-expanded', 'false');
188
+ })
189
+ target.textContent = 'Mostrar todo'
190
+ }
191
+ }
192
+
193
+ function checkIfAllPanelAreOpenOrClosed() {
194
+ const getAccordionTrigger = accordion.querySelectorAll('.c-accordion__trigger');
195
+ let arrayAccordionTrigger = [...getAccordionTrigger].map(element => element.getAttribute('aria-expanded'));
196
+
197
+ if(arrayAccordionTrigger.every(element => element === 'true')) {
198
+ accordion.querySelector('.c-accordion__toggle-all').textContent = 'Ocultar todo';
199
+ }
200
+
201
+ if(arrayAccordionTrigger.every(element => element === 'false')) {
202
+ accordion.querySelector('.c-accordion__toggle-all').textContent = 'Mostrar todo';
203
+ }
204
+ }
205
+
185
206
  window.activateItemAccordion = function (menuId, activeItemId) {
186
207
  const menu = document.getElementById(menuId);
187
208
  if (menu) {
@@ -194,7 +215,18 @@ export function accordion(aria) {
194
215
  return null;
195
216
  }
196
217
  } else {
197
- console.log('There is no menu with this id in the document.');
218
+ console.log('There is no accordion with this id in the document.');
219
+ return null;
220
+ }
221
+ };
222
+
223
+ window.activateAllAccordion = function (element, show) {
224
+ const button = document.getElementById(element);
225
+ if (button) {
226
+ toggleAllAccordion(button, show);
227
+ return [button, show]
228
+ } else {
229
+ console.log('There is no element with this id in the menu.');
198
230
  return null;
199
231
  }
200
232
  };
@@ -1,46 +1,61 @@
1
1
  export function Toggle(aria) {
2
2
 
3
- class Toggle {
4
- constructor(domNode) {
5
- this.rootEl = domNode;
6
- this.buttonEl = this.rootEl.querySelector('.c-toggle__button');
7
- this.buttonEl.addEventListener('click', this.toggle.bind(this));
8
- if(this.buttonEl.getAttribute('aria-pressed') === 'true' || this.buttonEl.getAttribute('aria-checked') === 'true') {
9
- this.buttonEl.click()
10
- }
3
+ aria.toggleInit = function (domNode) {
4
+ this.rootEl = domNode;
5
+ this.buttonEl = this.rootEl.querySelector('.c-toggle__button');
6
+ this.buttonEl.addEventListener('click', this.toggle.bind(this));
7
+ if(this.buttonEl.getAttribute('aria-pressed') === 'true' || this.buttonEl.getAttribute('aria-checked') === 'true') {
8
+ this.buttonEl.click()
11
9
  }
10
+ };
12
11
 
13
- toggle(event) {
14
- const { target } = event
15
- this.buttonEl.classList.toggle('c-toggle--is-opened')
16
- target.querySelector('.c-button--is-not-pressed').classList.toggle('hidden')
17
- target.querySelector('.c-button--is-pressed').classList.toggle('hidden')
12
+ aria.toggle = function (event) {
13
+ const { target } = event
14
+ target.classList.toggle('c-toggle--is-opened')
18
15
 
19
- this.ariaAttribute(target)
16
+ this.ariaAttribute(target)
17
+ }
18
+
19
+ aria.ariaAttribute = function (target) {
20
+ if(target.getAttribute('aria-checked')) {
21
+ const toggleIsOpened = target.classList.contains('c-toggle--is-opened') ? true : false
22
+ target.setAttribute('aria-checked', toggleIsOpened);
23
+ }
24
+
25
+ if(target.getAttribute('aria-pressed')) {
26
+ const toggleIsOpened = target.classList.contains('c-toggle--is-opened') ? true : false
27
+ target.setAttribute('aria-pressed', toggleIsOpened);
28
+ }
29
+
30
+ if(target.getAttribute('aria-expanded')) {
31
+ const toggleIsOpened = target.classList.contains('c-toggle--is-opened') ? true : false
32
+ target.setAttribute('aria-expanded', toggleIsOpened);
20
33
  }
34
+ }
21
35
 
22
- ariaAttribute(target) {
23
- if(target.getAttribute('aria-checked')) {
24
- const toggleIsOpened = target.classList.contains('c-toggle--is-opened') ? true : false
25
- this.buttonEl.setAttribute('aria-checked', toggleIsOpened);
26
- }
27
-
28
- if(target.getAttribute('aria-pressed')) {
29
- const toggleIsOpened = target.classList.contains('c-toggle--is-opened') ? true : false
30
- this.buttonEl.setAttribute('aria-pressed', toggleIsOpened);
31
- }
32
-
33
- if(target.getAttribute('aria-expanded')) {
34
- const toggleIsOpened = target.classList.contains('c-toggle--is-opened') ? true : false
35
- this.buttonEl.setAttribute('aria-expanded', toggleIsOpened);
36
- }
36
+ function handleToggle(element, toggle) {
37
+ if(toggle){
38
+ element.classList.add('c-toggle--is-opened')
39
+ } else {
40
+ element.classList.remove('c-toggle--is-opened')
37
41
  }
38
42
 
43
+ aria.ariaAttribute(element)
39
44
  }
40
45
 
46
+ window.activateItemToggle = function (element, toggle) {
47
+ const toggleElement = document.getElementById(element);
48
+ if (toggleElement) {
49
+ handleToggle(toggleElement, toggle)
50
+ return [toggleElement, toggle];
51
+ } else {
52
+ console.log('There is no toggle with this id in the document.');
53
+ return null;
54
+ }
55
+ };
56
+
41
57
  const toggles = document.querySelectorAll('[data-module="c-toggle"]');
42
58
  toggles.forEach((toggleElement) => {
43
- new Toggle(toggleElement);
59
+ aria.toggleInit(toggleElement);
44
60
  });
45
-
46
61
  }
@@ -228,6 +228,35 @@
228
228
  ]
229
229
  }
230
230
  },
231
+ {
232
+ "name": "Mostrar todo u ocultar todo con JavaScript",
233
+ "description": 'Es necesario usar el parámetro <code>"showControl": true</code>. Puedes usar con javascript la función global <code>activateAllAccordion(element, show)</code>, para mostrar u ocultar todos los items, usando el id del botón, el parámetro <code>show</code> admite <code>true</code> o <code>false</code>, si le pasamos true se mostrarán todos los items expandidos, y si le pasamos false se mostrarán cerrados. Ej: Abre la consola del navegador y escribe <code>activateAllAccordion("show-all-accordion-button-js", true)</code> para mostrar todos los items expandidos.',
234
+ "data": {
235
+ "idPrefix": "show-all-accordion-example-js",
236
+ "id": "show-all-accordion-button-js",
237
+ "headingLevel": 3,
238
+ "heading": {
239
+ "text": "Encabezado de acordeón"
240
+ },
241
+ "showControl": true,
242
+ "allowMultiple": true,
243
+ "items": [
244
+ {
245
+ "headerText": "Item de acordeón 1",
246
+ "html": '<div class="w-48 p-2"><div class="border-4 border-dashed border-neutral-light rounded-lg h-40"></div></div>'
247
+ },
248
+ {
249
+ "headerText": "Item de acordeón 2",
250
+ "html": '<div class="w-48 p-2"><div class="border-4 border-dashed border-neutral-light rounded-lg h-40"></div></div>',
251
+ "open": true
252
+ },
253
+ {
254
+ "headerText": "Item de acordeón 3",
255
+ "html": '<div class="w-48 p-2"><div class="border-4 border-dashed border-neutral-light rounded-lg h-40"></div></div>'
256
+ }
257
+ ]
258
+ }
259
+ },
231
260
  {
232
261
  "name": "Con controles personalizados para mostrar/ocultar",
233
262
  "description": 'Usa los parámetros <code>"show"</code> y <code>"hide"</code> para personalizar los controles que permiten abrir cada item. El último item de este ejemplo no muestra ningún controlador visible.',
@@ -38,7 +38,7 @@
38
38
  {% endif %}
39
39
  {% endif %}
40
40
  {% if params.showControl %}
41
- <button class="c-accordion__toggle-all ml-auto py-base text-sm text-neutral-dark underline focus:text-black focus:bg-warning-base focus:outline-none focus:shadow-outline-focus text-right" type="button">
41
+ <button id="{{ params.id }}" class="c-accordion__toggle-all ml-auto py-base text-sm text-neutral-dark underline focus:text-black focus:bg-warning-base focus:outline-none focus:shadow-outline-focus text-right" type="button">
42
42
  Mostrar todo
43
43
  </button>
44
44
  {% endif %}
@@ -32,6 +32,10 @@ params:
32
32
  type: string
33
33
  required: false
34
34
  description: Classes to add to the heading.
35
+ - name: id
36
+ type: string
37
+ required: false
38
+ description: Id to add to the button to show or hide all elements. Not required, but recommended to improve the accessibility.
35
39
  - name: showControl
36
40
  type: boolean
37
41
  required: false
@@ -118,4 +122,4 @@ params:
118
122
  - name: attributes
119
123
  type: object
120
124
  required: false
121
- description: HTML attributes (for example data attributes) to add to the accordion container.
125
+ description: HTML attributes (for example data attributes) to add to the accordion container.
@@ -264,6 +264,35 @@
264
264
  ]
265
265
  }
266
266
  },
267
+ {
268
+ "name": "Mostrar todo u ocultar todo con JavaScript",
269
+ "description": 'Es necesario usar el parámetro <code>"showControl": true</code>. Puedes usar con javascript la función global <code>activateAllAccordion(element, show)</code>, para mostrar u ocultar todos los items, usando el id del botón, el parámetro <code>show</code> admite <code>true</code> o <code>false</code>, si le pasamos true se mostrarán todos los items expandidos, y si le pasamos false se mostrarán cerrados. Ej: Abre la consola del navegador y escribe <code>activateAllAccordion("show-all-accordion-history-button-js", true)</code> para mostrar todos los items expandidos.',
270
+ "data": {
271
+ "idPrefix": "show-all-accordion-example-history-js",
272
+ "id": "show-all-accordion-history-button-js",
273
+ "headingLevel": 3,
274
+ "heading": {
275
+ "text": "Encabezado de acordeón"
276
+ },
277
+ "showControl": true,
278
+ "allowMultiple": true,
279
+ "items": [
280
+ {
281
+ "headerText": "Item de acordeón 1",
282
+ "html": '<div class="w-48 p-2"><div class="border-4 border-dashed border-neutral-light rounded-lg h-40"></div></div>'
283
+ },
284
+ {
285
+ "headerText": "Item de acordeón 2",
286
+ "html": '<div class="w-48 p-2"><div class="border-4 border-dashed border-neutral-light rounded-lg h-40"></div></div>',
287
+ "open": true
288
+ },
289
+ {
290
+ "headerText": "Item de acordeón 3",
291
+ "html": '<div class="w-48 p-2"><div class="border-4 border-dashed border-neutral-light rounded-lg h-40"></div></div>'
292
+ }
293
+ ]
294
+ }
295
+ },
267
296
  {
268
297
  "name": "Con controles personalizados para mostrar/ocultar",
269
298
  "description": 'Usa los parámetros <code>"show"</code> y <code>"hide"</code> para personalizar los controles que permiten abrir cada item. El último item de este ejemplo no muestra ningún controlador visible.',
@@ -39,7 +39,7 @@
39
39
  {% endif %}
40
40
  {% endif %}
41
41
  {% if params.showControl %}
42
- <button class="c-accordion__toggle-all ml-auto py-base text-sm text-neutral-dark underline focus:text-black focus:bg-warning-base focus:outline-none focus:shadow-outline-focus text-right" type="button">
42
+ <button id="{{ params.id }}" class="c-accordion__toggle-all ml-auto py-base text-sm text-neutral-dark underline focus:text-black focus:bg-warning-base focus:outline-none focus:shadow-outline-focus text-right" type="button">
43
43
  Mostrar todo
44
44
  </button>
45
45
  {% endif %}
@@ -28,6 +28,10 @@ params:
28
28
  type: string
29
29
  required: true
30
30
  description: If `text` is set, this is not required. HTML to use within the heading. If `html` is provided, the `text` argument will be ignored.
31
+ - name: id
32
+ type: string
33
+ required: false
34
+ description: Id to add to the item. Not required, but recommended to improve the accessibility.
31
35
  - name: classes
32
36
  type: string
33
37
  required: false
@@ -122,4 +126,4 @@ params:
122
126
  - name: attributes
123
127
  type: object
124
128
  required: false
125
- description: HTML attributes (for example data attributes) to add to the accordion container.
129
+ description: HTML attributes (for example data attributes) to add to the accordion container.
@@ -23,7 +23,7 @@
23
23
  {% set subId = "sub-" + id %}
24
24
  <li class="relative" role="none">
25
25
  {% if item.sub %}
26
- <a href="#" role="menuitem" aria-haspopup="true" aria-expanded="false" class="c-menubar__button {%- if item.classes %} {{ item.classes }}{% endif %} {%- if item.disabled %} c-menubar__button--disabled{% endif %} {%- if item.active %} c-menu-navigation__button--has-selection{% endif %}" {%- if item.title %} title="{{ item.title }}"{% endif %} {% if item.disabled %} aria-disabled="true" tabindex="-1"{% endif %} id="{{ id }}"
26
+ <a href="#" role="menuitem" aria-haspopup="true" aria-expanded="false" class="c-menubar__button {%- if item.classes %} {{ item.classes }}{% endif %} {%- if item.disabled %} c-menubar__button--disabled{% endif %} {%- if item.active %} c-menubar__button--has-selection{% endif %}" {%- if item.title %} title="{{ item.title }}"{% endif %} {% if item.disabled %} aria-disabled="true" tabindex="-1"{% endif %} id="{{ id }}"
27
27
  {%- if item.sub.html %} data-aria-controls="{{ subId }}"{% endif %}
28
28
  {%- for attribute, value in item.attributes %} {{ attribute }}="{{ value }}"{% endfor -%}>
29
29
  <span class="inline-flex self-center max-w-xs align-middle truncate">{{ item.html | safe if item.html else item.text }}</span>
@@ -32,7 +32,7 @@
32
32
  </a>
33
33
  {% endif %}
34
34
  {% if item.href and not item.sub %}
35
- <a role="menuitem" {%- if id %} id="{{ id }}"{% endif %} {%- if item.href %} href="{{ item.href }}"{% endif %} class="c-menubar__button {%- if item.classes %} {{ item.classes }}{% endif %} {%- if item.disabled %} c-menubar__button--disabled{% endif %} {%- if item.active %} c-menu-navigation__button--has-selection{% endif %}" {%- if item.title %} title="{{ item.title }}"{% endif %} {% if item.disabled %} disabled="disabled" aria-disabled="true" tabindex="-1"{% endif %} {% if item.target %} target="{{ item.target }}"{% endif %}{%- for attribute, value in item.attributes %} {{ attribute }}="{{ value }}"{% endfor -%}>
35
+ <a role="menuitem" {%- if id %} id="{{ id }}"{% endif %} {%- if item.href %} href="{{ item.href }}"{% endif %} class="c-menubar__button {%- if item.classes %} {{ item.classes }}{% endif %} {%- if item.disabled %} c-menubar__button--disabled{% endif %} {%- if item.active %} c-menubar__button--has-selection{% endif %}" {%- if item.title %} title="{{ item.title }}"{% endif %} {% if item.disabled %} disabled="disabled" aria-disabled="true" tabindex="-1"{% endif %} {% if item.target %} target="{{ item.target }}"{% endif %}{%- for attribute, value in item.attributes %} {{ attribute }}="{{ value }}"{% endfor -%}>
36
36
  {{ item.html | safe if item.html else item.text }}
37
37
  </a>
38
38
  {% endif %}
@@ -58,7 +58,7 @@ params:
58
58
  - name: firstText
59
59
  type: string
60
60
  required: false
61
- description: Text for the first button. Defaults to "Anterior".
61
+ description: Text for the first button. Defaults to "Primera".
62
62
  - name: showLast
63
63
  type: boolean
64
64
  required: false
@@ -70,7 +70,7 @@ params:
70
70
  - name: lastText
71
71
  type: string
72
72
  required: false
73
- description: Text for the last button. Defaults to "Siguiente".
73
+ description: Text for the last button. Defaults to "Última".
74
74
  - name: itemsListbox
75
75
  type: object
76
76
  required: false
@@ -87,10 +87,6 @@ params:
87
87
  type: string
88
88
  required: false
89
89
  description: If `text` is set, this is not required. HTML for table tfoot cells. If `html` is provided, the `text` argument will be ignore
90
- - name: classes
91
- type: string
92
- required: false
93
- description: Classes to add to the table tfoot cell.
94
90
  - name: colspan
95
91
  type: integer
96
92
  required: false
@@ -18,6 +18,22 @@
18
18
  }
19
19
  }
20
20
  },
21
+ {
22
+ "name": "Expandir con JavaScript",
23
+ "description": 'También puedes usar con javascript la función global <code>activateItemToggle(element, open)</code>, para expandir un item , usando su id, el parámetro <code>open</code> admite <code>true</code> o <code>false</code>, si le pasamos true se mostrará expandido, y si le pasamos false se mostrará cerrado. Ej: Abre la consola del navegador y escribe <code>activateItemToggle("toggle-expanded-js", true)</code> para mostrar el item actual expandido.',
24
+ "data": {
25
+ "classes": "c-button",
26
+ "id": "toggle-expanded-js",
27
+ "offState": {
28
+ "classes": "",
29
+ "html": 'Mostrar detalles'
30
+ },
31
+ "onState": {
32
+ "classes": "c-button--has-selection",
33
+ "html": '<span class="inline-flex"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" class="self-center mr-2" aria-hidden="true" width="1em" height="1em"><path d="M13.714 42.857A6.857 6.857 0 0 1 8.4 40.183L.857 31.646a3.429 3.429 0 0 1 .309-4.869A3.429 3.429 0 0 1 6 27.12l7.063 7.989a.72.72 0 0 0 .617.308.789.789 0 0 0 .617-.274L42.103 6.206a3.429 3.429 0 0 1 4.937 4.731L18.926 40.526a6.651 6.651 0 0 1-5.212 2.331Z" fill="currentColor"/></svg>Mostrar detalles</span>'
34
+ }
35
+ }
36
+ },
21
37
  {
22
38
  "name": "2 iconos",
23
39
  "description": 'Apariencia de botón, sin cambio en el texto del botón, sólo cambian sus iconos. Necesita un elemento externo con un <code>id</code> para referenciarlo con su <code>aria-controls</code> para mostrar/ocultar ese elemento externo.',
@@ -52,6 +68,23 @@
52
68
  }
53
69
  }
54
70
  },
71
+ {
72
+ "name": "Pressed con Javascript",
73
+ "description": 'También puedes usar con javascript la función global <code>activateItemToggle(element, toggle)</code>, para expandir un item , usando su id, el parámetro <code>toggle</code> admite <code>true</code> o <code>false</code>, si le pasamos true se mostrará expandido, y si le pasamos false se mostrará cerrado. Ej: Abre la consola del navegador y escribe <code>activateItemToggle("toggle-pressed-js", true)</code> para mostrar el item actual expandido.',
74
+ "data": {
75
+ "isExpandible": false,
76
+ "classes": "c-button",
77
+ "id": "toggle-pressed-js",
78
+ "offState": {
79
+ "classes": "",
80
+ "html": '<span class="inline-flex"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" class="self-center mr-2" aria-hidden="true" width="1em" height="1em"><path d="M6.41 10.78a.25.25 0 0 0 0 .34l2.16 2.41a1.35 1.35 0 0 0 .8.27 1.31 1.31 0 0 0 1.31-1.31V7.12a.26.26 0 0 0-.43-.18ZM.26 13.81a.76.76 0 0 0 1 0l12.5-12.5a.76.76 0 0 0 .18-.31.71.71 0 0 0 .06-.24.73.73 0 0 0-.19-.49.74.74 0 0 0-1.06 0l-2 2a.26.26 0 0 1-.19.07.25.25 0 0 1-.18-.08 1.23 1.23 0 0 0-1-.45 1.29 1.29 0 0 0-.8.27L5.74 5.21a.23.23 0 0 1-.19.09H4.42a1.75 1.75 0 0 0-1.75 1.75v1.5A1.78 1.78 0 0 0 3 9.61a.25.25 0 0 1 0 .33L.22 12.73a.75.75 0 0 0 0 1.06Z" fill="currentColor" transform="scale(3.42857)"/></svg>Reproducir sonido</span>'
81
+ },
82
+ "onState": {
83
+ "classes": "c-button--has-selection",
84
+ "html": '<span class="inline-flex"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" class="self-center mr-2" aria-hidden="true" width="1em" height="1em"><path d="M12 2.21a.75.75 0 0 0-1.06 0 .75.75 0 0 0 0 1.06 5.26 5.26 0 0 1 0 7.46.75.75 0 0 0 0 1.06.75.75 0 0 0 1.06 0 6.74 6.74 0 0 0 0-9.58Z" fill="currentColor" transform="scale(3.42857)"/><path d="M10.34 4.89a.75.75 0 0 0-1.23.85 2.23 2.23 0 0 1 0 2.52.74.74 0 0 0 .19 1 .75.75 0 0 0 1-.19 3.7 3.7 0 0 0 0-4.22ZM6.69 1a1.35 1.35 0 0 0-.8.27L3.07 4.42a.27.27 0 0 1-.19.08H1.75A1.76 1.76 0 0 0 0 6.25v1.5A1.76 1.76 0 0 0 1.75 9.5h1.13a.27.27 0 0 1 .19.08l2.82 3.15a1.35 1.35 0 0 0 .8.27A1.31 1.31 0 0 0 8 11.69V2.31A1.31 1.31 0 0 0 6.69 1Z" fill="currentColor" transform="scale(3.42857)"/></svg>Reproducir sonido</span>'
85
+ }
86
+ }
87
+ },
55
88
  {
56
89
  "name": "Pressed",
57
90
  "description": 'Usa <code>"pressed": true</code> para activarlo inicialmente.',
@@ -107,6 +140,26 @@
107
140
  }
108
141
  }
109
142
  },
143
+ {
144
+ "name": "isSwitch con JavaScript",
145
+ "description": 'También puedes usar con javascript la función global <code>activateItemToggle(element, toggle)</code>, para modificar el estado del Switch, usando su id, el parámetro <code>toggle</code> admite <code>true</code> o <code>false</code>, si le pasamos true se mostrará activado, y si le pasamos false se mostrará desactivado. Ej: Abre la consola del navegador y escribe <code>activateItemToggle("toggle-switch-js", true)</code> para mostrar el switch activado.',
146
+ "data": {
147
+ "classes": "",
148
+ "id": "toggle-switch-js",
149
+ "isSwitch": true,
150
+ "offState": {
151
+ "classes": "",
152
+ "html": '<span class="flex align-center justify-between gap-xs"><span class="text-sm" aria-hidden="true">Off</span><span class="bg-neutral-base relative inline-flex flex-shrink-0 h-5 w-9 border-2 border-neutral-base rounded-full cursor-pointer focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75"><span class="sr-only">Off</span><span aria-hidden="true" class="translate-x-0 pointer-events-none inline-block h-4 w-4 rounded-full bg-white shadow-lg transform ring-0 transition ease-in-out duration-200" /></span></span><span class="text-sm" aria-hidden="true">On</span></span>'
153
+ },
154
+ "onState": {
155
+ "classes": "",
156
+ "html": '<span class="flex align-center justify-between gap-xs"><span class="text-sm" aria-hidden="true">Off</span><span class="bg-primary-base relative inline-flex flex-shrink-0 h-5 w-9 border-2 border-primary-base rounded-full cursor-pointer focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75"><span class="sr-only">On</span><span aria-hidden="true" class="translate-x-4 pointer-events-none inline-block h-4 w-4 rounded-full bg-white shadow-lg transform ring-0 transition ease-in-out duration-200" /></span></span><span class="text-sm" aria-hidden="true">On</span></span>'
157
+ },
158
+ "attributes": {
159
+ "aria-labelledby": "id-text"
160
+ }
161
+ }
162
+ },
110
163
  {
111
164
  "name": "isSwitch peque",
112
165
  "data": {
@@ -0,0 +1,31 @@
1
+ /* ==========================================================================
2
+ _styles.toggle.css
3
+ ========================================================================== */
4
+
5
+ @layer components {
6
+ .c-toggle {
7
+ [aria-expanded="true"],
8
+ [aria-pressed="true"],
9
+ [aria-checked="true"] {
10
+ .c-button--is-not-pressed {
11
+ @apply hidden;
12
+ }
13
+
14
+ .c-button--is-pressed {
15
+ @apply block;
16
+ }
17
+ }
18
+
19
+ [aria-expanded="false"],
20
+ [aria-pressed="false"],
21
+ [aria-checked="false"] {
22
+ .c-button--is-not-pressed {
23
+ @apply block;
24
+ }
25
+
26
+ .c-button--is-pressed {
27
+ @apply hidden;
28
+ }
29
+ }
30
+ }
31
+ }
@@ -17,6 +17,7 @@
17
17
  {% endif %}
18
18
  type="button"
19
19
  class="c-toggle__button {{ params.classes if params.classes else '' }}"
20
+ id="{{ params.id }}"
20
21
  {%- for attribute, value in params.attributes %} {{attribute}}="{{value}}"{% endfor %}
21
22
  >
22
23
  <span class="c-button--is-not-pressed pointer-events-none">{{ params.offState.html | safe if params.offState.html else params.offState.text }}</span>
@@ -23,6 +23,10 @@ params:
23
23
  type: string
24
24
  required: true
25
25
  description: If `text` is set, this is not required. HTML to use within the state. If `html` is provided, the `text` argument will be ignored.
26
+ - name: id
27
+ type: string
28
+ required: false
29
+ description: Id to add to the toggle element. Not required, but recommended to improve the accessibility.
26
30
  - name: classes
27
31
  type: string
28
32
  required: false