@italia/globals 0.1.0-alpha.2 → 1.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom-elements.json +66 -8
- package/dist/src/base-component/base-component.d.ts +19 -7
- package/dist/src/base-component/base-component.d.ts.map +1 -1
- package/dist/src/form/form-control.d.ts +2 -1
- package/dist/src/form/form-control.d.ts.map +1 -1
- package/dist/src/form/form-control.js +15 -7
- package/dist/src/form/form-control.js.map +1 -1
- package/dist/src/form/form-controller.d.ts +2 -0
- package/dist/src/form/form-controller.d.ts.map +1 -1
- package/dist/src/form/form-controller.js +35 -1
- package/dist/src/form/form-controller.js.map +1 -1
- package/dist/src/form/locales/it.d.ts.map +1 -1
- package/dist/src/form/locales/it.js +1 -0
- package/dist/src/form/locales/it.js.map +1 -1
- package/dist/src/index.d.ts +9 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/mixins/validity.d.ts +18 -6
- package/dist/src/mixins/validity.d.ts.map +1 -1
- package/dist/src/stories/formControlReusableStories.d.ts.map +1 -1
- package/dist/src/stories/formControlReusableStories.js +2 -1
- package/dist/src/stories/formControlReusableStories.js.map +1 -1
- package/dist/src/stories/reusableUsageGuidelinesStories.d.ts +13 -0
- package/dist/src/stories/reusableUsageGuidelinesStories.d.ts.map +1 -0
- package/dist/src/stories/reusableUsageGuidelinesStories.js +39 -0
- package/dist/src/stories/reusableUsageGuidelinesStories.js.map +1 -0
- package/package.json +2 -2
package/custom-elements.json
CHANGED
|
@@ -182,6 +182,14 @@
|
|
|
182
182
|
"name": "StoryFormControlMethodAndProps",
|
|
183
183
|
"module": "src/index.ts"
|
|
184
184
|
}
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"kind": "js",
|
|
188
|
+
"name": "CollapsibleOrHiddenContentGuidelines",
|
|
189
|
+
"declaration": {
|
|
190
|
+
"name": "CollapsibleOrHiddenContentGuidelines",
|
|
191
|
+
"module": "src/index.ts"
|
|
192
|
+
}
|
|
185
193
|
}
|
|
186
194
|
]
|
|
187
195
|
},
|
|
@@ -1125,6 +1133,16 @@
|
|
|
1125
1133
|
"attribute": "required",
|
|
1126
1134
|
"reflects": true
|
|
1127
1135
|
},
|
|
1136
|
+
{
|
|
1137
|
+
"kind": "field",
|
|
1138
|
+
"name": "isInGroup",
|
|
1139
|
+
"type": {
|
|
1140
|
+
"text": "boolean"
|
|
1141
|
+
},
|
|
1142
|
+
"privacy": "protected",
|
|
1143
|
+
"default": "false",
|
|
1144
|
+
"attribute": "isInGroup"
|
|
1145
|
+
},
|
|
1128
1146
|
{
|
|
1129
1147
|
"kind": "field",
|
|
1130
1148
|
"name": "validity",
|
|
@@ -1146,24 +1164,24 @@
|
|
|
1146
1164
|
},
|
|
1147
1165
|
{
|
|
1148
1166
|
"kind": "method",
|
|
1149
|
-
"name": "
|
|
1167
|
+
"name": "getForm",
|
|
1150
1168
|
"privacy": "public",
|
|
1151
1169
|
"return": {
|
|
1152
1170
|
"type": {
|
|
1153
|
-
"text": "
|
|
1171
|
+
"text": "HTMLFormElement | null"
|
|
1154
1172
|
}
|
|
1155
|
-
}
|
|
1173
|
+
},
|
|
1174
|
+
"description": "Gets the associated form, if one exists."
|
|
1156
1175
|
},
|
|
1157
1176
|
{
|
|
1158
1177
|
"kind": "method",
|
|
1159
|
-
"name": "
|
|
1178
|
+
"name": "checkValidity",
|
|
1160
1179
|
"privacy": "public",
|
|
1161
1180
|
"return": {
|
|
1162
1181
|
"type": {
|
|
1163
|
-
"text": "
|
|
1182
|
+
"text": "boolean"
|
|
1164
1183
|
}
|
|
1165
|
-
}
|
|
1166
|
-
"description": "Gets the associated form, if one exists."
|
|
1184
|
+
}
|
|
1167
1185
|
},
|
|
1168
1186
|
{
|
|
1169
1187
|
"kind": "method",
|
|
@@ -1426,6 +1444,14 @@
|
|
|
1426
1444
|
"default": "false",
|
|
1427
1445
|
"description": "If the input is required.",
|
|
1428
1446
|
"fieldName": "required"
|
|
1447
|
+
},
|
|
1448
|
+
{
|
|
1449
|
+
"name": "isInGroup",
|
|
1450
|
+
"type": {
|
|
1451
|
+
"text": "boolean"
|
|
1452
|
+
},
|
|
1453
|
+
"default": "false",
|
|
1454
|
+
"fieldName": "isInGroup"
|
|
1429
1455
|
}
|
|
1430
1456
|
],
|
|
1431
1457
|
"superclass": {
|
|
@@ -1484,6 +1510,14 @@
|
|
|
1484
1510
|
},
|
|
1485
1511
|
"default": "{ form: (input) => { // If there's a form attribute, use it to find the target form by id // Controls may not always reflect the 'form' property. For example, `<it-button>` doesn't reflect. const formId = input.form; if (formId) { const root = input.getRootNode() as Document | ShadowRoot | HTMLElement; const form = root.querySelector(`#${formId}`); if (form) { return form as HTMLFormElement; } } return input.closest('form'); }, name: (input) => input.name, value: (input) => input.value, disabled: (input) => input.disabled ?? false, reportValidity: (input: FormControl) => typeof input.reportValidity === 'function' ? input.reportValidity() : true, checkValidity: (input: FormControl) => (typeof input.checkValidity === 'function' ? input.checkValidity() : true), setValue: (input, value) => { // eslint-disable-next-line no-param-reassign input.value = value as string; }, assumeInteractionOn: ['it-input'], ...options, }"
|
|
1486
1512
|
},
|
|
1513
|
+
{
|
|
1514
|
+
"kind": "field",
|
|
1515
|
+
"name": "submittedOnce",
|
|
1516
|
+
"type": {
|
|
1517
|
+
"text": "boolean"
|
|
1518
|
+
},
|
|
1519
|
+
"default": "false"
|
|
1520
|
+
},
|
|
1487
1521
|
{
|
|
1488
1522
|
"kind": "method",
|
|
1489
1523
|
"name": "hostConnected"
|
|
@@ -1630,6 +1664,10 @@
|
|
|
1630
1664
|
],
|
|
1631
1665
|
"description": "Synchronously sets the form control's validity. Call this when you know the future validity but need to update\nthe host element immediately, i.e. before Lit updates the component in the next update."
|
|
1632
1666
|
},
|
|
1667
|
+
{
|
|
1668
|
+
"kind": "method",
|
|
1669
|
+
"name": "userInteracted"
|
|
1670
|
+
},
|
|
1633
1671
|
{
|
|
1634
1672
|
"kind": "method",
|
|
1635
1673
|
"name": "updateValidity",
|
|
@@ -1864,6 +1902,26 @@
|
|
|
1864
1902
|
}
|
|
1865
1903
|
]
|
|
1866
1904
|
},
|
|
1905
|
+
{
|
|
1906
|
+
"kind": "javascript-module",
|
|
1907
|
+
"path": "src/stories/reusableUsageGuidelinesStories.ts",
|
|
1908
|
+
"declarations": [
|
|
1909
|
+
{
|
|
1910
|
+
"kind": "function",
|
|
1911
|
+
"name": "CollapsibleOrHiddenContentGuidelines"
|
|
1912
|
+
}
|
|
1913
|
+
],
|
|
1914
|
+
"exports": [
|
|
1915
|
+
{
|
|
1916
|
+
"kind": "js",
|
|
1917
|
+
"name": "CollapsibleOrHiddenContentGuidelines",
|
|
1918
|
+
"declaration": {
|
|
1919
|
+
"name": "CollapsibleOrHiddenContentGuidelines",
|
|
1920
|
+
"module": "src/stories/reusableUsageGuidelinesStories.ts"
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
]
|
|
1924
|
+
},
|
|
1867
1925
|
{
|
|
1868
1926
|
"kind": "javascript-module",
|
|
1869
1927
|
"path": "src/utils/cookies.ts",
|
|
@@ -2070,7 +2128,7 @@
|
|
|
2070
2128
|
"type": {
|
|
2071
2129
|
"text": "DefaultTranslation"
|
|
2072
2130
|
},
|
|
2073
|
-
"default": "{ $code: 'it', $name: 'Italiano', $dir: 'ltr', validityRequired: 'Questo campo è obbligatorio.', validityPattern: 'Il valore non corrisponde al formato richiesto.', validityMinlength: 'Il valore deve essere lungo almeno {minlength} caratteri.', validityMaxlength: 'Il valore deve essere lungo al massimo {maxlength} caratteri.', }"
|
|
2131
|
+
"default": "{ $code: 'it', $name: 'Italiano', $dir: 'ltr', validityRequired: 'Questo campo è obbligatorio.', validityGroupRequired: \"Scegli almeno un'opzione\", validityPattern: 'Il valore non corrisponde al formato richiesto.', validityMinlength: 'Il valore deve essere lungo almeno {minlength} caratteri.', validityMaxlength: 'Il valore deve essere lungo al massimo {maxlength} caratteri.', }"
|
|
2074
2132
|
}
|
|
2075
2133
|
],
|
|
2076
2134
|
"exports": [
|
|
@@ -26,7 +26,7 @@ export declare class BaseComponent extends LitElement {
|
|
|
26
26
|
}
|
|
27
27
|
export declare const BaseLocalizedComponent: (new (...args: any[]) => {
|
|
28
28
|
localize: import("@italia/i18n").LocalizeController;
|
|
29
|
-
|
|
29
|
+
get $localize(): import("@italia/i18n").LocalizeController<import("@italia/i18n").DefaultTranslation>;
|
|
30
30
|
$t(t: string): string;
|
|
31
31
|
$d(d: Date | string, p: Intl.DateTimeFormatOptions): string;
|
|
32
32
|
$n(d: number, p: Intl.NumberFormatOptions): string;
|
|
@@ -37,6 +37,7 @@ export declare const BaseLocalizedComponent: (new (...args: any[]) => {
|
|
|
37
37
|
accessKey: string;
|
|
38
38
|
readonly accessKeyLabel: string;
|
|
39
39
|
autocapitalize: string;
|
|
40
|
+
autocorrect: boolean;
|
|
40
41
|
dir: string;
|
|
41
42
|
draggable: boolean;
|
|
42
43
|
hidden: boolean;
|
|
@@ -144,6 +145,8 @@ export declare const BaseLocalizedComponent: (new (...args: any[]) => {
|
|
|
144
145
|
setPointerCapture(pointerId: number): void;
|
|
145
146
|
toggleAttribute(qualifiedName: string, force?: boolean): boolean;
|
|
146
147
|
webkitMatchesSelector(selectors: string): boolean;
|
|
148
|
+
get textContent(): string;
|
|
149
|
+
set textContent(value: string | null): any;
|
|
147
150
|
readonly baseURI: string;
|
|
148
151
|
readonly childNodes: NodeListOf<ChildNode>;
|
|
149
152
|
readonly firstChild: ChildNode | null;
|
|
@@ -156,7 +159,6 @@ export declare const BaseLocalizedComponent: (new (...args: any[]) => {
|
|
|
156
159
|
readonly parentElement: HTMLElement | null;
|
|
157
160
|
readonly parentNode: ParentNode | null;
|
|
158
161
|
readonly previousSibling: ChildNode | null;
|
|
159
|
-
textContent: string | null;
|
|
160
162
|
appendChild<T_1 extends Node>(node: T_1): T_1;
|
|
161
163
|
cloneNode(subtree?: boolean): Node;
|
|
162
164
|
compareDocumentPosition(other: Node): number;
|
|
@@ -191,6 +193,7 @@ export declare const BaseLocalizedComponent: (new (...args: any[]) => {
|
|
|
191
193
|
readonly DOCUMENT_POSITION_CONTAINED_BY: 16;
|
|
192
194
|
readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: 32;
|
|
193
195
|
dispatchEvent(event: Event): boolean;
|
|
196
|
+
ariaActiveDescendantElement: Element | null;
|
|
194
197
|
ariaAtomic: string | null;
|
|
195
198
|
ariaAutoComplete: string | null;
|
|
196
199
|
ariaBrailleLabel: string | null;
|
|
@@ -201,21 +204,28 @@ export declare const BaseLocalizedComponent: (new (...args: any[]) => {
|
|
|
201
204
|
ariaColIndex: string | null;
|
|
202
205
|
ariaColIndexText: string | null;
|
|
203
206
|
ariaColSpan: string | null;
|
|
207
|
+
ariaControlsElements: ReadonlyArray<Element> | null;
|
|
204
208
|
ariaCurrent: string | null;
|
|
209
|
+
ariaDescribedByElements: ReadonlyArray<Element> | null;
|
|
205
210
|
ariaDescription: string | null;
|
|
211
|
+
ariaDetailsElements: ReadonlyArray<Element> | null;
|
|
206
212
|
ariaDisabled: string | null;
|
|
213
|
+
ariaErrorMessageElements: ReadonlyArray<Element> | null;
|
|
207
214
|
ariaExpanded: string | null;
|
|
215
|
+
ariaFlowToElements: ReadonlyArray<Element> | null;
|
|
208
216
|
ariaHasPopup: string | null;
|
|
209
217
|
ariaHidden: string | null;
|
|
210
218
|
ariaInvalid: string | null;
|
|
211
219
|
ariaKeyShortcuts: string | null;
|
|
212
220
|
ariaLabel: string | null;
|
|
221
|
+
ariaLabelledByElements: ReadonlyArray<Element> | null;
|
|
213
222
|
ariaLevel: string | null;
|
|
214
223
|
ariaLive: string | null;
|
|
215
224
|
ariaModal: string | null;
|
|
216
225
|
ariaMultiLine: string | null;
|
|
217
226
|
ariaMultiSelectable: string | null;
|
|
218
227
|
ariaOrientation: string | null;
|
|
228
|
+
ariaOwnsElements: ReadonlyArray<Element> | null;
|
|
219
229
|
ariaPlaceholder: string | null;
|
|
220
230
|
ariaPosInSet: string | null;
|
|
221
231
|
ariaPressed: string | null;
|
|
@@ -273,18 +283,19 @@ export declare const BaseLocalizedComponent: (new (...args: any[]) => {
|
|
|
273
283
|
onanimationend: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null;
|
|
274
284
|
onanimationiteration: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null;
|
|
275
285
|
onanimationstart: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null;
|
|
276
|
-
onauxclick: ((this: GlobalEventHandlers, ev:
|
|
286
|
+
onauxclick: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
277
287
|
onbeforeinput: ((this: GlobalEventHandlers, ev: InputEvent) => any) | null;
|
|
278
|
-
|
|
288
|
+
onbeforematch: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
289
|
+
onbeforetoggle: ((this: GlobalEventHandlers, ev: ToggleEvent) => any) | null;
|
|
279
290
|
onblur: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null;
|
|
280
291
|
oncancel: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
281
292
|
oncanplay: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
282
293
|
oncanplaythrough: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
283
294
|
onchange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
284
|
-
onclick: ((this: GlobalEventHandlers, ev:
|
|
295
|
+
onclick: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
285
296
|
onclose: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
286
297
|
oncontextlost: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
287
|
-
oncontextmenu: ((this: GlobalEventHandlers, ev:
|
|
298
|
+
oncontextmenu: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
288
299
|
oncontextrestored: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
289
300
|
oncopy: ((this: GlobalEventHandlers, ev: ClipboardEvent) => any) | null;
|
|
290
301
|
oncuechange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
@@ -332,6 +343,7 @@ export declare const BaseLocalizedComponent: (new (...args: any[]) => {
|
|
|
332
343
|
onpointermove: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
333
344
|
onpointerout: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
334
345
|
onpointerover: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
346
|
+
onpointerrawupdate: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
335
347
|
onpointerup: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
336
348
|
onprogress: ((this: GlobalEventHandlers, ev: ProgressEvent) => any) | null;
|
|
337
349
|
onratechange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
@@ -350,7 +362,7 @@ export declare const BaseLocalizedComponent: (new (...args: any[]) => {
|
|
|
350
362
|
onsubmit: ((this: GlobalEventHandlers, ev: SubmitEvent) => any) | null;
|
|
351
363
|
onsuspend: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
352
364
|
ontimeupdate: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
353
|
-
ontoggle: ((this: GlobalEventHandlers, ev:
|
|
365
|
+
ontoggle: ((this: GlobalEventHandlers, ev: ToggleEvent) => any) | null;
|
|
354
366
|
ontouchcancel?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
355
367
|
ontouchend?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
356
368
|
ontouchmove?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-component.d.ts","sourceRoot":"","sources":["../../../src/base-component/base-component.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,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A6E,GAAG;;;;;;;WAA4V,GAAG;YAAiD,GAAG;;;;;;;;;;;oBAAupC,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAiiO,CAAC;cAA6F,CAAC;eAA8F,CAAC;gBAA+F,CAAC;;;;;;;;;;;;;;SAAulC,CAAC;;;iBAA+E,CAAC;yBAD/gtB,CAAC"}
|
|
@@ -37,12 +37,13 @@ export declare class FormControl extends BaseLocalizedComponent {
|
|
|
37
37
|
maxlength: number;
|
|
38
38
|
/** If the input is required. */
|
|
39
39
|
required: boolean;
|
|
40
|
+
protected isInGroup: boolean;
|
|
40
41
|
/** Gets the validity state object */
|
|
41
42
|
get validity(): ValidityState;
|
|
42
43
|
validationMessage: string;
|
|
43
|
-
checkValidity(): boolean;
|
|
44
44
|
/** Gets the associated form, if one exists. */
|
|
45
45
|
getForm(): HTMLFormElement | null;
|
|
46
|
+
checkValidity(): boolean;
|
|
46
47
|
/** Checks for validity and shows the browser's validation message if the control is invalid. */
|
|
47
48
|
reportValidity(): boolean;
|
|
48
49
|
/** Sets a custom validation message. Pass an empty string to restore validity. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-control.d.ts","sourceRoot":"","sources":["../../../src/form/form-control.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAK7D,qBAAa,WAAY,SAAQ,sBAAsB;IACrD,SAAS,CAAC,QAAQ,CAAC,qBAAqB,wBAErC;IASH,QAAQ,UAAS;IAGjB,YAAY,EAAG,gBAAgB,CAAC;IAEhC,4EAA4E;IAE5E,IAAI,SAAM;IAEV,qFAAqF;IAErF,KAAK,SAAM;IAEX,gCAAgC;IAEhC,QAAQ,UAAS;IAEjB;;;;OAIG;IACwC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C;IAExC;;;OAGG;IAEH,IAAI,EAAE,MAAM,GAAG,KAAK,CAAS;IAE7B,kCAAkC;IAElC,SAAS,SAAM;IAEf,kCAAkC;IAElC,SAAS,SAAM;IAEf,gCAAgC;IAEhC,QAAQ,UAAS;IAIjB,SAAS,CAAC,SAAS,UAAS;IAE5B,qCAAqC;IACrC,IAAW,QAAQ,IAAI,aAAa,CAEnC;IAGM,iBAAiB,SAAM;IAE9B,+CAA+C;IACxC,OAAO,IAAI,eAAe,GAAG,IAAI;IAKjC,aAAa,IAAI,OAAO;IAK/B,gGAAgG;IACzF,cAAc;IAOrB,kFAAkF;IAC3E,iBAAiB,CAAC,OAAO,EAAE,MAAM;IAOxC,SAAS,CAAC,YAAY;IAOtB,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE,KAAK;IAY/B,SAAS,CAAC,WAAW,CAAC,CAAC,EAAE,KAAK;IAO9B,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE,KAAK;IAK/B,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE,KAAK;IAO/B,SAAS,CAAC,wBAAwB;IAmClC,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK;IAKrC,SAAS,CAAC,aAAa,CAAC,CAAC,EAAE,KAAK;IAoCvB,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC;CAS3E"}
|
|
@@ -43,24 +43,27 @@ export class FormControl extends BaseLocalizedComponent {
|
|
|
43
43
|
this.maxlength = -1;
|
|
44
44
|
/** If the input is required. */
|
|
45
45
|
this.required = false;
|
|
46
|
+
/* For grouped input, like checkbox-group */
|
|
47
|
+
this.isInGroup = false;
|
|
46
48
|
this.validationMessage = '';
|
|
47
49
|
}
|
|
48
50
|
/** Gets the validity state object */
|
|
49
51
|
get validity() {
|
|
50
52
|
return this.inputElement?.validity;
|
|
51
53
|
}
|
|
54
|
+
/** Gets the associated form, if one exists. */
|
|
55
|
+
getForm() {
|
|
56
|
+
return this.formControlController.getForm();
|
|
57
|
+
}
|
|
52
58
|
// Form validation methods
|
|
53
59
|
checkValidity() {
|
|
54
60
|
const inputValid = this.inputElement?.checkValidity() ?? true; // this.inputElement.checkValidity() è la validazione del browser
|
|
55
61
|
return inputValid;
|
|
56
62
|
}
|
|
57
|
-
/** Gets the associated form, if one exists. */
|
|
58
|
-
getForm() {
|
|
59
|
-
return this.formControlController.getForm();
|
|
60
|
-
}
|
|
61
63
|
/** Checks for validity and shows the browser's validation message if the control is invalid. */
|
|
62
64
|
reportValidity() {
|
|
63
|
-
const ret = this.inputElement.checkValidity();
|
|
65
|
+
// const ret = this.inputElement.checkValidity();
|
|
66
|
+
const ret = this.checkValidity(); // chiama la checkValidity, che se è stata overridata chiama quella
|
|
64
67
|
this.handleValidationMessages();
|
|
65
68
|
return ret; // this.inputElement.reportValidity();
|
|
66
69
|
}
|
|
@@ -105,7 +108,8 @@ export class FormControl extends BaseLocalizedComponent {
|
|
|
105
108
|
handleValidationMessages() {
|
|
106
109
|
if (!this.customValidation) {
|
|
107
110
|
const _v = this.inputElement.validity;
|
|
108
|
-
|
|
111
|
+
const isRequiredHandledByGroup = this.isInGroup === true;
|
|
112
|
+
if (_v.valueMissing && !isRequiredHandledByGroup) {
|
|
109
113
|
this.setCustomValidity(this.$t('validityRequired'));
|
|
110
114
|
}
|
|
111
115
|
else if (_v.patternMismatch) {
|
|
@@ -176,7 +180,7 @@ export class FormControl extends BaseLocalizedComponent {
|
|
|
176
180
|
if (this.customValidation) {
|
|
177
181
|
this.setCustomValidity(this.validationText ?? '');
|
|
178
182
|
}
|
|
179
|
-
else {
|
|
183
|
+
else if (this.formControlController.userInteracted()) {
|
|
180
184
|
this.formControlController.updateValidity();
|
|
181
185
|
}
|
|
182
186
|
}
|
|
@@ -244,6 +248,10 @@ __decorate([
|
|
|
244
248
|
,
|
|
245
249
|
__metadata("design:type", Object)
|
|
246
250
|
], FormControl.prototype, "required", void 0);
|
|
251
|
+
__decorate([
|
|
252
|
+
property({ type: Boolean }),
|
|
253
|
+
__metadata("design:type", Object)
|
|
254
|
+
], FormControl.prototype, "isInGroup", void 0);
|
|
247
255
|
__decorate([
|
|
248
256
|
state(),
|
|
249
257
|
__metadata("design:type", Object)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-control.js","sourceRoot":"","sources":["../../../src/form/form-control.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEjC,mBAAmB,CAAC,EAAE,CAAC,CAAC;AAExB,MAAM,OAAO,WAAY,SAAQ,sBAAsB;IAAvD;;QACqB,0BAAqB,GAAG,IAAI,qBAAqB,CAAC,IAAI,EAAE;YACzE,mBAAmB,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,WAAW,CAAC;SAC1D,CAAC,CAAC;QAEH,4EAA4E;QAC5E,gCAAgC;QAEhC,gBAAgB;QAChB,sCAAsC;QAGtC,aAAQ,GAAG,KAAK,CAAC;QAKjB,4EAA4E;QAE5E,SAAI,GAAG,EAAE,CAAC;QAEV,qFAAqF;QAErF,UAAK,GAAG,EAAE,CAAC;QAEX,gCAAgC;QAEhC,aAAQ,GAAG,KAAK,CAAC;QAEjB;;;;WAIG;QACwC,SAAI,GAAG,EAAE,CAAC;QAErD,0FAA0F;QAE1F,qBAAgB,GAAG,KAAK,CAAC;QAEzB,uGAAuG;QAEvG,mBAAc,GAAW,EAAE,CAAC;QAc5B;;;WAGG;QAEH,SAAI,GAAmB,KAAK,CAAC;QAE7B,kCAAkC;QAElC,cAAS,GAAG,CAAC,CAAC,CA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,EAAE;;6CACS;AAGjB;IADC,KAAK,CAAC,mBAAmB,CAAC;8BACZ,gBAAgB;iDAAC;AAIhC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,mBAAmB;;;yCACpD;AAIV;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;0CACjB;AAIX;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,mBAAmB;;;6CAC9C;AAO0B;IAA1C,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;yCAAW;AAIrD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,mBAAmB,EAAE,CAAC;;qDAClD;AAIzB;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;mDAC/B;AAI5B;IADC,QAAQ,EAAE;;4CACM;AAIjB;IADC,QAAQ,EAAE;;wCAC6B;AAIxC;IADC,QAAQ,EAAE;;wCAC6B;AAOxC;IADC,QAAQ,EAAE;;yCACkB;AAI7B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CACZ;AAIf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CACZ;AAIf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,mBAAmB;;;6CAC9C;AAQV;IADN,KAAK,EAAE;;sDACsB","sourcesContent":["import { property, query, state } from 'lit/decorators.js';\nimport { registerTranslation } from '@italia/i18n';\nimport { BaseLocalizedComponent } from '../base-component/base-component.js';\nimport { FormControlController } from './form-controller.js';\nimport it from './locales/it.js';\n\nregisterTranslation(it);\n\nexport class FormControl extends BaseLocalizedComponent {\n protected readonly formControlController = new FormControlController(this, {\n assumeInteractionOn: ['it-input', 'it-blur', 'it-change'],\n });\n\n // TODO: verificare se serve davvero con il fatto che usiamo form-controller\n // static formAssociated = true;\n\n // @property()\n // internals = this.attachInternals();\n\n @state()\n _touched = false;\n\n @query('.it-form__control')\n inputElement!: HTMLInputElement; // from FormControl\n\n /** The name of the input, submitted as a name/value pair with form data. */\n @property({ type: String, reflect: true }) // from FormControl\n name = '';\n\n /** The current value of the input, submitted as a name/value pair with form data. */\n @property({ reflect: true })\n value = '';\n\n /** If the input is disabled. */\n @property({ type: Boolean, reflect: true }) // from FormControl\n disabled = false;\n\n /**\n * By default, form controls are associated with the nearest containing `<form>` element. This attribute allows you\n * to place the form control outside of a form and associate it with the form that has this `id`. The form must be in\n * the same document or shadow root for this to work.\n */\n @property({ reflect: true, type: String }) form = '';\n\n /** If you implement your custom validation and you won't to trigger default validation */\n @property({ type: Boolean, reflect: true, attribute: 'custom-validation' })\n customValidation = false;\n\n /** If your input is invalid from your custom validition, set this attribute with message validation */\n @property({ attribute: 'validity-message', reflect: true })\n validationText: string = '';\n\n /** Pattern the `value` must match to be valid */\n @property()\n pattern?: string;\n\n /** The input's minimum value. Only applies to date and number input types. */\n @property()\n min: number | string | Date | undefined;\n\n /** The input's maximum value. Only applies to date and number input types. */\n @property()\n max: number | string | Date | undefined;\n\n /**\n * Specifies the granularity that the value must adhere to, or the special value `any` which means no stepping is\n * implied, allowing any numeric value. Only applies to date and number input types.\n */\n @property()\n step: number | 'any' = 'any';\n\n /** The input's minimum length. */\n @property({ type: Number })\n minlength = -1;\n\n /** The input's maximum length. */\n @property({ type: Number })\n maxlength = -1;\n\n /** If the input is required. */\n @property({ type: Boolean, reflect: true }) // from FormControl\n required = false;\n\n /** Gets the validity state object */\n public get validity(): ValidityState {\n return this.inputElement?.validity;\n }\n\n @state()\n public validationMessage = '';\n\n // Form validation methods\n public checkValidity(): boolean {\n const inputValid = this.inputElement?.checkValidity() ?? true; // this.inputElement.checkValidity() è la validazione del browser\n return inputValid;\n }\n\n /** Gets the associated form, if one exists. */\n public getForm(): HTMLFormElement | null {\n return this.formControlController.getForm();\n }\n\n /** Checks for validity and shows the browser's validation message if the control is invalid. */\n public reportValidity() {\n const ret = this.inputElement.checkValidity();\n this.handleValidationMessages();\n return ret; // this.inputElement.reportValidity();\n }\n\n /** Sets a custom validation message. Pass an empty string to restore validity. */\n public setCustomValidity(message: string) {\n this.inputElement.setCustomValidity(message);\n this.validationMessage = this.inputElement.validationMessage;\n this.formControlController.updateValidity();\n }\n\n // Handlers\n\n protected _handleReady() {\n requestAnimationFrame(() => {\n this.dispatchEvent(new CustomEvent('it-input-ready', { bubbles: true, detail: { el: this.inputElement } }));\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleInput(e: Event) {\n this.handleValidationMessages();\n\n this.dispatchEvent(\n new CustomEvent('it-input', {\n detail: { value: this.inputElement.value, el: this.inputElement },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleBlur(e: Event) {\n this._touched = true;\n this.handleValidationMessages();\n\n this.dispatchEvent(new FocusEvent('it-blur', { bubbles: true, composed: true }));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleFocus(e: Event) {\n this.dispatchEvent(new FocusEvent('it-focus', { bubbles: true, composed: true }));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleClick(e: Event) {\n this.dispatchEvent(new MouseEvent('it-click', { bubbles: true, composed: true }));\n }\n\n /*\n Override default browser validation messages\n */\n protected handleValidationMessages() {\n if (!this.customValidation) {\n const _v = this.inputElement.validity;\n\n if (_v.valueMissing) {\n this.setCustomValidity(this.$t('validityRequired'));\n } else if (_v.patternMismatch) {\n this.setCustomValidity(this.$t('validityPattern'));\n } else if (_v.tooShort) {\n this.setCustomValidity(this.$t('validityMinlength').replace('{minlength}', this.minlength.toString()));\n } else if (_v.tooLong) {\n this.setCustomValidity(this.$t('validityMaxlength').replace('{maxlength}', this.maxlength.toString()));\n } else {\n /* nothing. Usa il messaggio di errore della validazione\n di default del browser per altri errori di validità come:\n - typeMismatch\n - rangeUnderflow\n - rangeOverflow\n - stepMismatch\n - badInput */\n\n const otherConstraintErrors =\n _v.typeMismatch || _v.rangeUnderflow || _v.rangeOverflow || _v.stepMismatch || _v.badInput;\n\n if (!otherConstraintErrors) {\n this.setCustomValidity('');\n }\n }\n }\n\n this.validationMessage = this.inputElement.validationMessage;\n }\n\n protected _handleInvalid(event: Event) {\n this.formControlController.setValidity(false);\n this.formControlController.emitInvalidEvent(event);\n }\n\n protected _handleChange(e: Event) {\n const target = e.target as HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;\n let value: unknown;\n\n if (target instanceof HTMLInputElement) {\n switch (target.type) {\n case 'checkbox':\n case 'radio':\n value = target.checked;\n break;\n case 'file':\n value = target.files; // FileList\n break;\n default:\n value = target.value;\n }\n } else if (target instanceof HTMLSelectElement) {\n if (target.multiple) {\n value = Array.from(target.selectedOptions).map((o) => o.value);\n } else {\n value = target.value;\n }\n } else {\n // textarea o altri input con value\n value = (target as any).value;\n }\n\n this.dispatchEvent(\n new CustomEvent('it-change', {\n detail: { value, el: target },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n override updated(changedProperties: Map<string | number | symbol, unknown>) {\n super.updated?.(changedProperties);\n\n if (this.customValidation) {\n this.setCustomValidity(this.validationText ?? '');\n } else {\n this.formControlController.updateValidity();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"form-control.js","sourceRoot":"","sources":["../../../src/form/form-control.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,sBAAsB,EA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,IAAI,EAAE,CAAC;;0CACjB;AAIX;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,mBAAmB;;;6CAC9C;AAO0B;IAA1C,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;yCAAW;AAIrD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,mBAAmB,EAAE,CAAC;;qDAClD;AAIzB;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;mDAC/B;AAI5B;IADC,QAAQ,EAAE;;4CACM;AAIjB;IADC,QAAQ,EAAE;;wCAC6B;AAIxC;IADC,QAAQ,EAAE;;wCAC6B;AAOxC;IADC,QAAQ,EAAE;;yCACkB;AAI7B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CACZ;AAIf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CACZ;AAIf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,mBAAmB;;;6CAC9C;AAIP;IADT,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;8CACA;AAQrB;IADN,KAAK,EAAE;;sDACsB","sourcesContent":["import { property, query, state } from 'lit/decorators.js';\nimport { registerTranslation } from '@italia/i18n';\nimport { BaseLocalizedComponent } from '../base-component/base-component.js';\nimport { FormControlController } from './form-controller.js';\nimport it from './locales/it.js';\n\nregisterTranslation(it);\n\nexport class FormControl extends BaseLocalizedComponent {\n protected readonly formControlController = new FormControlController(this, {\n assumeInteractionOn: ['it-input', 'it-blur', 'it-change'],\n });\n\n // TODO: verificare se serve davvero con il fatto che usiamo form-controller\n // static formAssociated = true;\n\n // @property()\n // internals = this.attachInternals();\n\n @state()\n _touched = false;\n\n @query('.it-form__control')\n inputElement!: HTMLInputElement; // from FormControl\n\n /** The name of the input, submitted as a name/value pair with form data. */\n @property({ type: String, reflect: true }) // from FormControl\n name = '';\n\n /** The current value of the input, submitted as a name/value pair with form data. */\n @property({ reflect: true })\n value = '';\n\n /** If the input is disabled. */\n @property({ type: Boolean, reflect: true }) // from FormControl\n disabled = false;\n\n /**\n * By default, form controls are associated with the nearest containing `<form>` element. This attribute allows you\n * to place the form control outside of a form and associate it with the form that has this `id`. The form must be in\n * the same document or shadow root for this to work.\n */\n @property({ reflect: true, type: String }) form = '';\n\n /** If you implement your custom validation and you won't to trigger default validation */\n @property({ type: Boolean, reflect: true, attribute: 'custom-validation' })\n customValidation = false;\n\n /** If your input is invalid from your custom validition, set this attribute with message validation */\n @property({ attribute: 'validity-message', reflect: true })\n validationText: string = '';\n\n /** Pattern the `value` must match to be valid */\n @property()\n pattern?: string;\n\n /** The input's minimum value. Only applies to date and number input types. */\n @property()\n min: number | string | Date | undefined;\n\n /** The input's maximum value. Only applies to date and number input types. */\n @property()\n max: number | string | Date | undefined;\n\n /**\n * Specifies the granularity that the value must adhere to, or the special value `any` which means no stepping is\n * implied, allowing any numeric value. Only applies to date and number input types.\n */\n @property()\n step: number | 'any' = 'any';\n\n /** The input's minimum length. */\n @property({ type: Number })\n minlength = -1;\n\n /** The input's maximum length. */\n @property({ type: Number })\n maxlength = -1;\n\n /** If the input is required. */\n @property({ type: Boolean, reflect: true }) // from FormControl\n required = false;\n\n /* For grouped input, like checkbox-group */\n @property({ type: Boolean })\n protected isInGroup = false;\n\n /** Gets the validity state object */\n public get validity(): ValidityState {\n return this.inputElement?.validity;\n }\n\n @state()\n public validationMessage = '';\n\n /** Gets the associated form, if one exists. */\n public getForm(): HTMLFormElement | null {\n return this.formControlController.getForm();\n }\n\n // Form validation methods\n public checkValidity(): boolean {\n const inputValid = this.inputElement?.checkValidity() ?? true; // this.inputElement.checkValidity() è la validazione del browser\n return inputValid;\n }\n\n /** Checks for validity and shows the browser's validation message if the control is invalid. */\n public reportValidity() {\n // const ret = this.inputElement.checkValidity();\n const ret = this.checkValidity(); // chiama la checkValidity, che se è stata overridata chiama quella\n this.handleValidationMessages();\n return ret; // this.inputElement.reportValidity();\n }\n\n /** Sets a custom validation message. Pass an empty string to restore validity. */\n public setCustomValidity(message: string) {\n this.inputElement.setCustomValidity(message);\n this.validationMessage = this.inputElement.validationMessage;\n this.formControlController.updateValidity();\n }\n\n // Handlers\n protected _handleReady() {\n requestAnimationFrame(() => {\n this.dispatchEvent(new CustomEvent('it-input-ready', { bubbles: true, detail: { el: this.inputElement } }));\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleInput(e: Event) {\n this.handleValidationMessages();\n this.dispatchEvent(\n new CustomEvent('it-input', {\n detail: { value: this.inputElement.value, el: this.inputElement },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleBlur(e: Event) {\n this._touched = true;\n this.handleValidationMessages();\n this.dispatchEvent(new FocusEvent('it-blur', { bubbles: true, composed: true }));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleFocus(e: Event) {\n this.dispatchEvent(new FocusEvent('it-focus', { bubbles: true, composed: true }));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleClick(e: Event) {\n this.dispatchEvent(new MouseEvent('it-click', { bubbles: true, composed: true }));\n }\n\n /*\n Override default browser validation messages\n */\n protected handleValidationMessages() {\n if (!this.customValidation) {\n const _v = this.inputElement.validity;\n\n const isRequiredHandledByGroup = this.isInGroup === true;\n\n if (_v.valueMissing && !isRequiredHandledByGroup) {\n this.setCustomValidity(this.$t('validityRequired'));\n } else if (_v.patternMismatch) {\n this.setCustomValidity(this.$t('validityPattern'));\n } else if (_v.tooShort) {\n this.setCustomValidity(this.$t('validityMinlength').replace('{minlength}', this.minlength.toString()));\n } else if (_v.tooLong) {\n this.setCustomValidity(this.$t('validityMaxlength').replace('{maxlength}', this.maxlength.toString()));\n } else {\n /* nothing. Usa il messaggio di errore della validazione\n di default del browser per altri errori di validità come:\n - typeMismatch\n - rangeUnderflow\n - rangeOverflow\n - stepMismatch\n - badInput */\n\n const otherConstraintErrors =\n _v.typeMismatch || _v.rangeUnderflow || _v.rangeOverflow || _v.stepMismatch || _v.badInput;\n\n if (!otherConstraintErrors) {\n this.setCustomValidity('');\n }\n }\n }\n\n this.validationMessage = this.inputElement.validationMessage;\n }\n\n protected _handleInvalid(event: Event) {\n this.formControlController.setValidity(false);\n this.formControlController.emitInvalidEvent(event);\n }\n\n protected _handleChange(e: Event) {\n const target = e.target as HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;\n let value: unknown;\n\n if (target instanceof HTMLInputElement) {\n switch (target.type) {\n case 'checkbox':\n case 'radio':\n value = target.checked;\n break;\n case 'file':\n value = target.files; // FileList\n break;\n default:\n value = target.value;\n }\n } else if (target instanceof HTMLSelectElement) {\n if (target.multiple) {\n value = Array.from(target.selectedOptions).map((o) => o.value);\n } else {\n value = target.value;\n }\n } else {\n // textarea o altri input con value\n value = (target as any).value;\n }\n\n this.dispatchEvent(\n new CustomEvent('it-change', {\n detail: { value, el: target },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n override updated(changedProperties: Map<string | number | symbol, unknown>) {\n super.updated?.(changedProperties);\n\n if (this.customValidation) {\n this.setCustomValidity(this.validationText ?? '');\n } else if (this.formControlController.userInteracted()) {\n this.formControlController.updateValidity();\n }\n }\n}\n"]}
|
|
@@ -24,6 +24,7 @@ export declare class FormControlController implements ReactiveController {
|
|
|
24
24
|
host: FormControl & ReactiveControllerHost;
|
|
25
25
|
form?: HTMLFormElement | null;
|
|
26
26
|
options: FormControlControllerOptions;
|
|
27
|
+
submittedOnce: boolean;
|
|
27
28
|
constructor(host: ReactiveControllerHost & FormControl, options?: Partial<FormControlControllerOptions>);
|
|
28
29
|
hostConnected(): void;
|
|
29
30
|
hostDisconnected(): void;
|
|
@@ -49,6 +50,7 @@ export declare class FormControlController implements ReactiveController {
|
|
|
49
50
|
* the host element immediately, i.e. before Lit updates the component in the next update.
|
|
50
51
|
*/
|
|
51
52
|
setValidity(isValid: boolean): void;
|
|
53
|
+
userInteracted(): boolean;
|
|
52
54
|
/**
|
|
53
55
|
* Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything
|
|
54
56
|
* that affects constraint validation changes so the component receives the correct validity states.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-controller.d.ts","sourceRoot":"","sources":["../../../src/form/form-controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,KAAK,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD,eAAO,MAAM,eAAe,EAAE,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,WAAW,CAAC,CAAiB,CAAC;AAoBzF,MAAM,WAAW,4BAA4B;IAC3C,oEAAoE;IACpE,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,eAAe,GAAG,IAAI,CAAC;IACrD,mGAAmG;IACnG,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,CAAC;IACrC,gEAAgE;IAChE,KAAK,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,GAAG,OAAO,EAAE,CAAC;IACnD,oHAAoH;IACpH,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IAK1C,cAAc,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IAMhD,aAAa,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IAC/C,oDAAoD;IACpD,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;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IAC9D,IAAI,EAAE,WAAW,GAAG,sBAAsB,CAAC;IAE3C,IAAI,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAE9B,OAAO,EAAE,4BAA4B,CAAC;IAEtC,aAAa,EAAE,OAAO,CAAS;gBAEnB,IAAI,EAAE,sBAAsB,GAAG,WAAW,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,4BAA4B,CAAC;IAkCvG,aAAa;IAab,gBAAgB;IAUhB,WAAW;IAmBX,OAAO,CAAC,UAAU;IA+BlB,OAAO,CAAC,UAAU;IAwClB,OAAO,CAAC,cAAc,CA8CpB;IAEF,OAAO,CAAC,gBAAgB,CAiCtB;IAEF,OAAO,CAAC,eAAe,CAKrB;IAEF,OAAO,CAAC,iBAAiB,CAWvB;IAEF,OAAO,CAAC,iBAAiB,CA2BvB;IAEF,OAAO,CAAC,kBAAkB,CA6BxB;IAGF,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,QAAQ;IA8BhB,8DAA8D;IAC9D,OAAO;IAIP,wEAAwE;IACxE,KAAK,CAAC,SAAS,CAAC,EAAE,gBAAgB,GAAG,GAAG;IAIxC,uEAAuE;IACvE,MAAM,CAAC,SAAS,CAAC,EAAE,gBAAgB,GAAG,GAAG;IAMzC;;;OAGG;IACH,WAAW,CAAC,OAAO,EAAE,OAAO;IAmB5B,cAAc;IAMd;;;OAGG;IACH,cAAc;IAKd;;;;;;OAMG;IACH,gBAAgB,CAAC,oBAAoB,CAAC,EAAE,KAAK;CAgB9C"}
|
|
@@ -22,6 +22,7 @@ const interactions = new WeakMap();
|
|
|
22
22
|
/** A reactive controller to allow form controls to participate in form submission, validation, etc. */
|
|
23
23
|
export class FormControlController {
|
|
24
24
|
constructor(host, options) {
|
|
25
|
+
this.submittedOnce = false;
|
|
25
26
|
this.handleFormData = (event) => {
|
|
26
27
|
// console.log('handleFormData');
|
|
27
28
|
const disabled = this.options.disabled(this.host);
|
|
@@ -43,6 +44,17 @@ export class FormControlController {
|
|
|
43
44
|
event.formData.append(name, value);
|
|
44
45
|
}
|
|
45
46
|
break;
|
|
47
|
+
case 'it-checkbox':
|
|
48
|
+
if (this.host.checked) {
|
|
49
|
+
if (event.formData.getAll(name).indexOf(value) < 0) {
|
|
50
|
+
// handle group checkbox
|
|
51
|
+
event.formData.append(name, value);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
case 'it-checkbox-group':
|
|
56
|
+
// non settare valori in formData, perchè ogni singola checkbox setta il suo valore
|
|
57
|
+
break;
|
|
46
58
|
default:
|
|
47
59
|
if (Array.isArray(value)) {
|
|
48
60
|
value.forEach((val) => {
|
|
@@ -64,13 +76,30 @@ export class FormControlController {
|
|
|
64
76
|
this.setUserInteracted(control, true);
|
|
65
77
|
});
|
|
66
78
|
}
|
|
67
|
-
|
|
79
|
+
const resReportValidity = reportValidity(this.host);
|
|
80
|
+
if (this.form && !this.form.noValidate && !disabled && !resReportValidity) {
|
|
68
81
|
event.preventDefault();
|
|
69
82
|
// event.stopImmediatePropagation(); // se lo attiviamo, valida un campo alla volta
|
|
83
|
+
// Scroll al primo controllo non valido
|
|
84
|
+
const formControls = formCollections.get(this.form);
|
|
85
|
+
if (formControls) {
|
|
86
|
+
for (const control of formControls) {
|
|
87
|
+
if (!control.validity?.valid) {
|
|
88
|
+
// Scroll smooth verso il controllo non valido
|
|
89
|
+
control.scrollIntoView({
|
|
90
|
+
behavior: 'smooth',
|
|
91
|
+
block: 'center',
|
|
92
|
+
});
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
70
97
|
}
|
|
98
|
+
this.submittedOnce = true;
|
|
71
99
|
};
|
|
72
100
|
this.handleFormReset = () => {
|
|
73
101
|
this.options.setValue(this.host, '');
|
|
102
|
+
this.submittedOnce = false;
|
|
74
103
|
this.setUserInteracted(this.host, false);
|
|
75
104
|
interactions.set(this.host, []);
|
|
76
105
|
};
|
|
@@ -235,6 +264,7 @@ export class FormControlController {
|
|
|
235
264
|
if (!formCollection) {
|
|
236
265
|
return;
|
|
237
266
|
}
|
|
267
|
+
this.submittedOnce = false;
|
|
238
268
|
// Remove this host from the form's collection
|
|
239
269
|
formCollection.delete(this.host);
|
|
240
270
|
// Check to make sure there's no other form controls in the collection. If we do this
|
|
@@ -331,6 +361,10 @@ export class FormControlController {
|
|
|
331
361
|
host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);
|
|
332
362
|
host.toggleAttribute('data-user-valid', isValid && hasInteracted);
|
|
333
363
|
}
|
|
364
|
+
userInteracted() {
|
|
365
|
+
const hasInteracted = Boolean(userInteractedControls.has(this.host));
|
|
366
|
+
return hasInteracted;
|
|
367
|
+
}
|
|
334
368
|
/**
|
|
335
369
|
* Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything
|
|
336
370
|
* that affects constraint validation changes so the component receives the correct validity states.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-controller.js","sourceRoot":"","sources":["../../../src/form/form-controller.ts"],"names":[],"mappings":"AAIA,EAAE;AACF,8GAA8G;AAC9G,oHAAoH;AACpH,uDAAuD;AACvD,EAAE;AACF,MAAM,CAAC,MAAM,eAAe,GAA+C,IAAI,OAAO,EAAE,CAAC;AAEzF,EAAE;AACF,mHAAmH;AACnH,sDAAsD;AACtD,EAAE;AACF,MAAM,uBAAuB,GAA4C,IAAI,OAAO,EAAE,CAAC;AACvF,MAAM,sBAAsB,GAA4C,IAAI,OAAO,EAAE,CAAC;AAEtF,EAAE;AACF,gHAAgH;AAChH,6DAA6D;AAC7D,EAAE;AACF,MAAM,sBAAsB,GAAyB,IAAI,OAAO,EAAE,CAAC;AAEnE,EAAE;AACF,uHAAuH;AACvH,EAAE;AACF,MAAM,YAAY,GAAG,IAAI,OAAO,EAAyB,CAAC;AA8B1D,uGAAuG;AACvG,MAAM,OAAO,qBAAqB;IAOhC,YAAY,IAA0C,EAAE,OAA+C;QAkJ/F,mBAAc,GAAG,CAAC,KAAo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I;YAChB,MAAM,EAAE,EAAE;SACX,CAAC,CAAC;QAEH,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC1B,cAAc,CAAC,cAAc,EAAE,CAAC;QAClC,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,EAAE,CAAC;YAC7C,oBAAoB,EAAE,cAAc,EAAE,CAAC;QACzC,CAAC;IACH,CAAC;CACF","sourcesContent":["/* eslint-disable prefer-destructuring */\nimport type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport { FormControl } from './form-control.js';\n\n//\n// We store a WeakMap of forms + controls so we can keep references to all FormControl within a given form. As\n// elements connect and disconnect to/from the DOM, their containing form is used as the key and the form control is\n// added and removed from the form's set, respectively.\n//\nexport const formCollections: WeakMap<HTMLFormElement, Set<FormControl>> = new WeakMap();\n\n//\n// We store a WeakMap of reportValidity() overloads so we can override it when form controls connect to the DOM and\n// restore the original behavior when they disconnect.\n//\nconst reportValidityOverloads: WeakMap<HTMLFormElement, () => boolean> = new WeakMap();\nconst checkValidityOverloads: WeakMap<HTMLFormElement, () => boolean> = new WeakMap();\n\n//\n// We store a Set of controls that users have interacted with. This allows us to determine the interaction state\n// without littering the DOM with additional data attributes.\n//\nconst userInteractedControls: WeakSet<FormControl> = new WeakSet();\n\n//\n// We store a WeakMap of interactions for each form control so we can track when all conditions are met for validation.\n//\nconst interactions = new WeakMap<FormControl, string[]>();\n\nexport interface FormControlControllerOptions {\n /** A function that returns the form containing the form control. */\n form: (input: FormControl) => HTMLFormElement | null;\n /** A function that returns the form control's name, which will be submitted with the form data. */\n name: (input: FormControl) => string;\n /** A function that returns the form control's current value. */\n value: (input: FormControl) => unknown | unknown[];\n /** A function that returns the form control's current disabled state. If disabled, the value won't be submitted. */\n disabled: (input: FormControl) => boolean;\n // /**\n // * A function that maps to the form control's reportValidity() function. When the control is invalid, this will\n // * prevent submission and trigger the browser's constraint violation warning.\n // */\n reportValidity: (input: FormControl) => boolean;\n\n // /**\n // * A function that maps to the form control's `checkValidity()` function. When the control is invalid, this will return false.\n // * this is helpful is you want to check validation without triggering the native browser constraint violation warning.\n // */\n checkValidity: (input: FormControl) => boolean;\n /** A function that sets the form control's value */\n setValue: (input: FormControl, value: unknown) => void;\n /**\n * An array of event names to listen to. When all events in the list are emitted, the control will receive validity\n * states such as user-valid and user-invalid.user interacted validity states. */\n assumeInteractionOn: string[];\n}\n\n/** A reactive controller to allow form controls to participate in form submission, validation, etc. */\nexport class FormControlController implements ReactiveController {\n host: FormControl & ReactiveControllerHost;\n\n form?: HTMLFormElement | null;\n\n options: FormControlControllerOptions;\n\n constructor(host: ReactiveControllerHost & FormControl, options?: Partial<FormControlControllerOptions>) {\n (this.host = host).addController(this);\n this.options = {\n form: (input) => {\n // If there's a form attribute, use it to find the target form by id\n // Controls may not always reflect the 'form' property. For example, `<it-button>` doesn't reflect.\n const formId = input.form;\n\n if (formId) {\n const root = input.getRootNode() as Document | ShadowRoot | HTMLElement;\n const form = root.querySelector(`#${formId}`);\n\n if (form) {\n return form as HTMLFormElement;\n }\n }\n\n return input.closest('form');\n },\n name: (input) => input.name,\n value: (input) => input.value,\n disabled: (input) => input.disabled ?? false,\n reportValidity: (input: FormControl) =>\n typeof input.reportValidity === 'function' ? input.reportValidity() : true,\n checkValidity: (input: FormControl) => (typeof input.checkValidity === 'function' ? input.checkValidity() : true),\n setValue: (input, value) => {\n // eslint-disable-next-line no-param-reassign\n input.value = value as string;\n },\n assumeInteractionOn: ['it-input'],\n ...options,\n };\n }\n\n hostConnected() {\n const form = this.options.form(this.host);\n if (form) {\n this.attachForm(form);\n }\n\n // Listen for interactions\n interactions.set(this.host, []);\n this.options.assumeInteractionOn.forEach((event) => {\n this.host.addEventListener(event, this.handleInteraction);\n });\n }\n\n hostDisconnected() {\n this.detachForm();\n\n // Clean up interactions\n interactions.delete(this.host);\n this.options.assumeInteractionOn.forEach((event) => {\n this.host.removeEventListener(event, this.handleInteraction);\n });\n }\n\n hostUpdated() {\n const form = this.options.form(this.host);\n\n // Detach if the form no longer exists\n if (!form) {\n this.detachForm();\n }\n\n // If the form has changed, reattach it\n if (form && this.form !== form) {\n this.detachForm();\n this.attachForm(form);\n }\n\n if (this.host.hasUpdated) {\n this.setValidity(this.host.validity.valid);\n }\n }\n\n private attachForm(form?: HTMLFormElement) {\n if (form) {\n this.form = form;\n\n // Add this element to the form's collection\n if (formCollections.has(this.form)) {\n formCollections.get(this.form)!.add(this.host);\n } else {\n formCollections.set(this.form, new Set<FormControl>([this.host]));\n }\n\n this.form.addEventListener('formdata', this.handleFormData);\n this.form.addEventListener('submit', this.handleFormSubmit);\n this.form.addEventListener('reset', this.handleFormReset);\n\n // Overload the form's reportValidity() method so it looks at FormControl\n if (!reportValidityOverloads.has(this.form)) {\n reportValidityOverloads.set(this.form, this.form.reportValidity);\n this.form.reportValidity = () => this.reportFormValidity();\n }\n\n // Overload the form's checkValidity() method so it looks at FormControl\n if (!checkValidityOverloads.has(this.form)) {\n checkValidityOverloads.set(this.form, this.form.checkValidity);\n this.form.checkValidity = () => this.checkFormValidity();\n }\n } else {\n this.form = undefined;\n }\n }\n\n private detachForm() {\n if (!this.form) return;\n\n const formCollection = formCollections.get(this.form);\n\n if (!formCollection) {\n return;\n }\n\n // Remove this host from the form's collection\n formCollection.delete(this.host);\n\n // Check to make sure there's no other form controls in the collection. If we do this\n // without checking if any other controls are still in the collection, then we will wipe out the\n // validity checks for all other elements.\n // see: https://github.com/shoelace-style/shoelace/issues/1703\n if (formCollection.size <= 0) {\n this.form.removeEventListener('formdata', this.handleFormData);\n this.form.removeEventListener('submit', this.handleFormSubmit);\n this.form.removeEventListener('reset', this.handleFormReset);\n\n // Remove the overload and restore the original method\n if (reportValidityOverloads.has(this.form)) {\n this.form.reportValidity = reportValidityOverloads.get(this.form)!;\n reportValidityOverloads.delete(this.form);\n }\n\n if (checkValidityOverloads.has(this.form)) {\n this.form.checkValidity = checkValidityOverloads.get(this.form)!;\n checkValidityOverloads.delete(this.form);\n }\n\n // So it looks weird here to not always set the form to undefined. But I _think_ if we unattach this.form here,\n // we end up in this fun spot where future validity checks don't have a reference to the form validity handler.\n // 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.\n this.form = undefined;\n }\n }\n\n private handleFormData = (event: FormDataEvent) => {\n // console.log('handleFormData');\n const disabled = this.options.disabled(this.host);\n const name = this.options.name(this.host);\n const value = this.options.value(this.host);\n const tagName = this.host.tagName.toLowerCase();\n\n // For buttons, we only submit the value if they were the submitter. This is currently done in doAction() by\n // injecting the name/value on a temporary button, so we can just skip them here.\n const isButton = tagName === 'it-button';\n\n if (\n this.host.isConnected &&\n !disabled &&\n !isButton &&\n typeof name === 'string' &&\n name.length > 0 &&\n typeof value !== 'undefined'\n ) {\n switch (tagName) {\n case 'it-radio':\n if ((this.host as any).checked) {\n event.formData.append(name, value as string);\n }\n break;\n default:\n if (Array.isArray(value)) {\n (value as unknown[]).forEach((val) => {\n event.formData.append(name, (val as string | number | boolean).toString());\n });\n } else {\n event.formData.append(name, (value as string | number | boolean).toString());\n }\n }\n }\n };\n\n private handleFormSubmit = (event: Event) => {\n const disabled = this.options.disabled(this.host);\n const reportValidity = this.options.reportValidity;\n\n // Update the interacted state for all controls when the form is submitted\n if (this.form && !this.form.noValidate) {\n formCollections.get(this.form)?.forEach((control) => {\n this.setUserInteracted(control, true);\n });\n }\n\n if (this.form && !this.form.noValidate && !disabled && !reportValidity(this.host)) {\n event.preventDefault();\n // event.stopImmediatePropagation(); // se lo attiviamo, valida un campo alla volta\n }\n };\n\n private handleFormReset = () => {\n this.options.setValue(this.host, '');\n this.setUserInteracted(this.host, false);\n interactions.set(this.host, []);\n };\n\n private handleInteraction = (event: Event) => {\n const emittedEvents = interactions.get(this.host)!;\n\n if (!emittedEvents.includes(event.type)) {\n emittedEvents.push(event.type);\n }\n\n // Mark it as user-interacted as soon as all associated events have been emitted\n if (emittedEvents.length === this.options.assumeInteractionOn.length) {\n this.setUserInteracted(this.host, true);\n }\n };\n\n private checkFormValidity = () => {\n // console.log('checkFormValidity');\n //\n // This is very similar to the `reportFormValidity` function, but it does not trigger native constraint validation\n // Allow the user to simply check if the form is valid and handling validity in their own way.\n //\n // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger\n // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't\n // be necessary once we can use ElementInternals.\n //\n // Note that we're also honoring the form's novalidate attribute.\n //\n if (this.form && !this.form.noValidate) {\n // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom\n // elements that support the constraint validation API.\n const elements = this.form.querySelectorAll<HTMLInputElement>('*');\n\n for (const element of elements) {\n if (typeof element.checkValidity === 'function') {\n if (!element.checkValidity()) {\n return false;\n }\n }\n }\n }\n\n return true;\n };\n\n private reportFormValidity = () => {\n // console.log('reportFormValidity');\n //\n // FormControl work hard to act like regular form controls. They support the Constraint Validation API\n // and its associated methods such as setCustomValidity() and reportValidity(). However, the HTMLFormElement also\n // has a reportValidity() method that will trigger validation on all child controls. Since we're not yet using\n // ElementInternals, we need to overload this method so it looks for any element with the reportValidity() method.\n //\n // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger\n // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't\n // be necessary once we can use ElementInternals.\n //\n // Note that we're also honoring the form's novalidate attribute.\n //\n if (this.form && !this.form.noValidate) {\n // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom\n // elements that support the constraint validation API.\n const elements = this.form.querySelectorAll<HTMLInputElement>('*');\n\n for (const element of elements) {\n if (typeof element.reportValidity === 'function') {\n if (!element.reportValidity()) {\n return false;\n }\n }\n }\n }\n\n return true;\n };\n\n // eslint-disable-next-line class-methods-use-this\n private setUserInteracted(el: FormControl, hasInteracted: boolean) {\n if (hasInteracted) {\n userInteractedControls.add(el);\n } else {\n userInteractedControls.delete(el);\n }\n\n el.requestUpdate();\n }\n\n private doAction(type: 'submit' | 'reset', submitter?: HTMLInputElement | any) {\n // console.log('doaction', type);\n if (this.form) {\n const button = document.createElement('button');\n button.type = type;\n button.style.position = 'absolute';\n button.style.width = '0';\n button.style.height = '0';\n button.style.clipPath = 'inset(50%)';\n button.style.overflow = 'hidden';\n button.style.whiteSpace = 'nowrap';\n\n // Pass name, value, and form attributes through to the temporary button\n if (submitter) {\n button.name = submitter.name;\n button.value = submitter.value;\n\n ['formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget'].forEach((attr) => {\n if (submitter.hasAttribute(attr)) {\n button.setAttribute(attr, submitter.getAttribute(attr)!);\n }\n });\n }\n\n this.form.append(button);\n button.click();\n button.remove();\n }\n }\n\n /** Returns the associated `<form>` element, if one exists. */\n getForm() {\n return this.form ?? null;\n }\n\n /** Resets the form, restoring all the control to their default value */\n reset(submitter?: HTMLInputElement | any) {\n this.doAction('reset', submitter);\n }\n\n /** Submits the form, triggering validation and form data injection. */\n submit(submitter?: HTMLInputElement | any) {\n // Calling form.submit() bypasses the submit event and constraint validation. To prevent this, we can inject a\n // native submit button into the form, \"click\" it, then remove it to simulate a standard form submission.\n this.doAction('submit', submitter);\n }\n\n /**\n * Synchronously sets the form control's validity. Call this when you know the future validity but need to update\n * the host element immediately, i.e. before Lit updates the component in the next update.\n */\n setValidity(isValid: boolean) {\n const host = this.host;\n const hasInteracted = Boolean(userInteractedControls.has(host));\n const required = Boolean(host.required);\n\n //\n // We're mapping the following \"states\" to data attributes. In the future, we can use ElementInternals.states to\n // create a similar mapping, but instead of [data-invalid] it will look like :--invalid.\n //\n // See this RFC for more details: https://github.com/shoelace-style/shoelace/issues/1011\n //\n host.toggleAttribute('data-required', required);\n host.toggleAttribute('data-optional', !required);\n host.toggleAttribute('data-invalid', !isValid);\n host.toggleAttribute('data-valid', isValid);\n host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);\n host.toggleAttribute('data-user-valid', isValid && hasInteracted);\n }\n\n /**\n * Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything\n * that affects constraint validation changes so the component receives the correct validity states.\n */\n updateValidity() {\n const host = this.host;\n this.setValidity(host.validity.valid);\n }\n\n /**\n * Dispatches a non-bubbling, cancelable custom event of type `it-invalid`.\n * If the `it-invalid` event will be cancelled then the original `invalid`\n * event (which may have been passed as argument) will also be cancelled.\n * If no original `invalid` event has been passed then the `it-invalid`\n * event will be cancelled before being dispatched.\n */\n emitInvalidEvent(originalInvalidEvent?: Event) {\n const itInvalidEvent = new CustomEvent<Record<PropertyKey, never>>('it-invalid', {\n bubbles: false,\n composed: false,\n cancelable: true,\n detail: {},\n });\n\n if (!originalInvalidEvent) {\n itInvalidEvent.preventDefault();\n }\n\n if (!this.host.dispatchEvent(itInvalidEvent)) {\n originalInvalidEvent?.preventDefault();\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"form-controller.js","sourceRoot":"","sources":["../../../src/form/form-controller.ts"],"names":[],"mappings":"AAIA,EAAE;AACF,8GAA8G;AAC9G,oHAAoH;AACpH,uDAAuD;AACvD,EAAE;AACF,MAAM,CAAC,MAAM,eAAe,GAA+C,IAAI,OAAO,EAAE,CAAC;AAEzF,EAAE;AACF,mHAAmH;AACnH,sDAAsD;AACtD,EAAE;AACF,MAAM,uBAAuB,GAA4C,IAAI,OAAO,EAAE,CAAC;AACvF,MAAM,sBAAsB,GAA4C,IAAI,OAAO,EAAE,CAAC;AAEtF,EAAE;AACF,gHAAgH;AAChH,6DAA6D;AAC7D,EAAE;AACF,MAAM,sBAAsB,GAAyB,IAAI,OAAO,EAAE,CAAC;AAEnE,EAAE;AACF,uHAAuH;AACvH,EAAE;AACF,MAAM,YAAY,GAAG,IAAI,OAAO,EAAyB,CAAC;AA8B1D,uGAAuG;AACvG,MAAM,OAAO,qBAAqB;IAShC,YAAY,IAA0C,EAAE,OAA+C;QAFvG,kBAAa,GAAY,KAAK,CAAC;QAqJvB,mBAAc,GAAG,CAAC,KAAoB,EAAE,EAAE;YAChD,iCAAiC;YACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,C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AC;YAC7C,oBAAoB,EAAE,cAAc,EAAE,CAAC;QACzC,CAAC;IACH,CAAC;CACF","sourcesContent":["/* eslint-disable prefer-destructuring */\nimport type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport { FormControl } from './form-control.js';\n\n//\n// We store a WeakMap of forms + controls so we can keep references to all FormControl within a given form. As\n// elements connect and disconnect to/from the DOM, their containing form is used as the key and the form control is\n// added and removed from the form's set, respectively.\n//\nexport const formCollections: WeakMap<HTMLFormElement, Set<FormControl>> = new WeakMap();\n\n//\n// We store a WeakMap of reportValidity() overloads so we can override it when form controls connect to the DOM and\n// restore the original behavior when they disconnect.\n//\nconst reportValidityOverloads: WeakMap<HTMLFormElement, () => boolean> = new WeakMap();\nconst checkValidityOverloads: WeakMap<HTMLFormElement, () => boolean> = new WeakMap();\n\n//\n// We store a Set of controls that users have interacted with. This allows us to determine the interaction state\n// without littering the DOM with additional data attributes.\n//\nconst userInteractedControls: WeakSet<FormControl> = new WeakSet();\n\n//\n// We store a WeakMap of interactions for each form control so we can track when all conditions are met for validation.\n//\nconst interactions = new WeakMap<FormControl, string[]>();\n\nexport interface FormControlControllerOptions {\n /** A function that returns the form containing the form control. */\n form: (input: FormControl) => HTMLFormElement | null;\n /** A function that returns the form control's name, which will be submitted with the form data. */\n name: (input: FormControl) => string;\n /** A function that returns the form control's current value. */\n value: (input: FormControl) => unknown | unknown[];\n /** A function that returns the form control's current disabled state. If disabled, the value won't be submitted. */\n disabled: (input: FormControl) => boolean;\n // /**\n // * A function that maps to the form control's reportValidity() function. When the control is invalid, this will\n // * prevent submission and trigger the browser's constraint violation warning.\n // */\n reportValidity: (input: FormControl) => boolean;\n\n // /**\n // * A function that maps to the form control's `checkValidity()` function. When the control is invalid, this will return false.\n // * this is helpful is you want to check validation without triggering the native browser constraint violation warning.\n // */\n checkValidity: (input: FormControl) => boolean;\n /** A function that sets the form control's value */\n setValue: (input: FormControl, value: unknown) => void;\n /**\n * An array of event names to listen to. When all events in the list are emitted, the control will receive validity\n * states such as user-valid and user-invalid.user interacted validity states. */\n assumeInteractionOn: string[];\n}\n\n/** A reactive controller to allow form controls to participate in form submission, validation, etc. */\nexport class FormControlController implements ReactiveController {\n host: FormControl & ReactiveControllerHost;\n\n form?: HTMLFormElement | null;\n\n options: FormControlControllerOptions;\n\n submittedOnce: boolean = false;\n\n constructor(host: ReactiveControllerHost & FormControl, options?: Partial<FormControlControllerOptions>) {\n (this.host = host).addController(this);\n this.options = {\n form: (input) => {\n // If there's a form attribute, use it to find the target form by id\n // Controls may not always reflect the 'form' property. For example, `<it-button>` doesn't reflect.\n const formId = input.form;\n\n if (formId) {\n const root = input.getRootNode() as Document | ShadowRoot | HTMLElement;\n const form = root.querySelector(`#${formId}`);\n\n if (form) {\n return form as HTMLFormElement;\n }\n }\n\n return input.closest('form');\n },\n name: (input) => input.name,\n value: (input) => input.value,\n disabled: (input) => input.disabled ?? false,\n reportValidity: (input: FormControl) =>\n typeof input.reportValidity === 'function' ? input.reportValidity() : true,\n checkValidity: (input: FormControl) => (typeof input.checkValidity === 'function' ? input.checkValidity() : true),\n setValue: (input, value) => {\n // eslint-disable-next-line no-param-reassign\n input.value = value as string;\n },\n assumeInteractionOn: ['it-input'],\n ...options,\n };\n }\n\n hostConnected() {\n const form = this.options.form(this.host);\n if (form) {\n this.attachForm(form);\n }\n\n // Listen for interactions\n interactions.set(this.host, []);\n this.options.assumeInteractionOn.forEach((event) => {\n this.host.addEventListener(event, this.handleInteraction);\n });\n }\n\n hostDisconnected() {\n this.detachForm();\n\n // Clean up interactions\n interactions.delete(this.host);\n this.options.assumeInteractionOn.forEach((event) => {\n this.host.removeEventListener(event, this.handleInteraction);\n });\n }\n\n hostUpdated() {\n const form = this.options.form(this.host);\n\n // Detach if the form no longer exists\n if (!form) {\n this.detachForm();\n }\n\n // If the form has changed, reattach it\n if (form && this.form !== form) {\n this.detachForm();\n this.attachForm(form);\n }\n\n if (this.host.hasUpdated) {\n this.setValidity(this.host.validity.valid);\n }\n }\n\n private attachForm(form?: HTMLFormElement) {\n if (form) {\n this.form = form;\n\n // Add this element to the form's collection\n if (formCollections.has(this.form)) {\n formCollections.get(this.form)!.add(this.host);\n } else {\n formCollections.set(this.form, new Set<FormControl>([this.host]));\n }\n\n this.form.addEventListener('formdata', this.handleFormData);\n this.form.addEventListener('submit', this.handleFormSubmit);\n this.form.addEventListener('reset', this.handleFormReset);\n\n // Overload the form's reportValidity() method so it looks at FormControl\n if (!reportValidityOverloads.has(this.form)) {\n reportValidityOverloads.set(this.form, this.form.reportValidity);\n this.form.reportValidity = () => this.reportFormValidity();\n }\n\n // Overload the form's checkValidity() method so it looks at FormControl\n if (!checkValidityOverloads.has(this.form)) {\n checkValidityOverloads.set(this.form, this.form.checkValidity);\n this.form.checkValidity = () => this.checkFormValidity();\n }\n } else {\n this.form = undefined;\n }\n }\n\n private detachForm() {\n if (!this.form) return;\n\n const formCollection = formCollections.get(this.form);\n\n if (!formCollection) {\n return;\n }\n this.submittedOnce = false;\n\n // Remove this host from the form's collection\n formCollection.delete(this.host);\n\n // Check to make sure there's no other form controls in the collection. If we do this\n // without checking if any other controls are still in the collection, then we will wipe out the\n // validity checks for all other elements.\n // see: https://github.com/shoelace-style/shoelace/issues/1703\n if (formCollection.size <= 0) {\n this.form.removeEventListener('formdata', this.handleFormData);\n this.form.removeEventListener('submit', this.handleFormSubmit);\n this.form.removeEventListener('reset', this.handleFormReset);\n\n // Remove the overload and restore the original method\n if (reportValidityOverloads.has(this.form)) {\n this.form.reportValidity = reportValidityOverloads.get(this.form)!;\n reportValidityOverloads.delete(this.form);\n }\n\n if (checkValidityOverloads.has(this.form)) {\n this.form.checkValidity = checkValidityOverloads.get(this.form)!;\n checkValidityOverloads.delete(this.form);\n }\n\n // So it looks weird here to not always set the form to undefined. But I _think_ if we unattach this.form here,\n // we end up in this fun spot where future validity checks don't have a reference to the form validity handler.\n // 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.\n this.form = undefined;\n }\n }\n\n private handleFormData = (event: FormDataEvent) => {\n // console.log('handleFormData');\n const disabled = this.options.disabled(this.host);\n const name = this.options.name(this.host);\n const value = this.options.value(this.host);\n const tagName = this.host.tagName.toLowerCase();\n\n // For buttons, we only submit the value if they were the submitter. This is currently done in doAction() by\n // injecting the name/value on a temporary button, so we can just skip them here.\n const isButton = tagName === 'it-button';\n\n if (\n this.host.isConnected &&\n !disabled &&\n !isButton &&\n typeof name === 'string' &&\n name.length > 0 &&\n typeof value !== 'undefined'\n ) {\n switch (tagName) {\n case 'it-radio':\n if ((this.host as any).checked) {\n event.formData.append(name, value as string);\n }\n break;\n case 'it-checkbox':\n if ((this.host as any).checked) {\n if (event.formData.getAll(name).indexOf(value as string) < 0) {\n // handle group checkbox\n event.formData.append(name, value as string);\n }\n }\n break;\n case 'it-checkbox-group':\n // non settare valori in formData, perchè ogni singola checkbox setta il suo valore\n break;\n default:\n if (Array.isArray(value)) {\n (value as unknown[]).forEach((val) => {\n event.formData.append(name, (val as string | number | boolean).toString());\n });\n } else {\n event.formData.append(name, (value as string | number | boolean).toString());\n }\n }\n }\n };\n\n private handleFormSubmit = (event: Event) => {\n const disabled = this.options.disabled(this.host);\n const reportValidity = this.options.reportValidity;\n\n // Update the interacted state for all controls when the form is submitted\n if (this.form && !this.form.noValidate) {\n formCollections.get(this.form)?.forEach((control) => {\n this.setUserInteracted(control, true);\n });\n }\n\n const resReportValidity = reportValidity(this.host);\n\n if (this.form && !this.form.noValidate && !disabled && !resReportValidity) {\n event.preventDefault();\n // event.stopImmediatePropagation(); // se lo attiviamo, valida un campo alla volta\n\n // Scroll al primo controllo non valido\n const formControls = formCollections.get(this.form);\n if (formControls) {\n for (const control of formControls) {\n if (!control.validity?.valid) {\n // Scroll smooth verso il controllo non valido\n control.scrollIntoView({\n behavior: 'smooth',\n block: 'center',\n });\n break;\n }\n }\n }\n }\n this.submittedOnce = true;\n };\n\n private handleFormReset = () => {\n this.options.setValue(this.host, '');\n this.submittedOnce = false;\n this.setUserInteracted(this.host, false);\n interactions.set(this.host, []);\n };\n\n private handleInteraction = (event: Event) => {\n const emittedEvents = interactions.get(this.host)!;\n\n if (!emittedEvents.includes(event.type)) {\n emittedEvents.push(event.type);\n }\n\n // Mark it as user-interacted as soon as all associated events have been emitted\n if (emittedEvents.length === this.options.assumeInteractionOn.length) {\n this.setUserInteracted(this.host, true);\n }\n };\n\n private checkFormValidity = () => {\n // console.log('checkFormValidity');\n //\n // This is very similar to the `reportFormValidity` function, but it does not trigger native constraint validation\n // Allow the user to simply check if the form is valid and handling validity in their own way.\n //\n // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger\n // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't\n // be necessary once we can use ElementInternals.\n //\n // Note that we're also honoring the form's novalidate attribute.\n //\n if (this.form && !this.form.noValidate) {\n // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom\n // elements that support the constraint validation API.\n const elements = this.form.querySelectorAll<HTMLInputElement>('*');\n\n for (const element of elements) {\n if (typeof element.checkValidity === 'function') {\n if (!element.checkValidity()) {\n return false;\n }\n }\n }\n }\n\n return true;\n };\n\n private reportFormValidity = () => {\n // console.log('reportFormValidity');\n //\n // FormControl work hard to act like regular form controls. They support the Constraint Validation API\n // and its associated methods such as setCustomValidity() and reportValidity(). However, the HTMLFormElement also\n // has a reportValidity() method that will trigger validation on all child controls. Since we're not yet using\n // ElementInternals, we need to overload this method so it looks for any element with the reportValidity() method.\n //\n // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger\n // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't\n // be necessary once we can use ElementInternals.\n //\n // Note that we're also honoring the form's novalidate attribute.\n //\n if (this.form && !this.form.noValidate) {\n // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom\n // elements that support the constraint validation API.\n const elements = this.form.querySelectorAll<HTMLInputElement>('*');\n\n for (const element of elements) {\n if (typeof element.reportValidity === 'function') {\n if (!element.reportValidity()) {\n return false;\n }\n }\n }\n }\n\n return true;\n };\n\n // eslint-disable-next-line class-methods-use-this\n private setUserInteracted(el: FormControl, hasInteracted: boolean) {\n if (hasInteracted) {\n userInteractedControls.add(el);\n } else {\n userInteractedControls.delete(el);\n }\n\n el.requestUpdate();\n }\n\n private doAction(type: 'submit' | 'reset', submitter?: HTMLInputElement | any) {\n // console.log('doaction', type);\n if (this.form) {\n const button = document.createElement('button');\n button.type = type;\n button.style.position = 'absolute';\n button.style.width = '0';\n button.style.height = '0';\n button.style.clipPath = 'inset(50%)';\n button.style.overflow = 'hidden';\n button.style.whiteSpace = 'nowrap';\n\n // Pass name, value, and form attributes through to the temporary button\n if (submitter) {\n button.name = submitter.name;\n button.value = submitter.value;\n\n ['formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget'].forEach((attr) => {\n if (submitter.hasAttribute(attr)) {\n button.setAttribute(attr, submitter.getAttribute(attr)!);\n }\n });\n }\n\n this.form.append(button);\n button.click();\n button.remove();\n }\n }\n\n /** Returns the associated `<form>` element, if one exists. */\n getForm() {\n return this.form ?? null;\n }\n\n /** Resets the form, restoring all the control to their default value */\n reset(submitter?: HTMLInputElement | any) {\n this.doAction('reset', submitter);\n }\n\n /** Submits the form, triggering validation and form data injection. */\n submit(submitter?: HTMLInputElement | any) {\n // Calling form.submit() bypasses the submit event and constraint validation. To prevent this, we can inject a\n // native submit button into the form, \"click\" it, then remove it to simulate a standard form submission.\n this.doAction('submit', submitter);\n }\n\n /**\n * Synchronously sets the form control's validity. Call this when you know the future validity but need to update\n * the host element immediately, i.e. before Lit updates the component in the next update.\n */\n setValidity(isValid: boolean) {\n const host = this.host;\n const hasInteracted = Boolean(userInteractedControls.has(host));\n const required = Boolean(host.required);\n\n //\n // We're mapping the following \"states\" to data attributes. In the future, we can use ElementInternals.states to\n // create a similar mapping, but instead of [data-invalid] it will look like :--invalid.\n //\n // See this RFC for more details: https://github.com/shoelace-style/shoelace/issues/1011\n //\n host.toggleAttribute('data-required', required);\n host.toggleAttribute('data-optional', !required);\n host.toggleAttribute('data-invalid', !isValid);\n host.toggleAttribute('data-valid', isValid);\n host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);\n host.toggleAttribute('data-user-valid', isValid && hasInteracted);\n }\n\n userInteracted() {\n const hasInteracted = Boolean(userInteractedControls.has(this.host));\n\n return hasInteracted;\n }\n\n /**\n * Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything\n * that affects constraint validation changes so the component receives the correct validity states.\n */\n updateValidity() {\n const host = this.host;\n this.setValidity(host.validity.valid);\n }\n\n /**\n * Dispatches a non-bubbling, cancelable custom event of type `it-invalid`.\n * If the `it-invalid` event will be cancelled then the original `invalid`\n * event (which may have been passed as argument) will also be cancelled.\n * If no original `invalid` event has been passed then the `it-invalid`\n * event will be cancelled before being dispatched.\n */\n emitInvalidEvent(originalInvalidEvent?: Event) {\n const itInvalidEvent = new CustomEvent<Record<PropertyKey, never>>('it-invalid', {\n bubbles: false,\n composed: false,\n cancelable: true,\n detail: {},\n });\n\n if (!originalInvalidEvent) {\n itInvalidEvent.preventDefault();\n }\n\n if (!this.host.dispatchEvent(itInvalidEvent)) {\n originalInvalidEvent?.preventDefault();\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"it.d.ts","sourceRoot":"","sources":["../../../../src/form/locales/it.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,QAAA,MAAM,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"it.d.ts","sourceRoot":"","sources":["../../../../src/form/locales/it.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,QAAA,MAAM,WAAW,EAAE,kBAUlB,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -3,6 +3,7 @@ const translation = {
|
|
|
3
3
|
$name: 'Italiano',
|
|
4
4
|
$dir: 'ltr',
|
|
5
5
|
validityRequired: 'Questo campo è obbligatorio.',
|
|
6
|
+
validityGroupRequired: "Scegli almeno un'opzione",
|
|
6
7
|
validityPattern: 'Il valore non corrisponde al formato richiesto.',
|
|
7
8
|
validityMinlength: 'Il valore deve essere lungo almeno {minlength} caratteri.',
|
|
8
9
|
validityMaxlength: 'Il valore deve essere lungo al massimo {maxlength} caratteri.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"it.js","sourceRoot":"","sources":["../../../../src/form/locales/it.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAuB;IACtC,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,UAAU;IACjB,IAAI,EAAE,KAAK;IAEX,gBAAgB,EAAE,8BAA8B;IAChD,eAAe,EAAE,iDAAiD;IAClE,iBAAiB,EAAE,2DAA2D;IAC9E,iBAAiB,EAAE,+DAA+D;CACnF,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import type { DefaultTranslation } from '@italia/i18n';\n\nconst translation: DefaultTranslation = {\n $code: 'it',\n $name: 'Italiano',\n $dir: 'ltr',\n\n validityRequired: 'Questo campo è obbligatorio.',\n validityPattern: 'Il valore non corrisponde al formato richiesto.',\n validityMinlength: 'Il valore deve essere lungo almeno {minlength} caratteri.',\n validityMaxlength: 'Il valore deve essere lungo al massimo {maxlength} caratteri.',\n};\n\nexport default translation;\n"]}
|
|
1
|
+
{"version":3,"file":"it.js","sourceRoot":"","sources":["../../../../src/form/locales/it.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAuB;IACtC,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,UAAU;IACjB,IAAI,EAAE,KAAK;IAEX,gBAAgB,EAAE,8BAA8B;IAChD,qBAAqB,EAAE,0BAA0B;IACjD,eAAe,EAAE,iDAAiD;IAClE,iBAAiB,EAAE,2DAA2D;IAC9E,iBAAiB,EAAE,+DAA+D;CACnF,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import type { DefaultTranslation } from '@italia/i18n';\n\nconst translation: DefaultTranslation = {\n $code: 'it',\n $name: 'Italiano',\n $dir: 'ltr',\n\n validityRequired: 'Questo campo è obbligatorio.',\n validityGroupRequired: \"Scegli almeno un'opzione\",\n validityPattern: 'Il valore non corrisponde al formato richiesto.',\n validityMinlength: 'Il valore deve essere lungo almeno {minlength} caratteri.',\n validityMaxlength: 'Il valore deve essere lungo al massimo {maxlength} caratteri.',\n};\n\nexport default translation;\n"]}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -2,6 +2,14 @@ import TrackFocus from './utils/track-focus.js';
|
|
|
2
2
|
import setAttributes from './directives/setAttributes.js';
|
|
3
3
|
import AriaKeyboardListController from './controllers/aria-keyboard-list-controller.js';
|
|
4
4
|
import { StoryFormControlMethodAndProps } from './stories/formControlReusableStories.js';
|
|
5
|
+
import { CollapsibleOrHiddenContentGuidelines } from './stories/reusableUsageGuidelinesStories.js';
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
_itAnalytics: {
|
|
9
|
+
version: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
5
13
|
export { TrackFocus, setAttributes, AriaKeyboardListController };
|
|
6
14
|
export type { AriaKeyboardConfig } from './controllers/aria-keyboard-list-controller.js';
|
|
7
15
|
export { RovingTabindexController } from './controllers/roving-tabindex-controller.js';
|
|
@@ -14,5 +22,5 @@ export { formCollections, FormControlControllerOptions, FormControlController }
|
|
|
14
22
|
export { cookies } from './utils/cookies.js';
|
|
15
23
|
export type Constructor<T = {}> = new (...args: any[]) => T;
|
|
16
24
|
export { WindowManager, type ScrollCallback, type ScrollState } from './window-manager.js';
|
|
17
|
-
export { StoryFormControlMethodAndProps };
|
|
25
|
+
export { StoryFormControlMethodAndProps, CollapsibleOrHiddenContentGuidelines };
|
|
18
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,0BAA0B,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,0BAA0B,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AACzF,OAAO,EAAE,oCAAoC,EAAE,MAAM,6CAA6C,CAAC;AAEnG,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,YAAY,EAAE;YACZ,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;KACH;CACF;AAUD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,0BAA0B,EAAE,CAAC;AACjE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AACvF,YAAY,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,+BAA+B,EAC/B,KAAK,2BAA2B,GACjC,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AAEnF,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACjH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EAAE,8BAA8B,EAAE,oCAAoC,EAAE,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -2,6 +2,14 @@ import TrackFocus from './utils/track-focus.js';
|
|
|
2
2
|
import setAttributes from './directives/setAttributes.js';
|
|
3
3
|
import AriaKeyboardListController from './controllers/aria-keyboard-list-controller.js';
|
|
4
4
|
import { StoryFormControlMethodAndProps } from './stories/formControlReusableStories.js';
|
|
5
|
+
import { CollapsibleOrHiddenContentGuidelines } from './stories/reusableUsageGuidelinesStories.js';
|
|
6
|
+
if (typeof window !== 'undefined') {
|
|
7
|
+
window._itAnalytics = window._itAnalytics || {};
|
|
8
|
+
window._itAnalytics = {
|
|
9
|
+
...window._itAnalytics,
|
|
10
|
+
version: '1.0.0-alpha.4',
|
|
11
|
+
};
|
|
12
|
+
}
|
|
5
13
|
export { TrackFocus, setAttributes, AriaKeyboardListController };
|
|
6
14
|
export { RovingTabindexController } from './controllers/roving-tabindex-controller.js';
|
|
7
15
|
export { BaseComponent, BaseLocalizedComponent, } from './base-component/base-component.js';
|
|
@@ -11,5 +19,5 @@ export { FormControl } from './form/form-control.js';
|
|
|
11
19
|
export { formCollections, FormControlController } from './form/form-controller.js';
|
|
12
20
|
export { cookies } from './utils/cookies.js';
|
|
13
21
|
export { WindowManager } from './window-manager.js';
|
|
14
|
-
export { StoryFormControlMethodAndProps };
|
|
22
|
+
export { StoryFormControlMethodAndProps, CollapsibleOrHiddenContentGuidelines };
|
|
15
23
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,0BAA0B,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,0BAA0B,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AACzF,OAAO,EAAE,oCAAoC,EAAE,MAAM,6CAA6C,CAAC;AAUnG,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;IAChD,MAAM,CAAC,YAAY,GAAG;QACpB,GAAG,MAAM,CAAC,YAAY;QACtB,OAAO,EAAE,eAAe;KACzB,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,0BAA0B,EAAE,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AAEvF,OAAO,EACL,aAAa,EAGb,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,+BAA+B,GAEhC,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AAEnF,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAgC,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACjH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAyC,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EAAE,8BAA8B,EAAE,oCAAoC,EAAE,CAAC","sourcesContent":["import TrackFocus from './utils/track-focus.js';\n\nimport setAttributes from './directives/setAttributes.js';\nimport AriaKeyboardListController from './controllers/aria-keyboard-list-controller.js';\nimport { StoryFormControlMethodAndProps } from './stories/formControlReusableStories.js';\nimport { CollapsibleOrHiddenContentGuidelines } from './stories/reusableUsageGuidelinesStories.js';\n\ndeclare global {\n interface Window {\n _itAnalytics: {\n version: string;\n };\n }\n}\n\nif (typeof window !== 'undefined') {\n window._itAnalytics = window._itAnalytics || {};\n window._itAnalytics = {\n ...window._itAnalytics,\n version: '1.0.0-alpha.4',\n };\n}\n\nexport { TrackFocus, setAttributes, AriaKeyboardListController };\nexport type { AriaKeyboardConfig } from './controllers/aria-keyboard-list-controller.js';\nexport { RovingTabindexController } from './controllers/roving-tabindex-controller.js';\nexport type { RovingTabindexConfig } from './controllers/roving-tabindex-controller.js';\nexport {\n BaseComponent,\n BaseComponentInterface,\n BaseComponentType,\n BaseLocalizedComponent,\n} from './base-component/base-component.js';\nexport {\n AriaKeyboardAccordionController,\n type AriaKeyboardAccordionConfig,\n} from './controllers/aria-keyboard-accordion-controller.js';\nexport { CollapseAnimationController } from './controllers/collapse-controller.js';\n\nexport { FormControl } from './form/form-control.js';\nexport { formCollections, FormControlControllerOptions, FormControlController } from './form/form-controller.js';\nexport { cookies } from './utils/cookies.js';\nexport type Constructor<T = {}> = new (...args: any[]) => T;\nexport { WindowManager, type ScrollCallback, type ScrollState } from './window-manager.js';\n\nexport { StoryFormControlMethodAndProps, CollapsibleOrHiddenContentGuidelines };\n"]}
|
|
@@ -94,6 +94,7 @@ declare const ValidityMixin: <T extends Constructor<HTMLElement>>(Base: T) => (a
|
|
|
94
94
|
accessKey: string;
|
|
95
95
|
readonly accessKeyLabel: string;
|
|
96
96
|
autocapitalize: string;
|
|
97
|
+
autocorrect: boolean;
|
|
97
98
|
dir: string;
|
|
98
99
|
draggable: boolean;
|
|
99
100
|
hidden: boolean;
|
|
@@ -201,6 +202,8 @@ declare const ValidityMixin: <T extends Constructor<HTMLElement>>(Base: T) => (a
|
|
|
201
202
|
setPointerCapture(pointerId: number): void;
|
|
202
203
|
toggleAttribute(qualifiedName: string, force?: boolean): boolean;
|
|
203
204
|
webkitMatchesSelector(selectors: string): boolean;
|
|
205
|
+
get textContent(): string;
|
|
206
|
+
set textContent(value: string | null);
|
|
204
207
|
readonly baseURI: string;
|
|
205
208
|
readonly childNodes: NodeListOf<ChildNode>;
|
|
206
209
|
readonly firstChild: ChildNode | null;
|
|
@@ -213,7 +216,6 @@ declare const ValidityMixin: <T extends Constructor<HTMLElement>>(Base: T) => (a
|
|
|
213
216
|
readonly parentElement: HTMLElement | null;
|
|
214
217
|
readonly parentNode: ParentNode | null;
|
|
215
218
|
readonly previousSibling: ChildNode | null;
|
|
216
|
-
textContent: string | null;
|
|
217
219
|
appendChild<T_1 extends Node>(node: T_1): T_1;
|
|
218
220
|
cloneNode(subtree?: boolean): Node;
|
|
219
221
|
compareDocumentPosition(other: Node): number;
|
|
@@ -248,6 +250,7 @@ declare const ValidityMixin: <T extends Constructor<HTMLElement>>(Base: T) => (a
|
|
|
248
250
|
readonly DOCUMENT_POSITION_CONTAINED_BY: 16;
|
|
249
251
|
readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: 32;
|
|
250
252
|
dispatchEvent(event: Event): boolean;
|
|
253
|
+
ariaActiveDescendantElement: Element | null;
|
|
251
254
|
ariaAtomic: string | null;
|
|
252
255
|
ariaAutoComplete: string | null;
|
|
253
256
|
ariaBrailleLabel: string | null;
|
|
@@ -258,21 +261,28 @@ declare const ValidityMixin: <T extends Constructor<HTMLElement>>(Base: T) => (a
|
|
|
258
261
|
ariaColIndex: string | null;
|
|
259
262
|
ariaColIndexText: string | null;
|
|
260
263
|
ariaColSpan: string | null;
|
|
264
|
+
ariaControlsElements: ReadonlyArray<Element> | null;
|
|
261
265
|
ariaCurrent: string | null;
|
|
266
|
+
ariaDescribedByElements: ReadonlyArray<Element> | null;
|
|
262
267
|
ariaDescription: string | null;
|
|
268
|
+
ariaDetailsElements: ReadonlyArray<Element> | null;
|
|
263
269
|
ariaDisabled: string | null;
|
|
270
|
+
ariaErrorMessageElements: ReadonlyArray<Element> | null;
|
|
264
271
|
ariaExpanded: string | null;
|
|
272
|
+
ariaFlowToElements: ReadonlyArray<Element> | null;
|
|
265
273
|
ariaHasPopup: string | null;
|
|
266
274
|
ariaHidden: string | null;
|
|
267
275
|
ariaInvalid: string | null;
|
|
268
276
|
ariaKeyShortcuts: string | null;
|
|
269
277
|
ariaLabel: string | null;
|
|
278
|
+
ariaLabelledByElements: ReadonlyArray<Element> | null;
|
|
270
279
|
ariaLevel: string | null;
|
|
271
280
|
ariaLive: string | null;
|
|
272
281
|
ariaModal: string | null;
|
|
273
282
|
ariaMultiLine: string | null;
|
|
274
283
|
ariaMultiSelectable: string | null;
|
|
275
284
|
ariaOrientation: string | null;
|
|
285
|
+
ariaOwnsElements: ReadonlyArray<Element> | null;
|
|
276
286
|
ariaPlaceholder: string | null;
|
|
277
287
|
ariaPosInSet: string | null;
|
|
278
288
|
ariaPressed: string | null;
|
|
@@ -330,18 +340,19 @@ declare const ValidityMixin: <T extends Constructor<HTMLElement>>(Base: T) => (a
|
|
|
330
340
|
onanimationend: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null;
|
|
331
341
|
onanimationiteration: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null;
|
|
332
342
|
onanimationstart: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null;
|
|
333
|
-
onauxclick: ((this: GlobalEventHandlers, ev:
|
|
343
|
+
onauxclick: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
334
344
|
onbeforeinput: ((this: GlobalEventHandlers, ev: InputEvent) => any) | null;
|
|
335
|
-
|
|
345
|
+
onbeforematch: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
346
|
+
onbeforetoggle: ((this: GlobalEventHandlers, ev: ToggleEvent) => any) | null;
|
|
336
347
|
onblur: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null;
|
|
337
348
|
oncancel: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
338
349
|
oncanplay: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
339
350
|
oncanplaythrough: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
340
351
|
onchange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
341
|
-
onclick: ((this: GlobalEventHandlers, ev:
|
|
352
|
+
onclick: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
342
353
|
onclose: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
343
354
|
oncontextlost: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
344
|
-
oncontextmenu: ((this: GlobalEventHandlers, ev:
|
|
355
|
+
oncontextmenu: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
345
356
|
oncontextrestored: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
346
357
|
oncopy: ((this: GlobalEventHandlers, ev: ClipboardEvent) => any) | null;
|
|
347
358
|
oncuechange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
@@ -389,6 +400,7 @@ declare const ValidityMixin: <T extends Constructor<HTMLElement>>(Base: T) => (a
|
|
|
389
400
|
onpointermove: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
390
401
|
onpointerout: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
391
402
|
onpointerover: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
403
|
+
onpointerrawupdate: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
392
404
|
onpointerup: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
393
405
|
onprogress: ((this: GlobalEventHandlers, ev: ProgressEvent) => any) | null;
|
|
394
406
|
onratechange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
@@ -407,7 +419,7 @@ declare const ValidityMixin: <T extends Constructor<HTMLElement>>(Base: T) => (a
|
|
|
407
419
|
onsubmit: ((this: GlobalEventHandlers, ev: SubmitEvent) => any) | null;
|
|
408
420
|
onsuspend: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
409
421
|
ontimeupdate: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
410
|
-
ontoggle: ((this: GlobalEventHandlers, ev:
|
|
422
|
+
ontoggle: ((this: GlobalEventHandlers, ev: ToggleEvent) => any) | null;
|
|
411
423
|
ontouchcancel?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
412
424
|
ontouchend?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
413
425
|
ontouchmove?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validity.d.ts","sourceRoot":"","sources":["../../../src/mixins/validity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C;;;;;;;GAOG;AAEH;;GAEG;AACH,oBAAY,iBAAiB;IAC3B;;OAEG;IACH,QAAQ,KAAK;IAEb;;OAEG;IACH,OAAO,YAAY;IAEnB;;OAEG;IACH,cAAc,aAAa;IAC3B;;OAEG;IACH,OAAO,YAAY;IAEnB;;OAEG;IACH,SAAS,cAAc;CACxB;AAED;;;GAGG;AACH,QAAA,MAAM,aAAa,GAAI,CAAC,SAAS,WAAW,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAI9D;;;;OAIG;+BACwB,MAAM,gBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAUvE;;OAEG;aACe,OAAO;IAEzB;;OAEG;cACgB,OAAO;IAE1B;;OAEG;qBACuB,MAAM;IAEhC;;OAEG;YACc,MAAM;IAE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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAM5C,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formControlReusableStories.d.ts","sourceRoot":"","sources":["../../../src/stories/formControlReusableStories.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,8BAA8B,GAAI;;;;;CAK9C;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"formControlReusableStories.d.ts","sourceRoot":"","sources":["../../../src/stories/formControlReusableStories.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,8BAA8B,GAAI;;;;;CAK9C;;;;;;;;;;;;CA4DA,CAAC"}
|
|
@@ -9,7 +9,8 @@ export const StoryFormControlMethodAndProps = ({ otherProps = '', otherMethods =
|
|
|
9
9
|
viewMode: 'docs', // assicura che si apra la tab Docs anziché Canvas
|
|
10
10
|
docs: {
|
|
11
11
|
description: {
|
|
12
|
-
story: `
|
|
12
|
+
story: `
|
|
13
|
+
Il componente espone delle proprietà, metodi, ed eventi, utili per eventuali interazioni via js.
|
|
13
14
|
|
|
14
15
|
\`\`\`html
|
|
15
16
|
<${componentName} ... id="myinput"></${componentName}>
|
|
@@ -1 +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
|
|
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;;;;GAId,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: `\nIl componente espone delle proprietà, metodi, ed 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,13 @@
|
|
|
1
|
+
export declare const CollapsibleOrHiddenContentGuidelines: () => {
|
|
2
|
+
name: string;
|
|
3
|
+
tags: string[];
|
|
4
|
+
render: () => import("lit").TemplateResult<1>;
|
|
5
|
+
parameters: {
|
|
6
|
+
docs: {
|
|
7
|
+
description: {
|
|
8
|
+
story: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=reusableUsageGuidelinesStories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reusableUsageGuidelinesStories.d.ts","sourceRoot":"","sources":["../../../src/stories/reusableUsageGuidelinesStories.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oCAAoC;;;;;;;;;;;CAmChD,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* eslint-disable arrow-body-style */
|
|
2
|
+
import { html } from 'lit';
|
|
3
|
+
export const CollapsibleOrHiddenContentGuidelines = () => {
|
|
4
|
+
return {
|
|
5
|
+
name: 'Differenza tra Collapse, Accordion e Tabs',
|
|
6
|
+
tags: ['!dev', '!autodocs'],
|
|
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: `
|
|
13
|
+
#### Differenza tra Collapse, Accordion e Tabs
|
|
14
|
+
I componenti Accordion, Tabs e Collapse funzionano tutti nascondendo sezioni di contenuto che l'utente può scegliere di visualizzare. Evitare di usare questi componenti l'uno all'interno dell'altro.
|
|
15
|
+
|
|
16
|
+
Se decidi di usare uno di questi componenti, considera quanto segue:
|
|
17
|
+
|
|
18
|
+
- L'utente ha bisogno di visualizzare più di una sezione alla volta? L'accordion può mostrare più sezioni contemporaneamente, a differenza dei tabs.
|
|
19
|
+
|
|
20
|
+
- L'utente deve passare rapidamente tra le sezioni? I tabs permettono di cambiare contenuto senza spostare le altre sezioni nella pagina, a differenza dell'accordion.
|
|
21
|
+
|
|
22
|
+
- Ci sono molte sezioni di contenuto? L'accordion può contenere più sezioni perché sono disposte verticalmente, mentre i tabs sono disposti orizzontalmente.
|
|
23
|
+
|
|
24
|
+
- Ci sono solo uno o due contenuti brevi e meno importanti? Il componente Collapse è più adatto perché visivamente più piccolo e meno prominente rispetto a un accordion o ai tabs.
|
|
25
|
+
|
|
26
|
+
<br/>
|
|
27
|
+
|
|
28
|
+
| Componente | Contenuti multipli | Visibilità | Esclusività | Uso tipico | Esempi |
|
|
29
|
+
|----------|--------------------|-------------|--------------|-------------|---------|
|
|
30
|
+
| **Collapse** | No | Singolo contenuto mostrato o nascosto | N/A | Mostrare o nascondere dettagli secondari | "Mostra dettagli", "Visualizza termini" |
|
|
31
|
+
| **Accordion** | Sì | Più sezioni espandibili | Solo una aperta alla volta *(consigliato)* | Raggruppare contenuti correlati in blocchi espandibili | FAQ, elenchi informativi |
|
|
32
|
+
| **Tabs** | Sì | Una sezione visibile alla volta | Sempre esclusiva | Organizzare viste equivalenti o alternative | Schede di impostazioni, pannelli di dati |
|
|
33
|
+
`,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=reusableUsageGuidelinesStories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reusableUsageGuidelinesStories.js","sourceRoot":"","sources":["../../../src/stories/reusableUsageGuidelinesStories.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAE3B,MAAM,CAAC,MAAM,oCAAoC,GAAG,GAAG,EAAE;IACvD,OAAO;QACL,IAAI,EAAE,2CAA2C;QACjD,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC;QAC3B,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAA,kCAAkC;QACpD,UAAU,EAAE;YACV,uEAAuE;YACvE,IAAI,EAAE;gBACJ,WAAW,EAAE;oBACX,KAAK,EAAE;;;;;;;;;;;;;;;;;;;;;CAqBhB;iBACQ;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable arrow-body-style */\nimport { html } from 'lit';\n\nexport const CollapsibleOrHiddenContentGuidelines = () => {\n return {\n name: 'Differenza tra Collapse, Accordion e Tabs',\n tags: ['!dev', '!autodocs'],\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: `\n#### Differenza tra Collapse, Accordion e Tabs\nI componenti Accordion, Tabs e Collapse funzionano tutti nascondendo sezioni di contenuto che l'utente può scegliere di visualizzare. Evitare di usare questi componenti l'uno all'interno dell'altro.\n\nSe decidi di usare uno di questi componenti, considera quanto segue:\n\n- L'utente ha bisogno di visualizzare più di una sezione alla volta? L'accordion può mostrare più sezioni contemporaneamente, a differenza dei tabs.\n\n- L'utente deve passare rapidamente tra le sezioni? I tabs permettono di cambiare contenuto senza spostare le altre sezioni nella pagina, a differenza dell'accordion.\n\n- Ci sono molte sezioni di contenuto? L'accordion può contenere più sezioni perché sono disposte verticalmente, mentre i tabs sono disposti orizzontalmente.\n\n- Ci sono solo uno o due contenuti brevi e meno importanti? Il componente Collapse è più adatto perché visivamente più piccolo e meno prominente rispetto a un accordion o ai tabs.\n\n<br/>\n\n| Componente | Contenuti multipli | Visibilità | Esclusività | Uso tipico | Esempi |\n|----------|--------------------|-------------|--------------|-------------|---------|\n| **Collapse** | No | Singolo contenuto mostrato o nascosto | N/A | Mostrare o nascondere dettagli secondari | \"Mostra dettagli\", \"Visualizza termini\" |\n| **Accordion** | Sì | Più sezioni espandibili | Solo una aperta alla volta *(consigliato)* | Raggruppare contenuti correlati in blocchi espandibili | FAQ, elenchi informativi |\n| **Tabs** | Sì | Una sezione visibile alla volta | Sempre esclusiva | Organizzare viste equivalenti o alternative | Schede di impostazioni, pannelli di dati |\n`,\n },\n },\n },\n };\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@italia/globals",
|
|
3
3
|
"description": "Utilities per i Web components del Design System .italia",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.0.0-alpha.4",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@floating-ui/dom": "^1.7.1",
|
|
36
36
|
"clsx": "^2.1.1",
|
|
37
37
|
"lit": "^3.3.0",
|
|
38
|
-
"@italia/i18n": "^
|
|
38
|
+
"@italia/i18n": "^1.0.0-alpha.4"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@custom-elements-manifest/analyzer": "^0.10.3",
|