@italia/button 0.1.0-alpha.1 → 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.
@@ -1,6 +1,6 @@
1
1
  import { directive, Directive } from 'lit/directive.js';
2
2
  import { LitElement, css, html } from 'lit';
3
- import { query, property, customElement } from 'lit/decorators.js';
3
+ import { state, query, property, customElement } from 'lit/decorators.js';
4
4
  import { ifDefined } from 'lit/directives/if-defined.js';
5
5
 
6
6
  /******************************************************************************
@@ -36,45 +36,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
36
36
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
37
37
  };
38
38
 
39
- /**
40
- * @license
41
- *
42
- * Copyright IBM Corp. 2020, 2022
43
- *
44
- * This source code is licensed under the Apache-2.0 license found in the
45
- * LICENSE file in the root directory of this source tree.
46
- */
47
- /**
48
- * Form validation status.
49
- */
50
- var VALIDATION_STATUS;
51
- (function (VALIDATION_STATUS) {
52
- /**
53
- * One indicating no validation error.
54
- */
55
- VALIDATION_STATUS["NO_ERROR"] = "";
56
- /**
57
- * One indicating that the value is invalid (generic).
58
- */
59
- VALIDATION_STATUS["INVALID"] = "invalid";
60
- /**
61
- * One indicating missing required value.
62
- */
63
- VALIDATION_STATUS["ERROR_REQUIRED"] = "required";
64
- /**
65
- * One indicating that the value does not match the pattern.
66
- */
67
- VALIDATION_STATUS["PATTERN"] = "pattern";
68
- /**
69
- * One indicating that the value is shorter than the minimum length.
70
- */
71
- VALIDATION_STATUS["MINLENGTH"] = "minlength";
72
- /**
73
- * One indicating that the value is less than the maximum length.
74
- */
75
- VALIDATION_STATUS["MAXLENGTH"] = "maxlength";
76
- })(VALIDATION_STATUS || (VALIDATION_STATUS = {}));
77
-
78
39
  class SetAttributesDirective extends Directive {
79
40
  update(part, [attributes]) {
80
41
  const el = part.element;
@@ -97,19 +58,26 @@ class SetAttributesDirective extends Directive {
97
58
  */
98
59
  const setAttributes = directive(SetAttributesDirective);
99
60
 
61
+ function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
62
+
100
63
  const connectedElements = new Set();
101
64
  if (window && !window.translations) {
102
65
  window.translations = new Map();
103
66
  }
104
67
  const { translations } = window;
68
+ let fallback;
69
+ // TODO: We need some way for users to be able to set these on the server.
70
+ let documentDirection = 'ltr';
71
+ // Fallback for server.
72
+ let documentLanguage = 'en';
105
73
  const isClient = typeof MutationObserver !== 'undefined' &&
106
74
  typeof document !== 'undefined' &&
107
75
  typeof document.documentElement !== 'undefined';
108
76
  /** Updates all localized elements that are currently connected */
109
77
  function update() {
110
78
  if (isClient) {
111
- document.documentElement.dir || 'ltr';
112
- document.documentElement.lang || navigator.language;
79
+ documentDirection = document.documentElement.dir || 'ltr';
80
+ documentLanguage = document.documentElement.lang || navigator.language;
113
81
  }
114
82
  [...connectedElements.keys()].forEach((el) => {
115
83
  const litEl = el;
@@ -120,8 +88,8 @@ function update() {
120
88
  }
121
89
  if (isClient) {
122
90
  const documentElementObserver = new MutationObserver(update);
123
- document.documentElement.dir || 'ltr';
124
- document.documentElement.lang || navigator.language;
91
+ documentDirection = document.documentElement.dir || 'ltr';
92
+ documentLanguage = document.documentElement.lang || navigator.language;
125
93
  // Watch for changes on <html lang>
126
94
  documentElementObserver.observe(document.documentElement, {
127
95
  attributes: true,
@@ -139,10 +107,240 @@ function registerTranslation(...translation) {
139
107
  else {
140
108
  translations.set(code, t);
141
109
  }
110
+ // The first translation that's registered is the fallback
111
+ if (!fallback) {
112
+ fallback = t;
113
+ }
142
114
  });
143
115
  update();
144
116
  }
145
- window.registerTranslation = registerTranslation;
117
+ if (typeof window !== 'undefined') {
118
+ window.registerTranslation = registerTranslation;
119
+ }
120
+ /**
121
+ * Localize Reactive Controller for components built with Lit
122
+ *
123
+ * To use this controller, import the class and instantiate it in a custom element constructor:
124
+ *
125
+ * private localize = new LocalizeController(this);
126
+ *
127
+ * This will add the element to the set and make it respond to changes to <html dir|lang> automatically. To make it
128
+ * respond to changes to its own dir|lang properties, make it a property:
129
+ *
130
+ * @property() dir: string;
131
+ * @property() lang: string;
132
+ *
133
+ * To use a translation method, call it like this:
134
+ *
135
+ * ${this.localize.term('term_key_here')}
136
+ * ${this.localize.date('2021-12-03')}
137
+ * ${this.localize.number(1000000)}
138
+ */
139
+ class LocalizeController {
140
+ constructor(host) {
141
+ this.host = host;
142
+ this.host.addController(this);
143
+ }
144
+ hostConnected() {
145
+ connectedElements.add(this.host);
146
+ }
147
+ hostDisconnected() {
148
+ connectedElements.delete(this.host);
149
+ }
150
+ /**
151
+ * Gets the host element's directionality as determined by the `dir` attribute. The return value is transformed to
152
+ * lowercase.
153
+ */
154
+ dir() {
155
+ return `${this.host.dir || documentDirection}`.toLowerCase();
156
+ }
157
+ /**
158
+ * Gets the host element's language as determined by the `lang` attribute. The return value is transformed to
159
+ * lowercase.
160
+ */
161
+ lang() {
162
+ return `${this.host.lang || documentLanguage}`.toLowerCase();
163
+ }
164
+ // eslint-disable-next-line class-methods-use-this
165
+ getTranslationData(lang) {
166
+ // Convert "en_US" to "en-US". Note that both underscores and dashes are allowed per spec, but underscores result in
167
+ // a RangeError by the call to `new Intl.Locale()`. See: https://unicode.org/reports/tr35/#unicode-locale-identifier
168
+ const locale = new Intl.Locale(lang.replace(/_/g, '-'));
169
+ const language = locale?.language.toLowerCase();
170
+ const region = locale?.region?.toLowerCase() ?? '';
171
+ const primary = translations.get(`${language}-${region}`);
172
+ const secondary = translations.get(language);
173
+ return { locale, language, region, primary, secondary };
174
+ }
175
+ /** Determines if the specified term exists, optionally checking the fallback translation. */
176
+ exists(key, options) {
177
+ const { primary, secondary } = this.getTranslationData(options.lang ?? this.lang());
178
+ const mergedOptions = {
179
+ includeFallback: false,
180
+ ...options,
181
+ };
182
+ if ((primary && primary[key]) ||
183
+ (secondary && secondary[key]) ||
184
+ (mergedOptions.includeFallback && fallback && fallback[key])) {
185
+ return true;
186
+ }
187
+ return false;
188
+ }
189
+ /** Outputs a translated term. */
190
+ term(key, ...args) {
191
+ const { primary, secondary } = this.getTranslationData(this.lang());
192
+ let term;
193
+ // Look for a matching term using regionCode, code, then the fallback
194
+ if (primary && primary[key]) {
195
+ term = primary[key];
196
+ }
197
+ else if (secondary && secondary[key]) {
198
+ term = secondary[key];
199
+ }
200
+ else if (fallback && fallback[key]) {
201
+ term = fallback[key];
202
+ }
203
+ else {
204
+ // eslint-disable-next-line no-console
205
+ console.error(`No translation found for: ${String(key)}`);
206
+ return String(key);
207
+ }
208
+ if (typeof term === 'function') {
209
+ return term(...args);
210
+ }
211
+ return term;
212
+ }
213
+ /** Outputs a localized date in the specified format. */
214
+ date(dateToFormat, options) {
215
+ const date = new Date(dateToFormat);
216
+ return new Intl.DateTimeFormat(this.lang(), options).format(date);
217
+ }
218
+ /** Outputs a localized number in the specified format. */
219
+ number(numberToFormat, options) {
220
+ const num = Number(numberToFormat);
221
+ return Number.isNaN(num) ? '' : new Intl.NumberFormat(this.lang(), options).format(num);
222
+ }
223
+ /** Outputs a localized time in relative format. */
224
+ relativeTime(value, unit, options) {
225
+ return new Intl.RelativeTimeFormat(this.lang(), options).format(value, unit);
226
+ }
227
+ }
228
+
229
+ /**
230
+ * @param Base The base class.
231
+ * @returns A mix-in implementing `localizations` method.
232
+ *
233
+ *@example
234
+ * <!-- Terms -->
235
+ ${this.$localize.term('hello')}
236
+ or
237
+ ${this.$t('hello')}
238
+
239
+ <!-- Dates -->
240
+ ${this.$localize.date('2021-09-15 14:00:00 ET', { month: 'long', day: 'numeric', year: 'numeric' })}
241
+ or
242
+ ${this.$d('2021-09-15 14:00:00 ET', { month: 'long', day: 'numeric', year: 'numeric' })}
243
+
244
+ <!-- Numbers/currency -->
245
+ ${this.$localize.number(1000, { style: 'currency', currency: 'USD'})}
246
+ or
247
+ ${this.$n(1000,{ style: 'currency', currency: 'USD'})}
248
+
249
+ <!-- Determining language -->
250
+ ${this.$localize.lang()}
251
+
252
+ <!-- Determining directionality, e.g. 'ltr' or 'rtl' -->
253
+ ${this.$localize.dir()}
254
+
255
+
256
+ *** HOW TO DEFINE TRANSLATIONS: ***
257
+ // Simple terms
258
+ upload: 'Upload',
259
+
260
+ // Terms with placeholders
261
+ greetUser: (name: string) => `Hello, ${name}!`,
262
+
263
+ // Plurals
264
+ numFilesSelected: (count: number) => {
265
+ if (count === 0) return 'No files selected';
266
+ if (count === 1) return '1 file selected';
267
+ return `${count} files selected`;
268
+ }
269
+ */
270
+ const LocalizeMixin = (Base) => class extends Base {
271
+ constructor() {
272
+ super(...arguments);
273
+ this.localize = new LocalizeController(this);
274
+ }
275
+ // Provide default values to avoid definite assignment errors and avoid decorators
276
+ // commentati perchè danno problemi su React.js. Sono attributi nativi, e assegnare un valore di default a react da fastidio
277
+ // dir: string = '';
278
+ // lang: string = '';
279
+ /**
280
+ * Restituisce tutta l'utility di traduzione
281
+ *
282
+
283
+ *
284
+ * @returns tutta l'utility di traduzione
285
+ *
286
+ * @example
287
+ * this.$localize.lang() -> ritorna la lingua corrente
288
+ * this.$localize.dir() -> ritorna la direzione della lingua corrente
289
+ */
290
+ get $localize() {
291
+ return this.localize;
292
+ }
293
+ /**
294
+ * Restituisce una stringa localizzata a partire da una chiave di termine.
295
+ *
296
+ * Utilizza il `LocalizeController` per accedere al dizionario corrente e
297
+ * tradurre la chiave fornita secondo la lingua attiva.
298
+ *
299
+ * @param t - La chiave del termine da localizzare (es. 'hello', 'submit', ecc.).
300
+ * @returns La stringa tradotta in base alla lingua attiva. Se la chiave non è trovata, restituisce la chiave stessa.
301
+ *
302
+ * @example
303
+ * this.$t('hello'); // → "Ciao" (in locale it-IT)
304
+ */
305
+ $t(t) {
306
+ // format term
307
+ return this.localize.term(t);
308
+ }
309
+ /**
310
+ * Formatta una data in base alla localizzazione attiva.
311
+ *
312
+ * Utilizza il `LocalizeController` per restituire una stringa localizzata
313
+ * secondo le opzioni fornite (es. mese esteso, anno, ecc.).
314
+ *
315
+ * @param n - La data da formattare come stringa compatibile (es. ISO o con timezone, es. '2021-09-15 14:00:00 ET').
316
+ * @param p - Le opzioni di formattazione per `Intl.DateTimeFormat` (es. { year: 'numeric', month: 'long', day: 'numeric' }).
317
+ * @returns Una stringa rappresentante la data formattata secondo la localizzazione attiva.
318
+ *
319
+ * @example
320
+ * this.$d('2021-09-15 14:00:00 ET', { year: 'numeric', month: 'long', day: 'numeric' });
321
+ * // → "15 settembre 2021" (in locale it-IT)
322
+ */
323
+ $d(d, p) {
324
+ // format date
325
+ return this.localize.date(d, p);
326
+ }
327
+ /**
328
+ * Formatta un numero secondo le impostazioni locali dell'utente corrente.
329
+ *
330
+ * Utilizza il `LocalizeController` per applicare formattazione numerica,
331
+ * incluse opzioni come separatori, decimali, valute, ecc.
332
+ *
333
+ * @param d - Il numero da formattare.
334
+ * @param p - Le opzioni di formattazione (es. { style: 'currency', currency: 'EUR' }).
335
+ * @returns Una stringa rappresentante il numero formattato secondo la localizzazione attiva.
336
+ *
337
+ * @example
338
+ * this.$n(1234.56, { style: 'currency', currency: 'USD' }); // → "$1,234.56" (in locale en-US)
339
+ */
340
+ $n(d, p) {
341
+ return this.localize.number(d, p);
342
+ }
343
+ };
146
344
 
147
345
  /* eslint-disable no-console */
148
346
  class Logger {
@@ -170,9 +368,21 @@ class Logger {
170
368
  class BaseComponent extends LitElement {
171
369
  constructor() {
172
370
  super();
173
- this._ariaAttributes = {}; // tutti gli attributi aria-* passati al Web component
371
+ this.composeClass = clsx;
174
372
  this.logger = new Logger(this.tagName.toLowerCase());
175
373
  }
374
+ get _ariaAttributes() {
375
+ const attributes = {};
376
+ for (const attr of this.getAttributeNames()) {
377
+ if (attr === 'it-role') {
378
+ attributes.role = this.getAttribute(attr);
379
+ }
380
+ else if (attr.startsWith('it-aria-')) {
381
+ attributes[attr.replace(/^it-/, '')] = this.getAttribute(attr);
382
+ }
383
+ }
384
+ return attributes;
385
+ }
176
386
  // eslint-disable-next-line class-methods-use-this
177
387
  generateId(prefix) {
178
388
  return `${prefix}-${Math.random().toString(36).slice(2)}`;
@@ -182,30 +392,708 @@ class BaseComponent extends LitElement {
182
392
  // new TrackFocus(element); // per il momento è stato disattivato perchè ci sono le pseudo classi ::focus-visible per fare quello che fa TrackFocus. Si possono aggiungere regole css in bsi-italia 3 dato che stiamo facendo una breaking release di bsi.
183
393
  }
184
394
  // eslint-disable-next-line class-methods-use-this
185
- composeClass(...classes) {
186
- let composedClass = '';
187
- classes
188
- .filter((c) => c.length > 0)
189
- .forEach((newClass) => {
190
- composedClass += ` ${newClass}`;
191
- });
192
- return composedClass.trim();
193
- }
194
- getAriaAttributes() {
195
- for (const attr of this.getAttributeNames()) {
196
- if (attr.startsWith('aria-')) {
197
- this._ariaAttributes[attr] = this.getAttribute(attr);
198
- }
395
+ getActiveElement() {
396
+ let active = document.activeElement;
397
+ while (active && active.shadowRoot && active.shadowRoot.activeElement) {
398
+ active = active.shadowRoot.activeElement;
199
399
  }
400
+ return active;
401
+ }
402
+ get focusElement() {
403
+ return this;
404
+ }
405
+ // eslint-disable-next-line class-methods-use-this
406
+ get prefersReducedMotion() {
407
+ return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
200
408
  }
201
409
  connectedCallback() {
202
- super.connectedCallback?.();
203
- this.getAriaAttributes();
410
+ super.connectedCallback();
204
411
  // generate internal _id
205
412
  const prefix = this.id?.length > 0 ? this.id : this.tagName.toLowerCase();
206
413
  this._id = this.generateId(prefix);
207
414
  }
208
415
  }
416
+ const BaseLocalizedComponent = LocalizeMixin(BaseComponent);
417
+
418
+ //
419
+ // We store a WeakMap of forms + controls so we can keep references to all FormControl within a given form. As
420
+ // elements connect and disconnect to/from the DOM, their containing form is used as the key and the form control is
421
+ // added and removed from the form's set, respectively.
422
+ //
423
+ const formCollections = new WeakMap();
424
+ //
425
+ // We store a WeakMap of reportValidity() overloads so we can override it when form controls connect to the DOM and
426
+ // restore the original behavior when they disconnect.
427
+ //
428
+ const reportValidityOverloads = new WeakMap();
429
+ const checkValidityOverloads = new WeakMap();
430
+ //
431
+ // We store a Set of controls that users have interacted with. This allows us to determine the interaction state
432
+ // without littering the DOM with additional data attributes.
433
+ //
434
+ const userInteractedControls = new WeakSet();
435
+ //
436
+ // We store a WeakMap of interactions for each form control so we can track when all conditions are met for validation.
437
+ //
438
+ const interactions = new WeakMap();
439
+ /** A reactive controller to allow form controls to participate in form submission, validation, etc. */
440
+ class FormControlController {
441
+ constructor(host, options) {
442
+ this.submittedOnce = false;
443
+ this.handleFormData = (event) => {
444
+ // console.log('handleFormData');
445
+ const disabled = this.options.disabled(this.host);
446
+ const name = this.options.name(this.host);
447
+ const value = this.options.value(this.host);
448
+ const tagName = this.host.tagName.toLowerCase();
449
+ // For buttons, we only submit the value if they were the submitter. This is currently done in doAction() by
450
+ // injecting the name/value on a temporary button, so we can just skip them here.
451
+ const isButton = tagName === 'it-button';
452
+ if (this.host.isConnected &&
453
+ !disabled &&
454
+ !isButton &&
455
+ typeof name === 'string' &&
456
+ name.length > 0 &&
457
+ typeof value !== 'undefined') {
458
+ switch (tagName) {
459
+ case 'it-radio':
460
+ if (this.host.checked) {
461
+ event.formData.append(name, value);
462
+ }
463
+ break;
464
+ case 'it-checkbox':
465
+ case 'it-toggle':
466
+ if (this.host.checked) {
467
+ if (event.formData.getAll(name).indexOf(value) < 0) {
468
+ // handle group checkbox
469
+ event.formData.append(name, value);
470
+ }
471
+ }
472
+ break;
473
+ case 'it-checkbox-group':
474
+ case 'it-toggle-group':
475
+ // non settare valori in formData, perchè ogni singola checkbox setta il suo valore
476
+ break;
477
+ case 'it-upload':
478
+ // value is File[] — append each File object directly (not as string)
479
+ if (Array.isArray(value)) {
480
+ value.forEach((file) => {
481
+ event.formData.append(name, file);
482
+ });
483
+ }
484
+ break;
485
+ default:
486
+ if (Array.isArray(value)) {
487
+ value.forEach((val) => {
488
+ event.formData.append(name, val.toString());
489
+ });
490
+ }
491
+ else {
492
+ event.formData.append(name, value.toString());
493
+ }
494
+ }
495
+ }
496
+ };
497
+ this.handleFormSubmit = (event) => {
498
+ const disabled = this.options.disabled(this.host);
499
+ const reportValidity = this.options.reportValidity;
500
+ // Update the interacted state for all controls when the form is submitted
501
+ if (this.form && !this.form.noValidate) {
502
+ formCollections.get(this.form)?.forEach((control) => {
503
+ this.setUserInteracted(control, true);
504
+ });
505
+ }
506
+ const resReportValidity = reportValidity(this.host);
507
+ if (this.form && !this.form.noValidate && !disabled && !resReportValidity) {
508
+ event.preventDefault();
509
+ // event.stopImmediatePropagation(); // se lo attiviamo, valida un campo alla volta
510
+ // Scroll al primo controllo non valido
511
+ const formControls = formCollections.get(this.form);
512
+ if (formControls) {
513
+ for (const control of formControls) {
514
+ if (!control.validity?.valid) {
515
+ // Scroll smooth verso il controllo non valido
516
+ control.scrollIntoView({
517
+ behavior: 'smooth',
518
+ block: 'center',
519
+ });
520
+ break;
521
+ }
522
+ }
523
+ }
524
+ }
525
+ this.submittedOnce = true;
526
+ };
527
+ this.handleFormReset = () => {
528
+ this.options.setValue(this.host, '');
529
+ this.submittedOnce = false;
530
+ this.setUserInteracted(this.host, false);
531
+ interactions.set(this.host, []);
532
+ };
533
+ this.handleInteraction = (event) => {
534
+ const emittedEvents = interactions.get(this.host);
535
+ if (!emittedEvents.includes(event.type)) {
536
+ emittedEvents.push(event.type);
537
+ }
538
+ // Mark it as user-interacted as soon as all associated events have been emitted
539
+ if (emittedEvents.length === this.options.assumeInteractionOn.length) {
540
+ this.setUserInteracted(this.host, true);
541
+ }
542
+ };
543
+ this.checkFormValidity = () => {
544
+ // console.log('checkFormValidity');
545
+ //
546
+ // This is very similar to the `reportFormValidity` function, but it does not trigger native constraint validation
547
+ // Allow the user to simply check if the form is valid and handling validity in their own way.
548
+ //
549
+ // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger
550
+ // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't
551
+ // be necessary once we can use ElementInternals.
552
+ //
553
+ // Note that we're also honoring the form's novalidate attribute.
554
+ //
555
+ if (this.form && !this.form.noValidate) {
556
+ // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom
557
+ // elements that support the constraint validation API.
558
+ const elements = this.form.querySelectorAll('*');
559
+ for (const element of elements) {
560
+ if (typeof element.checkValidity === 'function') {
561
+ if (!element.checkValidity()) {
562
+ return false;
563
+ }
564
+ }
565
+ }
566
+ }
567
+ return true;
568
+ };
569
+ this.reportFormValidity = () => {
570
+ // console.log('reportFormValidity');
571
+ //
572
+ // FormControl work hard to act like regular form controls. They support the Constraint Validation API
573
+ // and its associated methods such as setCustomValidity() and reportValidity(). However, the HTMLFormElement also
574
+ // has a reportValidity() method that will trigger validation on all child controls. Since we're not yet using
575
+ // ElementInternals, we need to overload this method so it looks for any element with the reportValidity() method.
576
+ //
577
+ // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger
578
+ // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't
579
+ // be necessary once we can use ElementInternals.
580
+ //
581
+ // Note that we're also honoring the form's novalidate attribute.
582
+ //
583
+ if (this.form && !this.form.noValidate) {
584
+ // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom
585
+ // elements that support the constraint validation API.
586
+ const elements = this.form.querySelectorAll('*');
587
+ for (const element of elements) {
588
+ if (typeof element.reportValidity === 'function') {
589
+ if (!element.reportValidity()) {
590
+ return false;
591
+ }
592
+ }
593
+ }
594
+ }
595
+ return true;
596
+ };
597
+ (this.host = host).addController(this);
598
+ this.options = {
599
+ form: (input) => {
600
+ // If there's a form attribute, use it to find the target form by id
601
+ // Controls may not always reflect the 'form' property. For example, `<it-button>` doesn't reflect.
602
+ const formId = input.form;
603
+ if (formId) {
604
+ const root = input.getRootNode();
605
+ const form = root.querySelector(`#${formId}`);
606
+ if (form) {
607
+ return form;
608
+ }
609
+ }
610
+ return input.closest('form');
611
+ },
612
+ name: (input) => input.name,
613
+ value: (input) => input.value,
614
+ disabled: (input) => input.disabled ?? false,
615
+ reportValidity: (input) => typeof input.reportValidity === 'function' ? input.reportValidity() : true,
616
+ checkValidity: (input) => (typeof input.checkValidity === 'function' ? input.checkValidity() : true),
617
+ setValue: (input, value) => {
618
+ // eslint-disable-next-line no-param-reassign
619
+ input.value = value;
620
+ },
621
+ assumeInteractionOn: ['it-input'],
622
+ ...options,
623
+ };
624
+ }
625
+ hostConnected() {
626
+ const form = this.options.form(this.host);
627
+ if (form) {
628
+ this.attachForm(form);
629
+ }
630
+ // Listen for interactions
631
+ interactions.set(this.host, []);
632
+ this.options.assumeInteractionOn.forEach((event) => {
633
+ this.host.addEventListener(event, this.handleInteraction);
634
+ });
635
+ }
636
+ hostDisconnected() {
637
+ this.detachForm();
638
+ // Clean up interactions
639
+ interactions.delete(this.host);
640
+ this.options.assumeInteractionOn.forEach((event) => {
641
+ this.host.removeEventListener(event, this.handleInteraction);
642
+ });
643
+ }
644
+ hostUpdated() {
645
+ const form = this.options.form(this.host);
646
+ // Detach if the form no longer exists
647
+ if (!form) {
648
+ this.detachForm();
649
+ }
650
+ // If the form has changed, reattach it
651
+ if (form && this.form !== form) {
652
+ this.detachForm();
653
+ this.attachForm(form);
654
+ }
655
+ if (this.host.hasUpdated) {
656
+ this.setValidity(this.host.validity.valid);
657
+ }
658
+ }
659
+ attachForm(form) {
660
+ if (form) {
661
+ this.form = form;
662
+ // Add this element to the form's collection
663
+ if (formCollections.has(this.form)) {
664
+ formCollections.get(this.form).add(this.host);
665
+ }
666
+ else {
667
+ formCollections.set(this.form, new Set([this.host]));
668
+ }
669
+ this.form.addEventListener('formdata', this.handleFormData);
670
+ this.form.addEventListener('submit', this.handleFormSubmit);
671
+ this.form.addEventListener('reset', this.handleFormReset);
672
+ // Overload the form's reportValidity() method so it looks at FormControl
673
+ if (!reportValidityOverloads.has(this.form)) {
674
+ reportValidityOverloads.set(this.form, this.form.reportValidity);
675
+ this.form.reportValidity = () => this.reportFormValidity();
676
+ }
677
+ // Overload the form's checkValidity() method so it looks at FormControl
678
+ if (!checkValidityOverloads.has(this.form)) {
679
+ checkValidityOverloads.set(this.form, this.form.checkValidity);
680
+ this.form.checkValidity = () => this.checkFormValidity();
681
+ }
682
+ }
683
+ else {
684
+ this.form = undefined;
685
+ }
686
+ }
687
+ detachForm() {
688
+ if (!this.form)
689
+ return;
690
+ const formCollection = formCollections.get(this.form);
691
+ if (!formCollection) {
692
+ return;
693
+ }
694
+ this.submittedOnce = false;
695
+ // Remove this host from the form's collection
696
+ formCollection.delete(this.host);
697
+ // Check to make sure there's no other form controls in the collection. If we do this
698
+ // without checking if any other controls are still in the collection, then we will wipe out the
699
+ // validity checks for all other elements.
700
+ // see: https://github.com/shoelace-style/shoelace/issues/1703
701
+ if (formCollection.size <= 0) {
702
+ this.form.removeEventListener('formdata', this.handleFormData);
703
+ this.form.removeEventListener('submit', this.handleFormSubmit);
704
+ this.form.removeEventListener('reset', this.handleFormReset);
705
+ // Remove the overload and restore the original method
706
+ if (reportValidityOverloads.has(this.form)) {
707
+ this.form.reportValidity = reportValidityOverloads.get(this.form);
708
+ reportValidityOverloads.delete(this.form);
709
+ }
710
+ if (checkValidityOverloads.has(this.form)) {
711
+ this.form.checkValidity = checkValidityOverloads.get(this.form);
712
+ checkValidityOverloads.delete(this.form);
713
+ }
714
+ // So it looks weird here to not always set the form to undefined. But I _think_ if we unattach this.form here,
715
+ // we end up in this fun spot where future validity checks don't have a reference to the form validity handler.
716
+ // First form element in sets the validity handler. So we can't clean up `this.form` until there are no other form elements in the form.
717
+ this.form = undefined;
718
+ }
719
+ }
720
+ // eslint-disable-next-line class-methods-use-this
721
+ setUserInteracted(el, hasInteracted) {
722
+ if (hasInteracted) {
723
+ userInteractedControls.add(el);
724
+ }
725
+ else {
726
+ userInteractedControls.delete(el);
727
+ }
728
+ el.requestUpdate();
729
+ }
730
+ doAction(type, submitter) {
731
+ // console.log('doaction', type);
732
+ if (this.form) {
733
+ const button = document.createElement('button');
734
+ button.type = type;
735
+ button.style.position = 'absolute';
736
+ button.style.width = '0';
737
+ button.style.height = '0';
738
+ button.style.clipPath = 'inset(50%)';
739
+ button.style.overflow = 'hidden';
740
+ button.style.whiteSpace = 'nowrap';
741
+ // Pass name, value, and form attributes through to the temporary button
742
+ if (submitter) {
743
+ button.name = submitter.name;
744
+ button.value = submitter.value;
745
+ ['formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget'].forEach((attr) => {
746
+ if (submitter.hasAttribute(attr)) {
747
+ button.setAttribute(attr, submitter.getAttribute(attr));
748
+ }
749
+ });
750
+ }
751
+ this.form.append(button);
752
+ button.click();
753
+ button.remove();
754
+ }
755
+ }
756
+ /** Returns the associated `<form>` element, if one exists. */
757
+ getForm() {
758
+ return this.form ?? null;
759
+ }
760
+ /** Resets the form, restoring all the control to their default value */
761
+ reset(submitter) {
762
+ this.doAction('reset', submitter);
763
+ }
764
+ /** Submits the form, triggering validation and form data injection. */
765
+ submit(submitter) {
766
+ // Calling form.submit() bypasses the submit event and constraint validation. To prevent this, we can inject a
767
+ // native submit button into the form, "click" it, then remove it to simulate a standard form submission.
768
+ this.doAction('submit', submitter);
769
+ }
770
+ /**
771
+ * Synchronously sets the form control's validity. Call this when you know the future validity but need to update
772
+ * the host element immediately, i.e. before Lit updates the component in the next update.
773
+ */
774
+ setValidity(isValid) {
775
+ const host = this.host;
776
+ const hasInteracted = Boolean(userInteractedControls.has(host));
777
+ const required = Boolean(host.required);
778
+ //
779
+ // We're mapping the following "states" to data attributes. In the future, we can use ElementInternals.states to
780
+ // create a similar mapping, but instead of [data-invalid] it will look like :--invalid.
781
+ //
782
+ // See this RFC for more details: https://github.com/shoelace-style/shoelace/issues/1011
783
+ //
784
+ host.toggleAttribute('data-required', required);
785
+ host.toggleAttribute('data-optional', !required);
786
+ host.toggleAttribute('data-invalid', !isValid);
787
+ host.toggleAttribute('data-valid', isValid);
788
+ host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);
789
+ host.toggleAttribute('data-user-valid', isValid && hasInteracted);
790
+ }
791
+ userInteracted() {
792
+ const hasInteracted = Boolean(userInteractedControls.has(this.host));
793
+ return hasInteracted;
794
+ }
795
+ /**
796
+ * Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything
797
+ * that affects constraint validation changes so the component receives the correct validity states.
798
+ */
799
+ updateValidity() {
800
+ const host = this.host;
801
+ this.setValidity(host.validity.valid);
802
+ }
803
+ /**
804
+ * Dispatches a non-bubbling, cancelable custom event of type `it-invalid`.
805
+ * If the `it-invalid` event will be cancelled then the original `invalid`
806
+ * event (which may have been passed as argument) will also be cancelled.
807
+ * If no original `invalid` event has been passed then the `it-invalid`
808
+ * event will be cancelled before being dispatched.
809
+ */
810
+ emitInvalidEvent(originalInvalidEvent) {
811
+ const itInvalidEvent = new CustomEvent('it-invalid', {
812
+ bubbles: false,
813
+ composed: false,
814
+ cancelable: true,
815
+ detail: {},
816
+ });
817
+ if (!originalInvalidEvent) {
818
+ itInvalidEvent.preventDefault();
819
+ }
820
+ if (!this.host.dispatchEvent(itInvalidEvent)) {
821
+ originalInvalidEvent?.preventDefault();
822
+ }
823
+ }
824
+ }
825
+
826
+ const translation = {
827
+ $code: 'it',
828
+ $name: 'Italiano',
829
+ $dir: 'ltr',
830
+ validityRequired: 'Questo campo è obbligatorio.',
831
+ validityGroupRequired: "Scegli almeno un'opzione",
832
+ validityPattern: 'Il valore non corrisponde al formato richiesto.',
833
+ validityMinlength: 'Il valore deve essere lungo almeno {minlength} caratteri.',
834
+ validityMaxlength: 'Il valore deve essere lungo al massimo {maxlength} caratteri.',
835
+ };
836
+
837
+ registerTranslation(translation);
838
+ class FormControl extends BaseLocalizedComponent {
839
+ constructor() {
840
+ super(...arguments);
841
+ this.formControlController = new FormControlController(this, {
842
+ assumeInteractionOn: ['it-input', 'it-blur', 'it-change'],
843
+ });
844
+ // TODO: verificare se serve davvero con il fatto che usiamo form-controller
845
+ // static formAssociated = true;
846
+ // @property()
847
+ // internals = this.attachInternals();
848
+ this._touched = false;
849
+ /** The name of the input, submitted as a name/value pair with form data. */
850
+ this.name = '';
851
+ /** The current value of the input, submitted as a name/value pair with form data. */
852
+ this.value = '';
853
+ /** If the input is disabled. */
854
+ this.disabled = false;
855
+ /**
856
+ * By default, form controls are associated with the nearest containing `<form>` element. This attribute allows you
857
+ * to place the form control outside of a form and associate it with the form that has this `id`. The form must be in
858
+ * the same document or shadow root for this to work.
859
+ */
860
+ this.form = '';
861
+ /** If you implement your custom validation and you won't to trigger default validation */
862
+ this.customValidation = false;
863
+ /** If your input is invalid from your custom validition, set this attribute with message validation */
864
+ this.validationText = '';
865
+ /**
866
+ * Specifies the granularity that the value must adhere to, or the special value `any` which means no stepping is
867
+ * implied, allowing any numeric value. Only applies to date and number input types.
868
+ */
869
+ this.step = 'any';
870
+ /** The input's minimum length. */
871
+ this.minlength = -1;
872
+ /** The input's maximum length. */
873
+ this.maxlength = -1;
874
+ /** If the input is required. */
875
+ this.required = false;
876
+ /* For grouped input, like checkbox-group */
877
+ this.isInGroup = false;
878
+ this.validationMessage = '';
879
+ }
880
+ /** Gets the validity state object */
881
+ get validity() {
882
+ return this.inputElement?.validity;
883
+ }
884
+ /** Gets the associated form, if one exists. */
885
+ getForm() {
886
+ return this.formControlController.getForm();
887
+ }
888
+ // Form validation methods
889
+ checkValidity() {
890
+ const inputValid = this.inputElement?.checkValidity() ?? true; // this.inputElement.checkValidity() è la validazione del browser
891
+ return inputValid;
892
+ }
893
+ /** Checks for validity and shows the browser's validation message if the control is invalid. */
894
+ reportValidity() {
895
+ // const ret = this.inputElement.checkValidity();
896
+ const ret = this.checkValidity(); // chiama la checkValidity, che se è stata overridata chiama quella
897
+ this.handleValidationMessages();
898
+ return ret; // this.inputElement.reportValidity();
899
+ }
900
+ /** Sets a custom validation message. Pass an empty string to restore validity. */
901
+ setCustomValidity(message) {
902
+ this.inputElement.setCustomValidity(message);
903
+ this.validationMessage = this.inputElement.validationMessage;
904
+ this.formControlController.updateValidity();
905
+ }
906
+ // Handlers
907
+ _handleReady() {
908
+ requestAnimationFrame(() => {
909
+ this.dispatchEvent(new CustomEvent('it-input-ready', { bubbles: true, detail: { el: this.inputElement } }));
910
+ });
911
+ }
912
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
913
+ _handleInput(e) {
914
+ this.handleValidationMessages();
915
+ this.dispatchEvent(new CustomEvent('it-input', {
916
+ detail: { value: this.inputElement.value, el: this.inputElement },
917
+ bubbles: true,
918
+ composed: true,
919
+ }));
920
+ }
921
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
922
+ _handleBlur(e) {
923
+ this._touched = true;
924
+ this.handleValidationMessages();
925
+ this.dispatchEvent(new FocusEvent('it-blur', { bubbles: true, composed: true }));
926
+ }
927
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
928
+ _handleFocus(e) {
929
+ this.dispatchEvent(new FocusEvent('it-focus', { bubbles: true, composed: true }));
930
+ }
931
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
932
+ _handleClick(e) {
933
+ this.dispatchEvent(new MouseEvent('it-click', { bubbles: true, composed: true }));
934
+ }
935
+ /*
936
+ Override default browser validation messages
937
+ */
938
+ handleValidationMessages() {
939
+ if (!this.customValidation) {
940
+ const _v = this.inputElement.validity;
941
+ const isRequiredHandledByGroup = this.isInGroup === true;
942
+ if (_v.valueMissing && !isRequiredHandledByGroup) {
943
+ this.setCustomValidity(this.$t('validityRequired'));
944
+ }
945
+ else if (_v.patternMismatch) {
946
+ this.setCustomValidity(this.$t('validityPattern'));
947
+ }
948
+ else if (_v.tooShort) {
949
+ this.setCustomValidity(this.$t('validityMinlength').replace('{minlength}', this.minlength.toString()));
950
+ }
951
+ else if (_v.tooLong) {
952
+ this.setCustomValidity(this.$t('validityMaxlength').replace('{maxlength}', this.maxlength.toString()));
953
+ }
954
+ else {
955
+ /* nothing. Usa il messaggio di errore della validazione
956
+ di default del browser per altri errori di validità come:
957
+ - typeMismatch
958
+ - rangeUnderflow
959
+ - rangeOverflow
960
+ - stepMismatch
961
+ - badInput */
962
+ const otherConstraintErrors = _v.typeMismatch || _v.rangeUnderflow || _v.rangeOverflow || _v.stepMismatch || _v.badInput;
963
+ if (!otherConstraintErrors) {
964
+ this.setCustomValidity('');
965
+ }
966
+ }
967
+ }
968
+ this.validationMessage = this.inputElement.validationMessage;
969
+ }
970
+ _handleInvalid(event) {
971
+ this.formControlController.setValidity(false);
972
+ this.formControlController.emitInvalidEvent(event);
973
+ }
974
+ _handleChange(e) {
975
+ const target = e.target;
976
+ let value;
977
+ if (target instanceof HTMLInputElement) {
978
+ switch (target.type) {
979
+ case 'checkbox':
980
+ case 'radio':
981
+ value = target.checked;
982
+ break;
983
+ case 'file':
984
+ value = target.files; // FileList
985
+ break;
986
+ default:
987
+ value = target.value;
988
+ }
989
+ }
990
+ else if (target instanceof HTMLSelectElement) {
991
+ if (target.multiple) {
992
+ value = Array.from(target.selectedOptions).map((o) => o.value);
993
+ }
994
+ else {
995
+ value = target.value;
996
+ }
997
+ }
998
+ else {
999
+ // textarea o altri input con value
1000
+ value = target.value;
1001
+ }
1002
+ this.dispatchEvent(new CustomEvent('it-change', {
1003
+ detail: { value, el: target },
1004
+ bubbles: true,
1005
+ composed: true,
1006
+ }));
1007
+ }
1008
+ updated(changedProperties) {
1009
+ super.updated?.(changedProperties);
1010
+ if (this.customValidation) {
1011
+ this.setCustomValidity(this.validationText ?? '');
1012
+ }
1013
+ else if (this.formControlController.userInteracted()) {
1014
+ this.formControlController.updateValidity();
1015
+ }
1016
+ }
1017
+ }
1018
+ __decorate([
1019
+ state(),
1020
+ __metadata("design:type", Object)
1021
+ ], FormControl.prototype, "_touched", void 0);
1022
+ __decorate([
1023
+ query('.it-form__control'),
1024
+ __metadata("design:type", HTMLInputElement)
1025
+ ], FormControl.prototype, "inputElement", void 0);
1026
+ __decorate([
1027
+ property({ type: String, reflect: true }) // from FormControl
1028
+ ,
1029
+ __metadata("design:type", Object)
1030
+ ], FormControl.prototype, "name", void 0);
1031
+ __decorate([
1032
+ property({ reflect: true }),
1033
+ __metadata("design:type", Object)
1034
+ ], FormControl.prototype, "value", void 0);
1035
+ __decorate([
1036
+ property({ type: Boolean, reflect: true }) // from FormControl
1037
+ ,
1038
+ __metadata("design:type", Object)
1039
+ ], FormControl.prototype, "disabled", void 0);
1040
+ __decorate([
1041
+ property({ reflect: true, type: String }),
1042
+ __metadata("design:type", Object)
1043
+ ], FormControl.prototype, "form", void 0);
1044
+ __decorate([
1045
+ property({ type: Boolean, reflect: true, attribute: 'custom-validation' }),
1046
+ __metadata("design:type", Object)
1047
+ ], FormControl.prototype, "customValidation", void 0);
1048
+ __decorate([
1049
+ property({ attribute: 'validity-message', reflect: true }),
1050
+ __metadata("design:type", String)
1051
+ ], FormControl.prototype, "validationText", void 0);
1052
+ __decorate([
1053
+ property(),
1054
+ __metadata("design:type", String)
1055
+ ], FormControl.prototype, "pattern", void 0);
1056
+ __decorate([
1057
+ property(),
1058
+ __metadata("design:type", Object)
1059
+ ], FormControl.prototype, "min", void 0);
1060
+ __decorate([
1061
+ property(),
1062
+ __metadata("design:type", Object)
1063
+ ], FormControl.prototype, "max", void 0);
1064
+ __decorate([
1065
+ property(),
1066
+ __metadata("design:type", Object)
1067
+ ], FormControl.prototype, "step", void 0);
1068
+ __decorate([
1069
+ property({ type: Number }),
1070
+ __metadata("design:type", Object)
1071
+ ], FormControl.prototype, "minlength", void 0);
1072
+ __decorate([
1073
+ property({ type: Number }),
1074
+ __metadata("design:type", Object)
1075
+ ], FormControl.prototype, "maxlength", void 0);
1076
+ __decorate([
1077
+ property({ type: Boolean, reflect: true }) // from FormControl
1078
+ ,
1079
+ __metadata("design:type", Object)
1080
+ ], FormControl.prototype, "required", void 0);
1081
+ __decorate([
1082
+ property({ type: Boolean }),
1083
+ __metadata("design:type", Object)
1084
+ ], FormControl.prototype, "isInGroup", void 0);
1085
+ __decorate([
1086
+ state(),
1087
+ __metadata("design:type", Object)
1088
+ ], FormControl.prototype, "validationMessage", void 0);
1089
+
1090
+ if (typeof window !== 'undefined') {
1091
+ window._itAnalytics = window._itAnalytics || {};
1092
+ window._itAnalytics = {
1093
+ ...window._itAnalytics,
1094
+ version: '1.0.0-alpha.10',
1095
+ };
1096
+ }
209
1097
 
210
1098
  var styles = css`/***************************** 1 ****************************************/
211
1099
  /***************************** 2 ****************************************/
@@ -272,78 +1160,82 @@ button:not(:disabled),
272
1160
  }
273
1161
  }
274
1162
  .btn {
275
- --bs-btn-padding-x: var(--bs-spacing-s);
276
- --bs-btn-padding-y: var(--bs-spacing-xs);
277
- --bs-btn-font-family: var(--bs-font-sans);
278
- --bs-btn-font-weight: var(--bs-font-weight-solid);
279
- --bs-btn-font-size: var(--bs-label-font-size);
280
- --bs-btn-line-height: var(--bs-font-line-height-3);
281
- --bs-btn-text-color: var(--bs-color-text-primary);
282
- --bs-btn-background: transparent;
283
- --bs-btn-border-size: 0;
284
- --bs-btn-border-color: transparent;
285
- --bs-btn-border-radius: var(--bs-radius-smooth);
286
- --bs-btn-outline-border-size: 2px;
287
- --bs-btn-outline-border-color: transparent;
288
- --bs-btn-disabled-opacity: 0.5;
1163
+ --bsi-btn-background: transparent;
1164
+ --bsi-btn-border-color: transparent;
1165
+ --bsi-btn-border-radius: var(--bsi-radius-smooth);
1166
+ --bsi-btn-border-size: 0;
1167
+ --bsi-btn-disabled-opacity: 0.5;
1168
+ --bsi-btn-font-family: var(--bsi-font-sans);
1169
+ --bsi-btn-font-size: var(--bsi-label-font-size);
1170
+ --bsi-btn-font-weight: var(--bsi-font-weight-solid);
1171
+ --bsi-btn-line-height: var(--bsi-font-leading-3);
1172
+ --bsi-btn-outline-border-color: transparent;
1173
+ --bsi-btn-outline-border-size: 2px;
1174
+ --bsi-btn-padding-x: var(--bsi-spacing-s);
1175
+ --bsi-btn-padding-y: var(--bsi-spacing-xs);
1176
+ --bsi-btn-text-color: var(--bsi-color-text-primary);
289
1177
  }
290
1178
 
1179
+ /* stylelint-disable-next-line no-duplicate-selectors */
291
1180
  .btn {
292
1181
  display: inline-block;
293
- padding: var(--bs-btn-padding-y) var(--bs-btn-padding-x);
294
- border: var(--bs-btn-border-width) solid var(--bs-btn-border-color);
295
- border-radius: var(--bs-btn-border-radius);
296
- background: var(--bs-btn-background);
297
- box-shadow: var(--bs-btn-box-shadow, none);
298
- color: var(--bs-btn-text-color);
299
- font-family: var(--bs-btn-font-family);
300
- font-size: var(--bs-btn-font-size);
301
- font-weight: var(--bs-btn-font-weight);
302
- line-height: var(--bs-btn-line-height);
1182
+ padding: var(--bsi-btn-padding-y) var(--bsi-btn-padding-x);
1183
+ border: var(--bsi-btn-border-width) solid var(--bsi-btn-border-color);
1184
+ border-radius: var(--bsi-btn-border-radius);
1185
+ background: var(--bsi-btn-background);
1186
+ box-shadow: var(--bsi-btn-box-shadow, none);
1187
+ color: var(--bsi-btn-text-color);
1188
+ font-family: var(--bsi-btn-font-family);
1189
+ font-size: var(--bsi-btn-font-size);
1190
+ font-weight: var(--bsi-btn-font-weight);
1191
+ line-height: var(--bsi-btn-line-height);
303
1192
  text-align: center;
304
1193
  text-decoration: none;
305
1194
  vertical-align: middle;
306
1195
  white-space: initial;
307
1196
  width: auto;
308
- transition: all var(--bs-transition-instant) ease-in-out;
1197
+ transition: all var(--bsi-transition-instant) ease-in-out;
309
1198
  user-select: none;
310
1199
  }
1200
+ .btn:hover {
1201
+ color: var(--bsi-btn-text-color);
1202
+ }
311
1203
  .btn:disabled, .btn.disabled {
312
- opacity: var(--bs-btn-disabled-opacity);
1204
+ opacity: var(--bsi-btn-disabled-opacity);
313
1205
  cursor: not-allowed;
314
1206
  pointer-events: none;
315
1207
  }
316
1208
  .btn:focus-visible {
317
- border-color: var(--bs-btn-hover-border-color);
1209
+ border-color: var(--bsi-btn-hover-border-color);
318
1210
  outline: 0;
319
1211
  }
320
1212
  .btn-check:focus-visible + .btn {
321
- border-color: var(--bs-btn-hover-border-color);
1213
+ border-color: var(--bsi-btn-hover-border-color);
322
1214
  outline: 0;
323
1215
  }
324
1216
 
325
1217
  .btn-link {
326
- --bs-btn-background: transparent;
327
- --bs-btn-border-color: transparent;
1218
+ --bsi-btn-background: transparent;
1219
+ --bsi-btn-border-color: transparent;
328
1220
  text-decoration: underline;
329
1221
  }
330
1222
  .btn-link:hover {
331
- color: var(--bs-color-link-hover);
1223
+ color: var(--bsi-color-link-hover);
332
1224
  }
333
1225
 
334
1226
  .btn-xs {
335
- --bs-btn-padding-x: var(--bs-spacing-xs);
336
- --bs-btn-padding-y: var(--bs-spacing-xs);
337
- --bs-btn-font-size: var(--bs-label-font-size-s);
338
- --bs-btn-line-height: var(--bs-font-line-height-1);
339
- --bs-rounded-icon-size: 20px;
1227
+ --bsi-btn-padding-x: var(--bsi-spacing-xs);
1228
+ --bsi-btn-padding-y: var(--bsi-spacing-xs);
1229
+ --bsi-btn-font-size: var(--bsi-label-font-size-s);
1230
+ --bsi-btn-line-height: var(--bsi-font-leading-1);
1231
+ --bsi-rounded-icon-size: 20px;
340
1232
  }
341
1233
 
342
1234
  .btn-lg {
343
- --bs-btn-padding-x: var(--bs-spacing-m);
344
- --bs-btn-padding-y: var(--bs-spacing-s);
345
- --bs-btn-font-size: var(--bs-label-font-size-m);
346
- --bs-btn-line-height: var(--bs-font-line-height-5);
1235
+ --bsi-btn-padding-x: var(--bsi-spacing-m);
1236
+ --bsi-btn-padding-y: var(--bsi-spacing-s);
1237
+ --bsi-btn-font-size: var(--bsi-label-font-size-l);
1238
+ --bsi-btn-line-height: var(--bsi-font-leading-5);
347
1239
  }
348
1240
 
349
1241
  .btn-progress {
@@ -355,7 +1247,7 @@ button:not(:disabled),
355
1247
  flex-direction: row;
356
1248
  align-items: center;
357
1249
  justify-content: center;
358
- gap: var(--bs-icon-spacing);
1250
+ gap: var(--bsi-icon-spacing);
359
1251
  }
360
1252
 
361
1253
  .btn-full {
@@ -382,16 +1274,16 @@ button:not(:disabled),
382
1274
 
383
1275
  .btn-primary,
384
1276
  a.btn-primary {
385
- --bs-btn-text-color: var(--bs-color-text-inverse);
386
- --bs-btn-background: var(--bs-color-background-primary);
1277
+ --bsi-btn-text-color: var(--bsi-color-text-inverse);
1278
+ --bsi-btn-background: var(--bsi-color-background-primary);
387
1279
  }
388
1280
  .btn-primary:hover,
389
1281
  a.btn-primary:hover {
390
- --bs-btn-background: var(--bs-color-background-primary-hover);
1282
+ --bsi-btn-background: var(--bsi-color-background-primary-hover);
391
1283
  }
392
1284
  .btn-primary:active,
393
1285
  a.btn-primary:active {
394
- --bs-btn-background: var(--bs-color-background-primary-active);
1286
+ --bsi-btn-background: var(--bsi-color-background-primary-active);
395
1287
  }
396
1288
  .btn-primary.btn-progress,
397
1289
  a.btn-primary.btn-progress {
@@ -402,16 +1294,16 @@ a.btn-primary.btn-progress {
402
1294
 
403
1295
  .btn-secondary,
404
1296
  a.btn-secondary {
405
- --bs-btn-text-color: var(--bs-color-text-inverse);
406
- --bs-btn-background: var(--bs-color-background-secondary);
1297
+ --bsi-btn-text-color: var(--bsi-color-text-inverse);
1298
+ --bsi-btn-background: var(--bsi-color-background-secondary);
407
1299
  }
408
1300
  .btn-secondary:hover,
409
1301
  a.btn-secondary:hover {
410
- --bs-btn-background: var(--bs-color-background-secondary-hover);
1302
+ --bsi-btn-background: var(--bsi-color-background-secondary-hover);
411
1303
  }
412
1304
  .btn-secondary:active,
413
1305
  a.btn-secondary:active {
414
- --bs-btn-background: var(--bs-color-background-secondary-active);
1306
+ --bsi-btn-background: var(--bsi-color-background-secondary-active);
415
1307
  }
416
1308
  .btn-secondary:disabled.btn-progress, .btn-secondary.disabled.btn-progress,
417
1309
  a.btn-secondary:disabled.btn-progress,
@@ -423,135 +1315,174 @@ a.btn-secondary.disabled.btn-progress {
423
1315
 
424
1316
  .btn-success,
425
1317
  a.btn-success {
426
- --bs-btn-text-color: var(--bs-color-text-inverse);
427
- --bs-btn-background: var(--bs-color-background-success);
1318
+ --bsi-btn-text-color: var(--bsi-color-text-inverse);
1319
+ --bsi-btn-background: var(--bsi-color-background-success);
428
1320
  }
429
1321
  .btn-success:hover,
430
1322
  a.btn-success:hover {
431
- --bs-btn-background: var(--bs-color-background-success-hover);
1323
+ --bsi-btn-background: var(--bsi-color-background-success-hover);
432
1324
  }
433
1325
  .btn-success:active,
434
1326
  a.btn-success:active {
435
- --bs-btn-background: var(--bs-color-background-success-active);
1327
+ --bsi-btn-background: var(--bsi-color-background-success-active);
436
1328
  }
437
1329
 
438
1330
  .btn-warning,
439
1331
  a.btn-warning {
440
- --bs-btn-text-color: var(--bs-color-text-inverse);
441
- --bs-btn-background: var(--bs-color-background-warning);
1332
+ --bsi-btn-text-color: var(--bsi-color-text-inverse);
1333
+ --bsi-btn-background: var(--bsi-color-background-warning);
442
1334
  }
443
1335
  .btn-warning:hover,
444
1336
  a.btn-warning:hover {
445
- --bs-btn-background: var(--bs-color-background-warning-hover);
1337
+ --bsi-btn-background: var(--bsi-color-background-warning-hover);
446
1338
  }
447
1339
  .btn-warning:active,
448
1340
  a.btn-warning:active {
449
- --bs-btn-background: var(--bs-color-background-warning-active);
1341
+ --bsi-btn-background: var(--bsi-color-background-warning-active);
450
1342
  }
451
1343
 
452
1344
  .btn-danger,
453
1345
  a.btn-danger {
454
- --bs-btn-text-color: var(--bs-color-text-inverse);
455
- --bs-btn-background: var(--bs-color-background-danger);
1346
+ --bsi-btn-text-color: var(--bsi-color-text-inverse);
1347
+ --bsi-btn-background: var(--bsi-color-background-danger);
456
1348
  }
457
1349
  .btn-danger:hover,
458
1350
  a.btn-danger:hover {
459
- --bs-btn-background: var(--bs-color-background-danger-hover);
1351
+ --bsi-btn-background: var(--bsi-color-background-danger-hover);
460
1352
  }
461
1353
  .btn-danger:active,
462
1354
  a.btn-danger:active {
463
- --bs-btn-background: var(--bs-color-background-danger-active);
1355
+ --bsi-btn-background: var(--bsi-color-background-danger-active);
464
1356
  }
465
1357
 
466
1358
  .btn[class*=btn-outline-] {
467
- --bs-btn-box-shadow: inset 0 0 0 var(--bs-btn-outline-border-size) var(--bs-btn-outline-border-color);
1359
+ --bsi-btn-box-shadow: inset 0 0 0 var(--bsi-btn-outline-border-size) var(--bsi-btn-outline-border-color);
468
1360
  }
469
1361
 
470
1362
  .btn-outline-primary,
471
1363
  a.btn-outline-primary {
472
- --bs-btn-outline-border-color: var(--bs-color-border-primary);
473
- --bs-btn-text-color: var(--bs-color-text-primary);
1364
+ --bsi-btn-outline-border-color: var(--bsi-color-border-primary);
1365
+ --bsi-btn-text-color: var(--bsi-color-text-primary);
474
1366
  }
475
1367
  .btn-outline-primary:hover,
476
1368
  a.btn-outline-primary:hover {
477
- --bs-btn-outline-border-color: var(--bs-color-border-primary-hover);
478
- --bs-btn-text-color: var(--bs-color-link-hover);
1369
+ --bsi-btn-outline-border-color: color-mix(in srgb, var(--bsi-color-border-primary-hover) 70%, black);
1370
+ --bsi-btn-text-color: var(--bsi-color-link-hover);
479
1371
  }
480
1372
  .btn-outline-primary:active,
481
1373
  a.btn-outline-primary:active {
482
- --bs-btn-outline-border-color: var(--bs-color-border-primary-active);
483
- --bs-btn-text-color: var(--bs-color-link-active);
1374
+ --bsi-btn-outline-border-color: var(--bsi-color-border-primary-active);
1375
+ --bsi-btn-text-color: var(--bsi-color-link-active);
484
1376
  }
485
1377
  .btn-outline-secondary,
486
1378
  a.btn-outline-secondary {
487
- --bs-btn-outline-border-color: var(--bs-color-border-secondary);
488
- --bs-btn-text-color: var(--bs-color-text-secondary);
1379
+ --bsi-btn-outline-border-color: var(--bsi-color-border-secondary);
1380
+ --bsi-btn-text-color: var(--bsi-color-text-secondary);
489
1381
  }
490
1382
  .btn-outline-secondary:hover,
491
1383
  a.btn-outline-secondary:hover {
492
- --bs-btn-outline-border-color: var(--bs-color-border-secondary-hover);
493
- --bs-btn-text-color: var(--bs-color-text-secondary-hover);
1384
+ --bsi-btn-outline-border-color: var(--bsi-color-border-secondary-hover);
1385
+ --bsi-btn-text-color: var(--bsi-color-link-secondary-hover);
494
1386
  }
495
1387
  .btn-outline-secondary:active,
496
1388
  a.btn-outline-secondary:active {
497
- --bs-btn-outline-border-color: var(--bs-color-border-secondary-active);
498
- --bs-btn-text-color: var(--bs-color-text-secondary-active);
1389
+ --bsi-btn-outline-border-color: var(--bsi-color-border-secondary-active);
1390
+ --bsi-btn-text-color: var(--bsi-color-link-secondary-active);
499
1391
  }
500
1392
  .btn-outline-success,
501
1393
  a.btn-outline-success {
502
- --bs-btn-outline-border-color: var(--bs-color-border-success);
503
- --bs-btn-text-color: var(--bs-color-text-success);
1394
+ --bsi-btn-outline-border-color: var(--bsi-color-border-success);
1395
+ --bsi-btn-text-color: var(--bsi-color-text-success);
504
1396
  }
505
1397
  .btn-outline-success:hover,
506
1398
  a.btn-outline-success:hover {
507
- --bs-btn-outline-border-color: var(--bs-color-border-success-hover);
508
- --bs-btn-text-color: var(--bs-color-text-success-hover);
1399
+ /* aumenta contrasto scurendo il bordo rispetto al token base */
1400
+ --bsi-btn-outline-border-color: color-mix(in srgb, var(--bsi-color-border-success-hover) 70%, black);
1401
+ --bsi-btn-text-color: var(--bsi-color-text-success-hover);
509
1402
  }
510
1403
  .btn-outline-success:active,
511
1404
  a.btn-outline-success:active {
512
- --bs-btn-outline-border-color: var(--bs-color-border-success-active);
513
- --bs-btn-text-color: var(--bs-color-text-success-active);
1405
+ --bsi-btn-outline-border-color: var(--bsi-color-border-success-active);
1406
+ --bsi-btn-text-color: var(--bsi-color-text-success-active);
514
1407
  }
515
1408
  .btn-outline-warning,
516
1409
  a.btn-outline-warning {
517
- --bs-btn-outline-border-color: var(--bs-color-border-warning);
518
- --bs-btn-text-color: var(--bs-color-text-warning);
1410
+ --bsi-btn-outline-border-color: var(--bsi-color-border-warning);
1411
+ --bsi-btn-text-color: var(--bsi-color-text-warning);
519
1412
  }
520
1413
  .btn-outline-warning:hover,
521
1414
  a.btn-outline-warning:hover {
522
- --bs-btn-outline-border-color: var(--bs-color-border-warning-hover);
523
- --bs-btn-text-color: var(--bs-color-text-warning-hover);
1415
+ --bsi-btn-outline-border-color: color-mix(in srgb, var(--bsi-color-border-warning-hover) 70%, black);
1416
+ --bsi-btn-text-color: var(--bsi-color-text-warning-hover);
524
1417
  }
525
1418
  .btn-outline-warning:active,
526
1419
  a.btn-outline-warning:active {
527
- --bs-btn-outline-border-color: var(--bs-color-border-warning-active);
528
- --bs-btn-text-color: var(--bs-color-text-warning-active);
1420
+ --bsi-btn-outline-border-color: var(--bsi-color-border-warning-active);
1421
+ --bsi-btn-text-color: var(--bsi-color-text-warning-active);
529
1422
  }
530
1423
  .btn-outline-danger,
531
1424
  a.btn-outline-danger {
532
- --bs-btn-outline-border-color: var(--bs-color-border-danger);
533
- --bs-btn-text-color: var(--bs-color-text-danger);
1425
+ --bsi-btn-outline-border-color: var(--bsi-color-border-danger);
1426
+ --bsi-btn-text-color: var(--bsi-color-text-danger);
534
1427
  }
535
1428
  .btn-outline-danger:hover,
536
1429
  a.btn-outline-danger:hover {
537
- --bs-btn-outline-border-color: var(--bs-color-border-danger-hover);
538
- --bs-btn-text-color: var(--bs-color-text-danger-hover);
1430
+ --bsi-btn-outline-border-color: color-mix(in srgb, var(--bsi-color-border-danger-hover) 70%, black);
1431
+ --bsi-btn-text-color: var(--bsi-color-text-danger-hover);
539
1432
  }
540
1433
  .btn-outline-danger:active,
541
1434
  a.btn-outline-danger:active {
542
- --bs-btn-outline-border-color: var(--bs-color-border-danger-active);
543
- --bs-btn-text-color: var(--bs-color-text-danger-active);
1435
+ --bsi-btn-outline-border-color: var(--bsi-color-border-danger-active);
1436
+ --bsi-btn-text-color: var(--bsi-color-text-danger-active);
544
1437
  }
545
1438
 
546
1439
  .bg-dark .btn-link {
547
- --bs-btn-text-color: var(--bs-color-text-inverse);
1440
+ --bsi-btn-text-color: var(--bsi-color-text-inverse);
1441
+ }
1442
+ .bg-dark a.btn-primary,
1443
+ .bg-dark .btn-primary {
1444
+ --bsi-btn-text-color: var(--bsi-color-text-primary);
1445
+ --bsi-btn-background: var(--bsi-color-background-inverse);
1446
+ }
1447
+ .bg-dark a.btn-primary:hover,
1448
+ .bg-dark .btn-primary:hover {
1449
+ --bsi-btn-background: color-mix(in srgb, var(--bsi-color-background-inverse) 85%, black);
1450
+ }
1451
+ .bg-dark a.btn-primary:active,
1452
+ .bg-dark .btn-primary:active {
1453
+ --bsi-btn-background: color-mix(in srgb, var(--bsi-color-background-inverse) 80%, black);
1454
+ }
1455
+ .bg-dark a.btn-secondary,
1456
+ .bg-dark .btn-secondary {
1457
+ --bsi-btn-text-color: var(--bsi-color-text-inverse);
1458
+ --bsi-btn-background: var(--bsi-color-background-secondary);
1459
+ }
1460
+ .bg-dark a.btn-secondary:hover, .bg-dark a.btn-secondary:active,
1461
+ .bg-dark .btn-secondary:hover,
1462
+ .bg-dark .btn-secondary:active {
1463
+ --bsi-btn-background: color-mix(in srgb, var(--bsi-color-background-secondary) 85%, black);
548
1464
  }
549
1465
  .bg-dark .btn-outline-primary,
550
- .bg-dark a.btn-outline-primary,
1466
+ .bg-dark a.btn-outline-primary {
1467
+ --bsi-btn-outline-border-color: var(--bsi-color-border-inverse);
1468
+ --bsi-btn-text-color: var(--bsi-color-text-inverse);
1469
+ }
1470
+ .bg-dark .btn-outline-primary:hover,
1471
+ .bg-dark a.btn-outline-primary:hover {
1472
+ --bsi-btn-boxshadow-color-darken: color-mix(in srgb, var(--bsi-color-border-inverse) 80%, black);
1473
+ --bsi-btn-boxshadow-color-desaturated: color-mix(in srgb, var(--bsi-btn-boxshadow-color-darken) 80%, gray);
1474
+ --bsi-btn-outline-border-color: var(--bsi-btn-boxshadow-color-desaturated);
1475
+ }
551
1476
  .bg-dark .btn-outline-secondary,
552
1477
  .bg-dark a.btn-outline-secondary {
553
- --bs-btn-outline-border-color: var(--bs-color-border-inverse);
554
- --bs-btn-text-color: var(--bs-color-text-inverse);
1478
+ --bsi-btn-text-color: var(--bsi-color-text-inverse);
1479
+ }
1480
+ .bg-dark .btn-outline-secondary:hover, .bg-dark .btn-outline-secondary:active,
1481
+ .bg-dark a.btn-outline-secondary:hover,
1482
+ .bg-dark a.btn-outline-secondary:active {
1483
+ --bsi-btn-boxshadow-color-darken: color-mix(in srgb, var(--bsi-color-background-secondary) 80%, black);
1484
+ --bsi-btn-boxshadow-color-desaturated: color-mix(in srgb, var(--bsi-btn-boxshadow-color-darken) 80%, gray);
1485
+ --bsi-btn-outline-border-color: var(--bsi-btn-boxshadow-color-desaturated);
555
1486
  }
556
1487
 
557
1488
  .btn-close {
@@ -561,25 +1492,24 @@ a.btn-outline-danger:active {
561
1492
  height: 2.5rem;
562
1493
  padding: 0;
563
1494
  border: 0;
564
- opacity: 0.5;
565
1495
  background-color: transparent;
566
- color: var(--bs-color-text-base);
567
1496
  }
568
1497
  .btn-close .icon {
569
1498
  position: absolute;
570
1499
  top: 50%;
571
1500
  left: 50%;
572
1501
  transform: translate(-50%, -50%);
1502
+ fill: var(--bsi-icon-secondary);
573
1503
  }
574
- .btn-close:hover {
575
- opacity: 1;
1504
+ .btn-close .icon:hover {
1505
+ fill: var(--bsi-icon-default);
576
1506
  text-decoration: none;
577
1507
  }
578
1508
  .btn-close:focus {
579
1509
  opacity: 1;
580
1510
  }
581
1511
  .btn-close:disabled, .btn-close.disabled {
582
- opacity: var(--bs-btn-disabled-opacity);
1512
+ opacity: var(--bsi-btn-disabled-opacity);
583
1513
  pointer-events: none;
584
1514
  user-select: none;
585
1515
  }
@@ -588,46 +1518,69 @@ a.btn-outline-danger:active {
588
1518
  filter: invert(1) grayscale(100%) brightness(200%);
589
1519
  }`;
590
1520
 
591
- let ItButton = class ItButton extends BaseComponent {
1521
+ var ItButton_1;
1522
+ let ItButton = ItButton_1 = class ItButton extends BaseComponent {
592
1523
  constructor() {
593
1524
  super(...arguments);
594
- this._buttonClasses = '';
595
1525
  this.type = 'button';
596
1526
  this.variant = '';
597
1527
  this.size = '';
598
1528
  this.outline = false;
599
1529
  this.block = false;
600
- this.icon = false;
601
1530
  this.value = '';
1531
+ this.itInert = false;
602
1532
  this.internals = this.attachInternals();
1533
+ this._hasIcon = false;
1534
+ this._hasProgress = false;
603
1535
  this._onKeyDown = (e) => {
604
1536
  if (e.key === 'Enter' || e.key === ' ') {
605
1537
  e.preventDefault();
606
- this._nativeButton?.click();
1538
+ if (!this.disabled) {
1539
+ this._nativeButton?.click();
1540
+ }
1541
+ else {
1542
+ e.stopPropagation();
1543
+ }
607
1544
  }
608
1545
  };
1546
+ this._updateSlottedStates = (elements) => {
1547
+ this._hasIcon = ItButton_1.hasMatchingElement(elements, 'it-icon');
1548
+ this._hasProgress = ItButton_1.hasMatchingElement(elements, 'it-progress');
1549
+ };
1550
+ this._onSlotChange = (event) => {
1551
+ const slot = event.target;
1552
+ const assignedElements = slot.assignedElements({ flatten: true });
1553
+ this._updateSlottedStates(assignedElements);
1554
+ };
609
1555
  }
610
1556
  static get formAssociated() {
611
1557
  return true;
612
1558
  }
613
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
614
- firstUpdated(_changedProperties) {
615
- const button = this.renderRoot.querySelector('button');
616
- if (button) {
617
- this.addFocus(button);
618
- }
619
- }
620
- updated() {
621
- this._buttonClasses = this.composeClass('btn', !this.outline && this.variant !== '' ? `btn-${this.variant}` : '', this.outline ? `${this.variant ? 'btn-outline-' : ''}${this.variant}` : '', 'aria-disabled' in this._ariaAttributes ? 'disabled' : '', this.size ? `btn-${this.size}` : '', this.block ? 'd-block w-100' : '', this.icon ? 'btn-icon' : '');
622
- }
623
1559
  surfaceSubmitEvent(event) {
624
- const disabled = 'aria-disabled' in this._ariaAttributes;
625
- if (this.form && !disabled) {
1560
+ if (this.form && !this.disabled) {
626
1561
  event.preventDefault();
627
1562
  event.stopPropagation();
628
- this.form.requestSubmit();
1563
+ let someInvalid = false;
1564
+ // valido ogni campo
1565
+ const itItems = Array.from(this.form.querySelectorAll('*')).filter((el) => el.tagName.toLowerCase().startsWith('it-'));
1566
+ itItems.forEach((itItem) => {
1567
+ // Accedi allo Shadow DOM del web component
1568
+ if (itItem.checkValidity) {
1569
+ itItem.checkValidity();
1570
+ }
1571
+ const isValid = itItem?.isValid ? itItem.isValid() : true;
1572
+ // Controlla se l'input interno esiste e se non è valido
1573
+ if (!isValid) {
1574
+ someInvalid = true;
1575
+ // eslint-disable-next-line no-console
1576
+ console.error(`Invalid field: [name]=${itItem.name}, [id]=${itItem.id}`);
1577
+ }
1578
+ });
1579
+ if (!someInvalid) {
1580
+ this.form.requestSubmit();
1581
+ }
629
1582
  }
630
- if (disabled) {
1583
+ if (this.disabled) {
631
1584
  event.preventDefault();
632
1585
  event.stopPropagation();
633
1586
  }
@@ -635,6 +1588,23 @@ let ItButton = class ItButton extends BaseComponent {
635
1588
  get form() {
636
1589
  return this.internals ? this.internals.form : null;
637
1590
  }
1591
+ focus() {
1592
+ this._nativeButton?.focus();
1593
+ }
1594
+ setDescribedBy(element) {
1595
+ const btn = this.shadowRoot?.querySelector('button');
1596
+ if (!btn)
1597
+ return;
1598
+ if ('ariaDescribedByElements' in Element.prototype) {
1599
+ btn.ariaDescribedByElements = element ? [element] : null;
1600
+ }
1601
+ else if (element?.id) {
1602
+ btn?.setAttribute('aria-describedby', element.id);
1603
+ }
1604
+ else {
1605
+ btn?.removeAttribute('aria-describedby');
1606
+ }
1607
+ }
638
1608
  connectedCallback() {
639
1609
  super.connectedCallback?.();
640
1610
  if (this.block) {
@@ -646,19 +1616,42 @@ let ItButton = class ItButton extends BaseComponent {
646
1616
  this.removeEventListener('keydown', this._onKeyDown);
647
1617
  super.disconnectedCallback?.();
648
1618
  }
1619
+ static hasMatchingElement(elements, selector) {
1620
+ return elements.some((element) => element.matches(selector) || element.querySelector(selector) !== null);
1621
+ }
1622
+ firstUpdated(changedProperties) {
1623
+ super.firstUpdated?.(changedProperties);
1624
+ this._updateSlottedStates(Array.from(this.children));
1625
+ }
649
1626
  // Render the UI as a function of component state
650
1627
  render() {
651
- const part = this.composeClass('button', 'focusable', this.variant?.length > 0 ? this.variant : '', this.outline ? 'outline' : '');
1628
+ const classes = this.composeClass('btn', this.className, {
1629
+ [`btn-${this.variant}`]: !!this.variant && !this.outline,
1630
+ [`btn-outline-${this.variant}`]: !!this.variant && this.outline,
1631
+ [`btn-${this.size}`]: !!this.size,
1632
+ disabled: this.disabled,
1633
+ 'btn-icon': this._hasIcon,
1634
+ 'btn-progress': this._hasProgress,
1635
+ 'd-block w-100': this.block,
1636
+ });
1637
+ const part = this.composeClass('button', 'focusable', {
1638
+ [this.variant]: this.variant?.length > 0,
1639
+ outline: this.outline,
1640
+ });
652
1641
  return html `
653
1642
  <button
1643
+ id=${ifDefined(this.id || undefined)}
654
1644
  part="${part}"
655
1645
  type="${this.type}"
656
- class="${this._buttonClasses}"
1646
+ class="${classes}"
657
1647
  @click="${this.type === 'submit' ? this.surfaceSubmitEvent : undefined}"
658
1648
  .value="${ifDefined(this.value ? this.value : undefined)}"
1649
+ aria-disabled="${ifDefined(this.disabled ? this.disabled : undefined)}"
659
1650
  ${setAttributes(this._ariaAttributes)}
1651
+ aria-expanded="${ifDefined(this.expanded !== undefined ? this.expanded : undefined)}"
1652
+ ?inert="${this.itInert}"
660
1653
  >
661
- <slot></slot>
1654
+ <slot @slotchange="${this._onSlotChange}"></slot>
662
1655
  </button>
663
1656
  `;
664
1657
  }
@@ -668,10 +1661,6 @@ __decorate([
668
1661
  query('button'),
669
1662
  __metadata("design:type", HTMLButtonElement)
670
1663
  ], ItButton.prototype, "_nativeButton", void 0);
671
- __decorate([
672
- property({ type: String }),
673
- __metadata("design:type", Object)
674
- ], ItButton.prototype, "_buttonClasses", void 0);
675
1664
  __decorate([
676
1665
  property({ type: String, reflect: true }),
677
1666
  __metadata("design:type", Object)
@@ -692,19 +1681,35 @@ __decorate([
692
1681
  property({ type: Boolean, reflect: true }),
693
1682
  __metadata("design:type", Object)
694
1683
  ], ItButton.prototype, "block", void 0);
695
- __decorate([
696
- property({ type: Boolean, reflect: true }),
697
- __metadata("design:type", Object)
698
- ], ItButton.prototype, "icon", void 0);
699
1684
  __decorate([
700
1685
  property({ type: String }),
701
1686
  __metadata("design:type", Object)
702
1687
  ], ItButton.prototype, "value", void 0);
1688
+ __decorate([
1689
+ property({ type: Boolean, reflect: true, attribute: 'it-inert' }),
1690
+ __metadata("design:type", Object)
1691
+ ], ItButton.prototype, "itInert", void 0);
703
1692
  __decorate([
704
1693
  property(),
705
1694
  __metadata("design:type", Object)
706
1695
  ], ItButton.prototype, "internals", void 0);
707
- ItButton = __decorate([
1696
+ __decorate([
1697
+ property({ type: Boolean, reflect: true }),
1698
+ __metadata("design:type", Boolean)
1699
+ ], ItButton.prototype, "disabled", void 0);
1700
+ __decorate([
1701
+ property({ type: Boolean, reflect: true, attribute: 'it-aria-expanded' }),
1702
+ __metadata("design:type", Boolean)
1703
+ ], ItButton.prototype, "expanded", void 0);
1704
+ __decorate([
1705
+ state(),
1706
+ __metadata("design:type", Object)
1707
+ ], ItButton.prototype, "_hasIcon", void 0);
1708
+ __decorate([
1709
+ state(),
1710
+ __metadata("design:type", Object)
1711
+ ], ItButton.prototype, "_hasProgress", void 0);
1712
+ ItButton = ItButton_1 = __decorate([
708
1713
  customElement('it-button')
709
1714
  ], ItButton);
710
1715