@italia/globals 0.0.1-alpha.0 → 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/custom-elements.json +1665 -143
  2. package/dist/src/base-component/base-component.d.ts +9 -6
  3. package/dist/src/base-component/base-component.d.ts.map +1 -1
  4. package/dist/src/base-component/base-component.js +27 -17
  5. package/dist/src/base-component/base-component.js.map +1 -1
  6. package/dist/src/controllers/aria-keyboard-accordion-controller.d.ts +15 -0
  7. package/dist/src/controllers/aria-keyboard-accordion-controller.d.ts.map +1 -0
  8. package/dist/src/controllers/aria-keyboard-accordion-controller.js +52 -0
  9. package/dist/src/controllers/aria-keyboard-accordion-controller.js.map +1 -0
  10. package/dist/src/controllers/aria-keyboard-list-controller.d.ts +18 -0
  11. package/dist/src/controllers/aria-keyboard-list-controller.d.ts.map +1 -0
  12. package/dist/src/controllers/aria-keyboard-list-controller.js +58 -0
  13. package/dist/src/controllers/aria-keyboard-list-controller.js.map +1 -0
  14. package/dist/src/controllers/collapse-controller.d.ts +12 -0
  15. package/dist/src/controllers/collapse-controller.d.ts.map +1 -0
  16. package/dist/src/controllers/collapse-controller.js +95 -0
  17. package/dist/src/controllers/collapse-controller.js.map +1 -0
  18. package/dist/src/controllers/roving-tabindex-controller.d.ts +85 -0
  19. package/dist/src/controllers/roving-tabindex-controller.d.ts.map +1 -0
  20. package/dist/src/controllers/roving-tabindex-controller.js +200 -0
  21. package/dist/src/controllers/roving-tabindex-controller.js.map +1 -0
  22. package/dist/src/form/form-control.d.ts +60 -0
  23. package/dist/src/form/form-control.d.ts.map +1 -0
  24. package/dist/src/form/form-control.js +251 -0
  25. package/dist/src/form/form-control.js.map +1 -0
  26. package/dist/src/form/form-controller.d.ts +66 -0
  27. package/dist/src/form/form-controller.d.ts.map +1 -0
  28. package/dist/src/form/form-controller.js +364 -0
  29. package/dist/src/form/form-controller.js.map +1 -0
  30. package/dist/src/form/locales/it.d.ts +4 -0
  31. package/dist/src/form/locales/it.d.ts.map +1 -0
  32. package/dist/src/form/locales/it.js +11 -0
  33. package/dist/src/form/locales/it.js.map +1 -0
  34. package/dist/src/index.d.ts +12 -4
  35. package/dist/src/index.d.ts.map +1 -1
  36. package/dist/src/index.js +10 -4
  37. package/dist/src/index.js.map +1 -1
  38. package/dist/src/mixins/validity.d.ts +36 -16
  39. package/dist/src/mixins/validity.d.ts.map +1 -1
  40. package/dist/src/mixins/validity.js +46 -29
  41. package/dist/src/mixins/validity.js.map +1 -1
  42. package/dist/src/stories/formControlReusableStories.d.ts +19 -0
  43. package/dist/src/stories/formControlReusableStories.d.ts.map +1 -0
  44. package/dist/src/stories/formControlReusableStories.js +63 -0
  45. package/dist/src/stories/formControlReusableStories.js.map +1 -0
  46. package/dist/src/window-manager.d.ts +20 -0
  47. package/dist/src/window-manager.d.ts.map +1 -0
  48. package/dist/src/window-manager.js +47 -0
  49. package/dist/src/window-manager.js.map +1 -0
  50. package/package.json +10 -8
  51. package/dist/src/mixins/form.d.ts +0 -363
  52. package/dist/src/mixins/form.d.ts.map +0 -1
  53. package/dist/src/mixins/form.js +0 -36
  54. package/dist/src/mixins/form.js.map +0 -1
@@ -15,10 +15,22 @@ export var VALIDATION_STATUS;
15
15
  * One indicating no validation error.
16
16
  */
17
17
  VALIDATION_STATUS["NO_ERROR"] = "";
18
+ /**
19
+ * One indicating that the value is invalid (generic).
20
+ */
21
+ VALIDATION_STATUS["INVALID"] = "invalid";
18
22
  /**
19
23
  * One indicating missing required value.
20
24
  */
21
25
  VALIDATION_STATUS["ERROR_REQUIRED"] = "required";
26
+ /**
27
+ * One indicating that the value does not match the pattern.
28
+ */
29
+ VALIDATION_STATUS["PATTERN"] = "pattern";
30
+ /**
31
+ * One indicating that the value is shorter than the minimum length.
32
+ */
33
+ VALIDATION_STATUS["MINLENGTH"] = "minlength";
22
34
  })(VALIDATION_STATUS || (VALIDATION_STATUS = {}));
23
35
  /**
24
36
  * @param Base The base class.
@@ -33,46 +45,51 @@ const ValidityMixin = (Base) => {
33
45
  * @returns The form validation error mesasages associated with the given status.
34
46
  * @protected
35
47
  */
36
- _getValidityMessage(state) {
48
+ _getValidityMessage(state, translations) {
37
49
  return {
38
50
  [VALIDATION_STATUS.NO_ERROR]: '',
39
- [VALIDATION_STATUS.ERROR_REQUIRED]: this.requiredValidityMessage,
51
+ [VALIDATION_STATUS.INVALID]: translations.validityInvalid,
52
+ [VALIDATION_STATUS.ERROR_REQUIRED]: translations.validityRequired,
53
+ [VALIDATION_STATUS.PATTERN]: translations.validityPattern,
54
+ [VALIDATION_STATUS.MINLENGTH]: translations.validityMinlength.replace('{minlength}', this.minlength.toString()),
40
55
  }[state];
41
56
  }
42
- // Not using TypeScript `protected` due to: microsoft/TypeScript#17744
43
- // Using `string` instead of `VALIDATION_STATUS` until we can require TypeScript 3.8
44
57
  /**
45
58
  * Checks if the value meets the constraints.
46
59
  *
47
- * @returns `VALIDATION_STATUS.NO_ERROR` if the value meets the constraints. Some other values otherwise.
48
- * @protected
49
- */
50
- _testValidity() {
51
- const { required, value } = this;
52
- return required && !value ? VALIDATION_STATUS.ERROR_REQUIRED : VALIDATION_STATUS.NO_ERROR;
53
- }
54
- /**
55
- * Checks if the value meets the constraints.
56
- * Fires cancelable `invalid` event if it doesn't.
57
- *
58
60
  * @returns `true` if the value meets the constraints. `false` otherwise.
59
61
  */
60
- checkValidity() {
61
- const status = this._testValidity();
62
- if (status !== VALIDATION_STATUS.NO_ERROR) {
63
- if (this.dispatchEvent(new CustomEvent('invalid', {
64
- bubbles: false,
65
- cancelable: true,
66
- composed: false,
67
- }))) {
68
- this.invalid = true;
69
- this.validityMessage = this._getValidityMessage(status);
62
+ _checkValidity(translations, htmlValidity = true) {
63
+ // htmlValidity = this.inputElement.checkValidity(); //check browser validity
64
+ if (this.customValidation) {
65
+ return undefined;
66
+ }
67
+ let validity = htmlValidity;
68
+ let message = validity
69
+ ? this._getValidityMessage(VALIDATION_STATUS.NO_ERROR, translations)
70
+ : this._getValidityMessage(VALIDATION_STATUS.INVALID, translations);
71
+ if (this.required || (this._value && this.pattern)) {
72
+ if (this.pattern) {
73
+ const regex = new RegExp(`^${this.pattern}$`, 'u');
74
+ validity = regex.test(this._value.toString());
75
+ if (!validity) {
76
+ message = this._getValidityMessage(VALIDATION_STATUS.PATTERN, translations);
77
+ }
78
+ }
79
+ if (typeof this.minlength !== 'undefined') {
80
+ validity = validity && this._value.toString().length >= this.minlength;
81
+ if (!validity) {
82
+ message = this._getValidityMessage(VALIDATION_STATUS.MINLENGTH, translations);
83
+ }
84
+ }
85
+ if (this.required && !this._value) {
86
+ validity = false;
87
+ message = this._getValidityMessage(VALIDATION_STATUS.ERROR_REQUIRED, translations);
70
88
  }
71
- return false;
72
89
  }
73
- this.invalid = false;
74
- this.validityMessage = '';
75
- return true;
90
+ this.invalid = !validity;
91
+ this.validityMessage = message;
92
+ return validity;
76
93
  }
77
94
  /**
78
95
  * Sets the given custom validity message.
@@ -1 +1 @@
1
- {"version":3,"file":"validity.js","sourceRoot":"","sources":["../../../src/mixins/validity.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,CAAN,IAAY,iBAUX;AAVD,WAAY,iBAAiB;IAC3B;;OAEG;IACH,kCAAa,CAAA;IAEb;;OAEG;IACH,gDAA2B,CAAA;AAC7B,CAAC,EAVW,iBAAiB,KAAjB,iBAAiB,QAU5B;AAED;;;GAGG;AACH,MAAM,aAAa,GAAG,CAAqC,IAAO,EAAE,EAAE;IACpE,MAAe,iBAAkB,SAAQ,IAAI;QAC3C,sEAAsE;QACtE,oFAAoF;QACpF;;;;WAIG;QACH,mBAAmB,CAAC,KAAa;YAC/B,OAAO;gBACL,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,EAAE;gBAChC,CAAC,iBAAiB,CAAC,cAAc,CAAC,EAAE,IAAI,CAAC,uBAAuB;aACjE,CAAC,KAAK,CAAC,CAAC;QACX,CAAC;QAED,sEAAsE;QACtE,oFAAoF;QACpF;;;;;WAKG;QACH,aAAa;YACX,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;YACjC,OAAO,QAAQ,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC;QAC5F,CAAC;QA2BD;;;;;WAKG;QACH,aAAa;YACX,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YACpC,IAAI,MAAM,KAAK,iBAAiB,CAAC,QAAQ,EAAE,CAAC;gBAC1C,IACE,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,SAAS,EAAE;oBACzB,OAAO,EAAE,KAAK;oBACd,UAAU,EAAE,IAAI;oBAChB,QAAQ,EAAE,KAAK;iBAChB,CAAC,CACH,EACD,CAAC;oBACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;oBACpB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAW,CAAC;gBACpE,CAAC;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC;QACd,CAAC;QAED;;;;WAIG;QACH,iBAAiB,CAAC,eAAuB;YACvC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;YACxC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACzC,CAAC;KACF;IACD,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { Constructor } from '../index.js';\n/**\n * @license\n *\n * Copyright IBM Corp. 2020, 2022\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n/**\n * Form validation status.\n */\nexport enum VALIDATION_STATUS {\n /**\n * One indicating no validation error.\n */\n NO_ERROR = '',\n\n /**\n * One indicating missing required value.\n */\n ERROR_REQUIRED = 'required',\n}\n\n/**\n * @param Base The base class.\n * @returns A mix-in implementing `.setCustomValidity()` method.\n */\nconst ValidityMixin = <T extends Constructor<HTMLElement>>(Base: T) => {\n abstract class ValidityMixinImpl extends Base {\n // Not using TypeScript `protected` due to: microsoft/TypeScript#17744\n // Using `string` instead of `VALIDATION_STATUS` until we can require TypeScript 3.8\n /**\n * @param state The form validation status.\n * @returns The form validation error mesasages associated with the given status.\n * @protected\n */\n _getValidityMessage(state: string) {\n return {\n [VALIDATION_STATUS.NO_ERROR]: '',\n [VALIDATION_STATUS.ERROR_REQUIRED]: this.requiredValidityMessage,\n }[state];\n }\n\n // Not using TypeScript `protected` due to: microsoft/TypeScript#17744\n // Using `string` instead of `VALIDATION_STATUS` until we can require TypeScript 3.8\n /**\n * Checks if the value meets the constraints.\n *\n * @returns `VALIDATION_STATUS.NO_ERROR` if the value meets the constraints. Some other values otherwise.\n * @protected\n */\n _testValidity(): string {\n const { required, value } = this;\n return required && !value ? VALIDATION_STATUS.ERROR_REQUIRED : VALIDATION_STATUS.NO_ERROR;\n }\n\n /**\n * `true` to show the UI of the invalid state.\n */\n abstract invalid: boolean;\n\n /**\n * `true` if the value is required.\n */\n abstract required: boolean;\n\n /**\n * The special validity message for `required`.\n */\n abstract requiredValidityMessage: string;\n\n /**\n * The validity message.\n */\n abstract validityMessage: string;\n\n /**\n * The value.\n */\n abstract value: string;\n\n /**\n * Checks if the value meets the constraints.\n * Fires cancelable `invalid` event if it doesn't.\n *\n * @returns `true` if the value meets the constraints. `false` otherwise.\n */\n checkValidity() {\n const status = this._testValidity();\n if (status !== VALIDATION_STATUS.NO_ERROR) {\n if (\n this.dispatchEvent(\n new CustomEvent('invalid', {\n bubbles: false,\n cancelable: true,\n composed: false,\n }),\n )\n ) {\n this.invalid = true;\n this.validityMessage = this._getValidityMessage(status) as string;\n }\n return false;\n }\n this.invalid = false;\n this.validityMessage = '';\n return true;\n }\n\n /**\n * Sets the given custom validity message.\n *\n * @param validityMessage The custom validity message\n */\n setCustomValidity(validityMessage: string) {\n this.invalid = Boolean(validityMessage);\n this.validityMessage = validityMessage;\n }\n }\n return ValidityMixinImpl;\n};\n\nexport default ValidityMixin;\n"]}
1
+ {"version":3,"file":"validity.js","sourceRoot":"","sources":["../../../src/mixins/validity.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,CAAN,IAAY,iBAwBX;AAxBD,WAAY,iBAAiB;IAC3B;;OAEG;IACH,kCAAa,CAAA;IAEb;;OAEG;IACH,wCAAmB,CAAA;IAEnB;;OAEG;IACH,gDAA2B,CAAA;IAC3B;;OAEG;IACH,wCAAmB,CAAA;IAEnB;;OAEG;IACH,4CAAuB,CAAA;AACzB,CAAC,EAxBW,iBAAiB,KAAjB,iBAAiB,QAwB5B;AAED;;;GAGG;AACH,MAAM,aAAa,GAAG,CAAqC,IAAO,EAAE,EAAE;IACpE,MAAe,iBAAkB,SAAQ,IAAI;QAC3C,sEAAsE;QACtE,oFAAoF;QACpF;;;;WAIG;QACH,mBAAmB,CAAC,KAAa,EAAE,YAAoC;YACrE,OAAO;gBACL,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,EAAE;gBAChC,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC,eAAe;gBACzD,CAAC,iBAAiB,CAAC,cAAc,CAAC,EAAE,YAAY,CAAC,gBAAgB;gBACjE,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC,eAAe;gBACzD,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE,YAAY,CAAC,iBAAiB,CAAC,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;aAChH,CAAC,KAAK,CAAC,CAAC;QACX,CAAC;QA+CD;;;;WAIG;QACH,cAAc,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AI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;oBAClC,QAAQ,GAAG,KAAK,CAAC;oBACjB,OAAO,GAAG,IAAI,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,cAAc,EAAE,YAAY,CAAW,CAAC;gBAC/F,CAAC;YACH,CAAC;YAED,IAAI,CAAC,OAAO,GAAG,CAAC,QAAQ,CAAC;YACzB,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC;YAC/B,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED;;;;WAIG;QACH,iBAAiB,CAAC,eAAuB;YACvC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;YACxC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACzC,CAAC;KACF;IACD,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { Constructor } from '../index.js';\n/**\n * @license\n *\n * Copyright IBM Corp. 2020, 2022\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n/**\n * Form validation status.\n */\nexport enum VALIDATION_STATUS {\n /**\n * One indicating no validation error.\n */\n NO_ERROR = '',\n\n /**\n * One indicating that the value is invalid (generic).\n */\n INVALID = 'invalid',\n\n /**\n * One indicating missing required value.\n */\n ERROR_REQUIRED = 'required',\n /**\n * One indicating that the value does not match the pattern.\n */\n PATTERN = 'pattern',\n\n /**\n * One indicating that the value is shorter than the minimum length.\n */\n MINLENGTH = 'minlength',\n}\n\n/**\n * @param Base The base class.\n * @returns A mix-in implementing `.setCustomValidity()` method.\n */\nconst ValidityMixin = <T extends Constructor<HTMLElement>>(Base: T) => {\n abstract class ValidityMixinImpl extends Base {\n // Not using TypeScript `protected` due to: microsoft/TypeScript#17744\n // Using `string` instead of `VALIDATION_STATUS` until we can require TypeScript 3.8\n /**\n * @param state The form validation status.\n * @returns The form validation error mesasages associated with the given status.\n * @protected\n */\n _getValidityMessage(state: string, translations: Record<string, string>) {\n return {\n [VALIDATION_STATUS.NO_ERROR]: '',\n [VALIDATION_STATUS.INVALID]: translations.validityInvalid,\n [VALIDATION_STATUS.ERROR_REQUIRED]: translations.validityRequired,\n [VALIDATION_STATUS.PATTERN]: translations.validityPattern,\n [VALIDATION_STATUS.MINLENGTH]: translations.validityMinlength.replace('{minlength}', this.minlength.toString()),\n }[state];\n }\n\n /**\n * `true` to show the UI of the invalid state.\n */\n abstract invalid: boolean;\n\n /**\n * `true` if the value is required.\n */\n abstract required: boolean;\n\n /**\n * The validity message.\n */\n abstract validityMessage: string;\n\n /**\n * The value.\n */\n abstract _value: string;\n\n /**\n * The pattern to match to be valid.\n */\n abstract pattern?: string;\n\n /**\n * `true` if the element is disabled.\n */\n abstract disabled: boolean;\n\n /**\n * The minimum length of the value.\n */\n abstract minlength: number;\n\n /**\n * The maximum length of the value.\n */\n abstract maxlength: number;\n\n /**\n * External validation.\n */\n abstract customValidation: boolean;\n\n /**\n * Checks if the value meets the constraints.\n *\n * @returns `true` if the value meets the constraints. `false` otherwise.\n */\n _checkValidity(translations: Record<string, string>, htmlValidity: boolean = true): boolean | undefined {\n // htmlValidity = this.inputElement.checkValidity(); //check browser validity\n if (this.customValidation) {\n return undefined;\n }\n let validity = htmlValidity;\n let message: string = validity\n ? (this._getValidityMessage(VALIDATION_STATUS.NO_ERROR, translations) as string)\n : (this._getValidityMessage(VALIDATION_STATUS.INVALID, translations) as string);\n\n if (this.required || (this._value && this.pattern)) {\n if (this.pattern) {\n const regex = new RegExp(`^${this.pattern}$`, 'u');\n validity = regex.test(this._value.toString());\n if (!validity) {\n message = this._getValidityMessage(VALIDATION_STATUS.PATTERN, translations) as string;\n }\n }\n if (typeof this.minlength !== 'undefined') {\n validity = validity && this._value.toString().length >= this.minlength;\n if (!validity) {\n message = this._getValidityMessage(VALIDATION_STATUS.MINLENGTH, translations) as string;\n }\n }\n if (this.required && !this._value) {\n validity = false;\n message = this._getValidityMessage(VALIDATION_STATUS.ERROR_REQUIRED, translations) as string;\n }\n }\n\n this.invalid = !validity;\n this.validityMessage = message;\n return validity;\n }\n\n /**\n * Sets the given custom validity message.\n *\n * @param validityMessage The custom validity message\n */\n setCustomValidity(validityMessage: string) {\n this.invalid = Boolean(validityMessage);\n this.validityMessage = validityMessage;\n }\n }\n return ValidityMixinImpl;\n};\n\nexport default ValidityMixin;\n"]}
@@ -0,0 +1,19 @@
1
+ export declare const StoryFormControlMethodAndProps: ({ otherProps, otherMethods, otherEvents, componentName, }: {
2
+ otherProps?: string | undefined;
3
+ otherMethods?: string | undefined;
4
+ otherEvents?: string | undefined;
5
+ componentName?: string | undefined;
6
+ }) => {
7
+ name: string;
8
+ tags: string[];
9
+ render: () => import("lit").TemplateResult<1>;
10
+ parameters: {
11
+ viewMode: string;
12
+ docs: {
13
+ description: {
14
+ story: string;
15
+ };
16
+ };
17
+ };
18
+ };
19
+ //# sourceMappingURL=formControlReusableStories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formControlReusableStories.d.ts","sourceRoot":"","sources":["../../../src/stories/formControlReusableStories.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,8BAA8B,GAAI;;;;;CAK9C;;;;;;;;;;;;CA2DA,CAAC"}
@@ -0,0 +1,63 @@
1
+ /* eslint-disable arrow-body-style */
2
+ import { html } from 'lit';
3
+ export const StoryFormControlMethodAndProps = ({ otherProps = '', otherMethods = '', otherEvents = '', componentName = 'it-input', }) => {
4
+ return {
5
+ name: 'Proprietà, Metodi, ed Eventi accessibili via js',
6
+ tags: ['!dev'],
7
+ render: () => html `<div class="hide-preview"></div>`,
8
+ parameters: {
9
+ viewMode: 'docs', // assicura che si apra la tab Docs anziché Canvas
10
+ docs: {
11
+ description: {
12
+ story: `Il componente espone delle proprietà, dei metodi e degli eventi, utili per eventuali interazioni via js.
13
+
14
+ \`\`\`html
15
+ <${componentName} ... id="myinput"></${componentName}>
16
+ \`\`\`
17
+
18
+ \`\`\`js
19
+ const myInput = document.getElementById("myInput");
20
+ const validity = myInput.validity;
21
+ const validationMessage = myInput.validationMessage;
22
+
23
+ const form = myInput.getForm();
24
+ myInput.checkValidity();
25
+ myInput.reportValidity();
26
+ myInput.setCustomValidity("Messaggio di errore");
27
+ \`\`\`
28
+
29
+ <br/>
30
+ <h4>Proprietà accessibili dall'esterno</h4>
31
+ | Nome | Descrizione |
32
+ |------|-------------|
33
+ |\`validity\`| Ritorna l'oggetto di validazione effettuata dal browser.|
34
+ |\`validationMessage\`| Ritorna il messaggio di errore in caso di validazione fallita.|
35
+ ${otherProps}
36
+
37
+ <h4>Metodi</h4>
38
+ | Nome | Descrizione | Argomenti |
39
+ |------|-------------|-----------|
40
+ |\`getForm()\`| Ritorna l'elemento del DOM corrispondente alla form di riferimento dell'input. | - |
41
+ |\`checkValidity()\`| Triggera la validazione nativa del browser sul campo, e restituisce true o false a seconda che l'input sia valido o meno. | - |
42
+ |\`reportValidity()\`| Controlla se l'elemento è valido secondo le regole di validazione del browser. Se non è valido, mostra un messaggio di errore (tooltip nativo del browser) e restituisce \`false\`. Se è valido, restituisce \`true\`. | - |
43
+ |\`setCustomValidity('')\`| Permette di impostare un messaggio di errore personalizzato passato come parametro. Se il messaggio non è vuoto, rende invalido l'elemento. Se invece il messaggio è vuoto (''), rende valido l'elemento. | message: String |
44
+ ${otherMethods}
45
+
46
+
47
+ <h4>Eventi</h4>
48
+ | Nome | Descrizione |
49
+ |------|-------------|
50
+ |\`it-input-ready\`| Quando il componente è montato e l'elemento input interno è pronto. |
51
+ |\`it-input\`| Ogni volta che il valore di input cambia per interazione da parte dell'utente |
52
+ |\`it-blur\`| Quando l'input perde il focus (blur) |
53
+ |\`it-focus\`| Quando l'input riceve il focus (focus) |
54
+ |\`it-click\`| Quando l'utente fa click sull'input |
55
+ |\`it-change\`| Quando il valore dell’input viene modificato e il browser emette \`change\` |
56
+ |\`invalid\`| Emesso dal browser quando la validazione fallisce.|
57
+ ${otherEvents}`,
58
+ },
59
+ },
60
+ },
61
+ };
62
+ };
63
+ //# sourceMappingURL=formControlReusableStories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formControlReusableStories.js","sourceRoot":"","sources":["../../../src/stories/formControlReusableStories.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAE3B,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,EAC7C,UAAU,GAAG,EAAE,EACf,YAAY,GAAG,EAAE,EACjB,WAAW,GAAG,EAAE,EAChB,aAAa,GAAG,UAAU,GAC3B,EAAE,EAAE;IACH,OAAO;QACL,IAAI,EAAE,iDAAiD;QACvD,IAAI,EAAE,CAAC,MAAM,CAAC;QACd,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAA,kCAAkC;QACpD,UAAU,EAAE;YACV,QAAQ,EAAE,MAAM,EAAE,kDAAkD;YACpE,IAAI,EAAE;gBACJ,WAAW,EAAE;oBACX,KAAK,EAAE;;;GAGd,aAAa,uBAAuB,aAAa;;;;;;;;;;;;;;;;;;;;EAoBlD,UAAU;;;;;;;;;EASV,YAAY;;;;;;;;;;;;;EAaZ,WAAW,EAAE;iBACN;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable arrow-body-style */\nimport { html } from 'lit';\n\nexport const StoryFormControlMethodAndProps = ({\n otherProps = '',\n otherMethods = '',\n otherEvents = '',\n componentName = 'it-input',\n}) => {\n return {\n name: 'Proprietà, Metodi, ed Eventi accessibili via js',\n tags: ['!dev'],\n render: () => html`<div class=\"hide-preview\"></div>`,\n parameters: {\n viewMode: 'docs', // assicura che si apra la tab Docs anziché Canvas\n docs: {\n description: {\n story: `Il componente espone delle proprietà, dei metodi e degli eventi, utili per eventuali interazioni via js.\n\n\\`\\`\\`html\n<${componentName} ... id=\"myinput\"></${componentName}>\n\\`\\`\\`\n\n\\`\\`\\`js\nconst myInput = document.getElementById(\"myInput\");\nconst validity = myInput.validity;\nconst validationMessage = myInput.validationMessage;\n\nconst form = myInput.getForm();\nmyInput.checkValidity();\nmyInput.reportValidity();\nmyInput.setCustomValidity(\"Messaggio di errore\");\n\\`\\`\\`\n\n<br/>\n<h4>Proprietà accessibili dall'esterno</h4>\n| Nome | Descrizione |\n|------|-------------|\n|\\`validity\\`| Ritorna l'oggetto di validazione effettuata dal browser.|\n|\\`validationMessage\\`| Ritorna il messaggio di errore in caso di validazione fallita.|\n${otherProps}\n\n<h4>Metodi</h4>\n| Nome | Descrizione | Argomenti |\n|------|-------------|-----------|\n|\\`getForm()\\`| Ritorna l'elemento del DOM corrispondente alla form di riferimento dell'input. | - |\n|\\`checkValidity()\\`| Triggera la validazione nativa del browser sul campo, e restituisce true o false a seconda che l'input sia valido o meno. | - |\n|\\`reportValidity()\\`| Controlla se l'elemento è valido secondo le regole di validazione del browser. Se non è valido, mostra un messaggio di errore (tooltip nativo del browser) e restituisce \\`false\\`. Se è valido, restituisce \\`true\\`. | - |\n|\\`setCustomValidity('')\\`| Permette di impostare un messaggio di errore personalizzato passato come parametro. Se il messaggio non è vuoto, rende invalido l'elemento. Se invece il messaggio è vuoto (''), rende valido l'elemento. | message: String |\n${otherMethods}\n\n\n<h4>Eventi</h4>\n| Nome | Descrizione |\n|------|-------------|\n|\\`it-input-ready\\`| Quando il componente è montato e l'elemento input interno è pronto. |\n|\\`it-input\\`| Ogni volta che il valore di input cambia per interazione da parte dell'utente |\n|\\`it-blur\\`| Quando l'input perde il focus (blur) |\n|\\`it-focus\\`| Quando l'input riceve il focus (focus) |\n|\\`it-click\\`| Quando l'utente fa click sull'input |\n|\\`it-change\\`| Quando il valore dell’input viene modificato e il browser emette \\`change\\` |\n|\\`invalid\\`| Emesso dal browser quando la validazione fallisce.|\n${otherEvents}`,\n },\n },\n },\n };\n};\n"]}
@@ -0,0 +1,20 @@
1
+ export type ScrollState = {
2
+ scrollY: number;
3
+ width: number;
4
+ height: number;
5
+ };
6
+ export type ScrollCallback = (state: ScrollState, forceRecalc?: boolean) => void;
7
+ export declare class WindowManager {
8
+ private static initialized;
9
+ private static subscribers;
10
+ private static lastScrollY;
11
+ private static lastWidth;
12
+ private static lastHeight;
13
+ private static ticking;
14
+ static init(): void;
15
+ private static requestTick;
16
+ private static tick;
17
+ static subscribe(cb: ScrollCallback): void;
18
+ static unsubscribe(cb: ScrollCallback): void;
19
+ }
20
+ //# sourceMappingURL=window-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"window-manager.d.ts","sourceRoot":"","sources":["../../src/window-manager.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC7E,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,WAAW,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;AAEjF,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,WAAW,CAAS;IAEnC,OAAO,CAAC,MAAM,CAAC,WAAW,CAA6B;IAEvD,OAAO,CAAC,MAAM,CAAC,WAAW,CAAK;IAE/B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAK;IAE7B,OAAO,CAAC,MAAM,CAAC,UAAU,CAAK;IAE9B,OAAO,CAAC,MAAM,CAAC,OAAO,CAAS;IAE/B,MAAM,CAAC,IAAI;IAqBX,OAAO,CAAC,MAAM,CAAC,WAAW;IAO1B,OAAO,CAAC,MAAM,CAAC,IAAI;IAUnB,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,cAAc;IAInC,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,cAAc;CAGtC"}
@@ -0,0 +1,47 @@
1
+ export class WindowManager {
2
+ static init() {
3
+ if (this.initialized)
4
+ return;
5
+ this.lastScrollY = window.scrollY;
6
+ this.lastWidth = window.innerWidth;
7
+ this.lastHeight = window.innerHeight;
8
+ window.addEventListener('scroll', () => {
9
+ this.lastScrollY = window.scrollY;
10
+ this.requestTick();
11
+ });
12
+ window.addEventListener('resize', () => {
13
+ this.lastWidth = window.innerWidth;
14
+ this.lastHeight = window.innerHeight;
15
+ this.requestTick(true); // force recalculation
16
+ });
17
+ this.initialized = true;
18
+ }
19
+ static requestTick(forceRecalc = false) {
20
+ if (!this.ticking) {
21
+ requestAnimationFrame(() => this.tick(forceRecalc));
22
+ this.ticking = true;
23
+ }
24
+ }
25
+ static tick(forceRecalc) {
26
+ this.ticking = false;
27
+ const state = {
28
+ scrollY: this.lastScrollY,
29
+ width: this.lastWidth,
30
+ height: this.lastHeight,
31
+ };
32
+ this.subscribers.forEach((cb) => cb(state, forceRecalc));
33
+ }
34
+ static subscribe(cb) {
35
+ this.subscribers.add(cb);
36
+ }
37
+ static unsubscribe(cb) {
38
+ this.subscribers.delete(cb);
39
+ }
40
+ }
41
+ WindowManager.initialized = false;
42
+ WindowManager.subscribers = new Set();
43
+ WindowManager.lastScrollY = 0;
44
+ WindowManager.lastWidth = 0;
45
+ WindowManager.lastHeight = 0;
46
+ WindowManager.ticking = false;
47
+ //# sourceMappingURL=window-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"window-manager.js","sourceRoot":"","sources":["../../src/window-manager.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,aAAa;IAaxB,MAAM,CAAC,IAAI;QACT,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO;QAE7B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC;QAErC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE;YACrC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC;YAClC,IAAI,CAAC,WAAW,EAAE,CAAC;QACrB,CAAC,CAA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W,GAAG,CAAC,CAAC;AAEhB,uBAAS,GAAG,CAAC,CAAC;AAEd,wBAAU,GAAG,CAAC,CAAC;AAEf,qBAAO,GAAG,KAAK,CAAC","sourcesContent":["export type ScrollState = { scrollY: number; width: number; height: number };\nexport type ScrollCallback = (state: ScrollState, forceRecalc?: boolean) => void;\n\nexport class WindowManager {\n private static initialized = false;\n\n private static subscribers = new Set<ScrollCallback>();\n\n private static lastScrollY = 0;\n\n private static lastWidth = 0;\n\n private static lastHeight = 0;\n\n private static ticking = false;\n\n static init() {\n if (this.initialized) return;\n\n this.lastScrollY = window.scrollY;\n this.lastWidth = window.innerWidth;\n this.lastHeight = window.innerHeight;\n\n window.addEventListener('scroll', () => {\n this.lastScrollY = window.scrollY;\n this.requestTick();\n });\n\n window.addEventListener('resize', () => {\n this.lastWidth = window.innerWidth;\n this.lastHeight = window.innerHeight;\n this.requestTick(true); // force recalculation\n });\n\n this.initialized = true;\n }\n\n private static requestTick(forceRecalc = false) {\n if (!this.ticking) {\n requestAnimationFrame(() => this.tick(forceRecalc));\n this.ticking = true;\n }\n }\n\n private static tick(forceRecalc: boolean) {\n this.ticking = false;\n const state: ScrollState = {\n scrollY: this.lastScrollY,\n width: this.lastWidth,\n height: this.lastHeight,\n };\n this.subscribers.forEach((cb) => cb(state, forceRecalc));\n }\n\n static subscribe(cb: ScrollCallback) {\n this.subscribers.add(cb);\n }\n\n static unsubscribe(cb: ScrollCallback) {\n this.subscribers.delete(cb);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@italia/globals",
3
3
  "description": "Utilities per i Web components del Design System .italia",
4
- "version": "0.0.1-alpha.0",
4
+ "version": "0.1.0-alpha.2",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "license": "BSD-3-Clause",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/italia/design-web-components.git",
11
+ "url": "https://github.com/italia/dev-kit-italia.git",
12
12
  "directory": "packages/button"
13
13
  },
14
14
  "author": "Presidenza del Consiglio dei Ministri",
15
- "homepage": "https://italia.github.io/design-web-components",
15
+ "homepage": "https://italia.github.io/dev-kit-italia",
16
16
  "bugs": {
17
- "url": "https://github.com/italia/design-web-components/issues"
17
+ "url": "https://github.com/italia/dev-kit-italia/issues"
18
18
  },
19
19
  "type": "module",
20
20
  "main": "./dist/src/index.js",
@@ -32,8 +32,10 @@
32
32
  "custom-elements.json"
33
33
  ],
34
34
  "dependencies": {
35
+ "@floating-ui/dom": "^1.7.1",
36
+ "clsx": "^2.1.1",
35
37
  "lit": "^3.3.0",
36
- "@italia/i18n": "^0.0.1-alpha.0"
38
+ "@italia/i18n": "^0.1.0-alpha.2"
37
39
  },
38
40
  "devDependencies": {
39
41
  "@custom-elements-manifest/analyzer": "^0.10.3",
@@ -50,9 +52,9 @@
50
52
  "scripts": {
51
53
  "analyze": "cem analyze --litelement --exclude dist",
52
54
  "build": "tsc --build tsconfig.build.json",
53
- "clean": "rimraf node_modules .turbo",
55
+ "clean": "rimraf node_modules .turbo dist",
56
+ "prepublish": "pnpm build",
54
57
  "lint": "eslint --ext .ts \"src/**/*.ts\" && prettier \"src/**/*.ts\" --check",
55
- "format": "eslint --ext .ts \"src/**/*.ts\" --fix && prettier \"src/**/*.ts\" --write",
56
- "test-disabled": "wtr --coverage --node-resolve --config web-test-runner.config.js"
58
+ "format": "eslint --ext .ts \"src/**/*.ts\" --fix && prettier \"src/**/*.ts\" --write"
57
59
  }
58
60
  }