@govtechsg/sgds-web-component 3.23.0-rc.1 → 3.23.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/select-element.d.ts +4 -0
- package/base/select-element.js +6 -0
- package/base/select-element.js.map +1 -1
- package/components/Checkbox/index.umd.min.js +3 -3
- package/components/Checkbox/index.umd.min.js.map +1 -1
- package/components/Checkbox/sgds-checkbox-group.d.ts +5 -0
- package/components/Checkbox/sgds-checkbox-group.js +10 -0
- package/components/Checkbox/sgds-checkbox-group.js.map +1 -1
- package/components/Checkbox/sgds-checkbox.d.ts +5 -1
- package/components/Checkbox/sgds-checkbox.js +10 -1
- package/components/Checkbox/sgds-checkbox.js.map +1 -1
- package/components/ComboBox/index.umd.min.js +7 -6
- package/components/ComboBox/index.umd.min.js.map +1 -1
- package/components/ComboBox/sgds-combo-box.d.ts +11 -0
- package/components/ComboBox/sgds-combo-box.js +34 -0
- package/components/ComboBox/sgds-combo-box.js.map +1 -1
- package/components/Datepicker/index.umd.min.js +1 -1
- package/components/Datepicker/index.umd.min.js.map +1 -1
- package/components/Drawer/index.umd.min.js +10 -5
- package/components/Drawer/index.umd.min.js.map +1 -1
- package/components/Drawer/sgds-drawer.js +5 -4
- package/components/Drawer/sgds-drawer.js.map +1 -1
- package/components/FileUpload/index.umd.min.js +1 -1
- package/components/FileUpload/index.umd.min.js.map +1 -1
- package/components/Input/index.umd.min.js +1 -1
- package/components/Input/index.umd.min.js.map +1 -1
- package/components/Mainnav/index.umd.min.js +3 -1
- package/components/Mainnav/index.umd.min.js.map +1 -1
- package/components/Mainnav/sgds-mainnav-dropdown.d.ts +4 -0
- package/components/Mainnav/sgds-mainnav-dropdown.js +6 -0
- package/components/Mainnav/sgds-mainnav-dropdown.js.map +1 -1
- package/components/QuantityToggle/index.umd.min.js +1 -1
- package/components/QuantityToggle/index.umd.min.js.map +1 -1
- package/components/Radio/index.umd.min.js +2 -2
- package/components/Radio/index.umd.min.js.map +1 -1
- package/components/Radio/sgds-radio-group.d.ts +4 -0
- package/components/Radio/sgds-radio-group.js +9 -0
- package/components/Radio/sgds-radio-group.js.map +1 -1
- package/components/Select/index.umd.min.js +3 -3
- package/components/Select/index.umd.min.js.map +1 -1
- package/components/Select/sgds-select.d.ts +4 -0
- package/components/Select/sgds-select.js +10 -1
- package/components/Select/sgds-select.js.map +1 -1
- package/components/Textarea/index.umd.min.js +1 -1
- package/components/Textarea/index.umd.min.js.map +1 -1
- package/components/index.umd.min.js +80 -77
- package/components/index.umd.min.js.map +1 -1
- package/css/fouc.css +2 -2
- package/custom-elements.json +1249 -968
- package/index.umd.min.js +83 -80
- package/index.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/react/base/select-element.cjs.js +6 -0
- package/react/base/select-element.cjs.js.map +1 -1
- package/react/base/select-element.js +6 -0
- package/react/base/select-element.js.map +1 -1
- package/react/checkbox/index.cjs.js +3 -1
- package/react/checkbox/index.cjs.js.map +1 -1
- package/react/checkbox/index.js +3 -1
- package/react/checkbox/index.js.map +1 -1
- package/react/checkbox-group/index.cjs.js +3 -1
- package/react/checkbox-group/index.cjs.js.map +1 -1
- package/react/checkbox-group/index.js +3 -1
- package/react/checkbox-group/index.js.map +1 -1
- package/react/combo-box/index.cjs.js +1 -0
- package/react/combo-box/index.cjs.js.map +1 -1
- package/react/combo-box/index.js +1 -0
- package/react/combo-box/index.js.map +1 -1
- package/react/components/Checkbox/sgds-checkbox-group.cjs.js +10 -0
- package/react/components/Checkbox/sgds-checkbox-group.cjs.js.map +1 -1
- package/react/components/Checkbox/sgds-checkbox-group.js +10 -0
- package/react/components/Checkbox/sgds-checkbox-group.js.map +1 -1
- package/react/components/Checkbox/sgds-checkbox.cjs.js +10 -1
- package/react/components/Checkbox/sgds-checkbox.cjs.js.map +1 -1
- package/react/components/Checkbox/sgds-checkbox.js +10 -1
- package/react/components/Checkbox/sgds-checkbox.js.map +1 -1
- package/react/components/ComboBox/sgds-combo-box.cjs.js +34 -0
- package/react/components/ComboBox/sgds-combo-box.cjs.js.map +1 -1
- package/react/components/ComboBox/sgds-combo-box.js +34 -0
- package/react/components/ComboBox/sgds-combo-box.js.map +1 -1
- package/react/components/Drawer/sgds-drawer.cjs.js +4 -3
- package/react/components/Drawer/sgds-drawer.cjs.js.map +1 -1
- package/react/components/Drawer/sgds-drawer.js +5 -4
- package/react/components/Drawer/sgds-drawer.js.map +1 -1
- package/react/components/Mainnav/sgds-mainnav-dropdown.cjs.js +6 -0
- package/react/components/Mainnav/sgds-mainnav-dropdown.cjs.js.map +1 -1
- package/react/components/Mainnav/sgds-mainnav-dropdown.js +6 -0
- package/react/components/Mainnav/sgds-mainnav-dropdown.js.map +1 -1
- package/react/components/Radio/sgds-radio-group.cjs.js +9 -0
- package/react/components/Radio/sgds-radio-group.cjs.js.map +1 -1
- package/react/components/Radio/sgds-radio-group.js +9 -0
- package/react/components/Radio/sgds-radio-group.js.map +1 -1
- package/react/components/Select/sgds-select.cjs.js +9 -0
- package/react/components/Select/sgds-select.cjs.js.map +1 -1
- package/react/components/Select/sgds-select.js +10 -1
- package/react/components/Select/sgds-select.js.map +1 -1
- package/react/index.cjs.js +8 -8
- package/react/index.d.ts +2 -2
- package/react/index.js +2 -2
- package/react/radio-group/index.cjs.js +3 -1
- package/react/radio-group/index.cjs.js.map +1 -1
- package/react/radio-group/index.js +3 -1
- package/react/radio-group/index.js.map +1 -1
- package/react/select/index.cjs.js +2 -0
- package/react/select/index.cjs.js.map +1 -1
- package/react/select/index.js +2 -0
- package/react/select/index.js.map +1 -1
- package/react/utils/validatorMixin.cjs.js +9 -11
- package/react/utils/validatorMixin.cjs.js.map +1 -1
- package/react/utils/validatorMixin.js +9 -11
- package/react/utils/validatorMixin.js.map +1 -1
- package/types/react.d.ts +48 -21
- package/utils/validatorMixin.js +9 -11
- package/utils/validatorMixin.js.map +1 -1
package/types/react.d.ts
CHANGED
|
@@ -181,20 +181,6 @@ Variants include: `primary`, `accent`, `success`, `danger`, `warning`, `cyan`, `
|
|
|
181
181
|
onSgdsAfterHide?: SgdsEventHandler;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
// ── BreadcrumbItem ─────────────────────────────────────────────────────────────
|
|
185
|
-
|
|
186
|
-
export interface SgdsBreadcrumbItemProps extends SgdsBaseProps {
|
|
187
|
-
/** Indicates the link matches the current location of the page. Programmatically handled by SgdsBreadcrumb to set this prop to true for the last breadcrumb item */
|
|
188
|
-
active?: boolean;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// ── Breadcrumb ─────────────────────────────────────────────────────────────
|
|
192
|
-
|
|
193
|
-
export interface SgdsBreadcrumbProps extends SgdsBaseProps {
|
|
194
|
-
/** The aria-label of nav element within breadcrumb component. */
|
|
195
|
-
ariaLabel?: string;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
184
|
// ── Button ─────────────────────────────────────────────────────────────
|
|
199
185
|
|
|
200
186
|
export interface SgdsButtonProps extends SgdsBaseProps {
|
|
@@ -276,6 +262,20 @@ export interface SgdsCardProps extends SgdsBaseProps {
|
|
|
276
262
|
orientation?: CardOrientation;
|
|
277
263
|
}
|
|
278
264
|
|
|
265
|
+
// ── BreadcrumbItem ─────────────────────────────────────────────────────────────
|
|
266
|
+
|
|
267
|
+
export interface SgdsBreadcrumbItemProps extends SgdsBaseProps {
|
|
268
|
+
/** Indicates the link matches the current location of the page. Programmatically handled by SgdsBreadcrumb to set this prop to true for the last breadcrumb item */
|
|
269
|
+
active?: boolean;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ── Breadcrumb ─────────────────────────────────────────────────────────────
|
|
273
|
+
|
|
274
|
+
export interface SgdsBreadcrumbProps extends SgdsBaseProps {
|
|
275
|
+
/** The aria-label of nav element within breadcrumb component. */
|
|
276
|
+
ariaLabel?: string;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
279
|
// ── CheckboxGroup ─────────────────────────────────────────────────────────────
|
|
280
280
|
|
|
281
281
|
export interface SgdsCheckboxGroupProps extends SgdsBaseProps {
|
|
@@ -289,9 +289,10 @@ export interface SgdsCheckboxGroupProps extends SgdsBaseProps {
|
|
|
289
289
|
hintText?: string;
|
|
290
290
|
/** Makes the checkbox group a required field. Only available for when multiselect is true */
|
|
291
291
|
required?: boolean;
|
|
292
|
+
/** Disables native and sgds validation for the checkbox group. */
|
|
293
|
+
noValidate?: boolean;
|
|
292
294
|
/** Consolidates the values of its child checked checkboxes into a single string with semi-colon delimiter. Only available when required is true */
|
|
293
295
|
value?: string;
|
|
294
|
-
defaultValue?: string;
|
|
295
296
|
/** Returns the ValidityState object */
|
|
296
297
|
validity?: ValidityState;
|
|
297
298
|
/** Returns the validation message based on the ValidityState */
|
|
@@ -304,6 +305,10 @@ export interface SgdsCheckboxGroupProps extends SgdsBaseProps {
|
|
|
304
305
|
invalid?: boolean;
|
|
305
306
|
"onsgds-change"?: SgdsEventHandler;
|
|
306
307
|
onSgdsChange?: SgdsEventHandler;
|
|
308
|
+
"onsgds-invalid"?: SgdsEventHandler;
|
|
309
|
+
onSgdsInvalid?: SgdsEventHandler;
|
|
310
|
+
"onsgds-valid"?: SgdsEventHandler;
|
|
311
|
+
onSgdsValid?: SgdsEventHandler;
|
|
307
312
|
}
|
|
308
313
|
|
|
309
314
|
// ── Checkbox ─────────────────────────────────────────────────────────────
|
|
@@ -315,12 +320,12 @@ export interface SgdsCheckboxProps extends SgdsBaseProps {
|
|
|
315
320
|
checked?: boolean;
|
|
316
321
|
/** Allows invalidFeedback, invalid and valid styles to be visible with the input */
|
|
317
322
|
hasFeedback?: "style" | "text" | "both";
|
|
318
|
-
/** Gets or sets the default value used to reset this element. The initial value corresponds to the one originally specified in the HTML that created this element. */
|
|
319
|
-
defaultChecked?: boolean;
|
|
320
323
|
/** Marks the checkbox input as indeterminate , with indeterminate logo */
|
|
321
324
|
indeterminate?: boolean;
|
|
322
325
|
/** Makes the checkbox a required field. */
|
|
323
326
|
required?: boolean;
|
|
327
|
+
/** Disables native and sgds validation for the checkbox. */
|
|
328
|
+
noValidate?: boolean;
|
|
324
329
|
/** Feedback text for error state when validated */
|
|
325
330
|
invalidFeedback?: string;
|
|
326
331
|
/** Returns the ValidityState object */
|
|
@@ -347,6 +352,10 @@ export interface SgdsCheckboxProps extends SgdsBaseProps {
|
|
|
347
352
|
onSgdsCheck?: SgdsEventHandler;
|
|
348
353
|
"onsgds-uncheck"?: SgdsEventHandler;
|
|
349
354
|
onSgdsUncheck?: SgdsEventHandler;
|
|
355
|
+
"onsgds-invalid"?: SgdsEventHandler;
|
|
356
|
+
onSgdsInvalid?: SgdsEventHandler;
|
|
357
|
+
"onsgds-valid"?: SgdsEventHandler;
|
|
358
|
+
onSgdsValid?: SgdsEventHandler;
|
|
350
359
|
}
|
|
351
360
|
|
|
352
361
|
// ── CloseButton ─────────────────────────────────────────────────────────────
|
|
@@ -384,6 +393,8 @@ export interface SgdsComboBoxProps extends SgdsBaseProps {
|
|
|
384
393
|
async?: boolean;
|
|
385
394
|
/** When filtering remotely and there are no results, set this to true to enable no options feedback on the menu. Applicable for async combo box only. */
|
|
386
395
|
emptyMenuAsync?: boolean;
|
|
396
|
+
/** Number of pixels from the bottom of the menu at which the sgds-scroll-end event fires. */
|
|
397
|
+
scrollBottomOffset?: number;
|
|
387
398
|
/** The function used to filter the menu list, given the user's input value. */
|
|
388
399
|
filterFunction?: (inputValue: string, item: SgdsComboBoxOptionData) => boolean;
|
|
389
400
|
/** The input's label */
|
|
@@ -446,6 +457,8 @@ value: string;
|
|
|
446
457
|
onSgdsInvalid?: SgdsEventHandler;
|
|
447
458
|
"onsgds-valid"?: SgdsEventHandler;
|
|
448
459
|
onSgdsValid?: SgdsEventHandler;
|
|
460
|
+
"onsgds-scroll-end"?: SgdsEventHandler;
|
|
461
|
+
onSgdsScrollEnd?: SgdsEventHandler;
|
|
449
462
|
"onsgds-show"?: SgdsEventHandler;
|
|
450
463
|
onSgdsShow?: SgdsEventHandler;
|
|
451
464
|
"onsgds-after-show"?: SgdsEventHandler;
|
|
@@ -905,6 +918,8 @@ export interface SgdsMainnavDropdownProps extends SgdsBaseProps {
|
|
|
905
918
|
active?: boolean;
|
|
906
919
|
/** When true, applies active styles on the dropdown button */
|
|
907
920
|
disabled?: boolean;
|
|
921
|
+
/** Accessible label for the dropdown's toggle button. Forwarded to the button's aria-label attribute. */
|
|
922
|
+
ariaLabel?: string;
|
|
908
923
|
}
|
|
909
924
|
|
|
910
925
|
// ── MainnavItem ─────────────────────────────────────────────────────────────
|
|
@@ -1067,6 +1082,8 @@ export interface SgdsRadioGroupProps extends SgdsBaseProps {
|
|
|
1067
1082
|
hasFeedback?: boolean;
|
|
1068
1083
|
/** Makes the input as a required field. */
|
|
1069
1084
|
required?: boolean;
|
|
1085
|
+
/** Disables native and sgds validation for the radio group. */
|
|
1086
|
+
noValidate?: boolean;
|
|
1070
1087
|
/** Automatically focuses the selected radio input in the group when it becomes checked. */
|
|
1071
1088
|
autofocus?: boolean;
|
|
1072
1089
|
/** Returns the ValidityState object */
|
|
@@ -1085,6 +1102,10 @@ export interface SgdsRadioGroupProps extends SgdsBaseProps {
|
|
|
1085
1102
|
invalid?: boolean;
|
|
1086
1103
|
"onsgds-change"?: (event: CustomEvent<ISgdsRadioGroupChangeEventDetail>) => void;
|
|
1087
1104
|
onSgdsChange?: (event: CustomEvent<ISgdsRadioGroupChangeEventDetail>) => void;
|
|
1105
|
+
"onsgds-invalid"?: SgdsEventHandler;
|
|
1106
|
+
onSgdsInvalid?: SgdsEventHandler;
|
|
1107
|
+
"onsgds-valid"?: SgdsEventHandler;
|
|
1108
|
+
onSgdsValid?: SgdsEventHandler;
|
|
1088
1109
|
}
|
|
1089
1110
|
|
|
1090
1111
|
// ── Radio ─────────────────────────────────────────────────────────────
|
|
@@ -1118,6 +1139,8 @@ export interface SgdsSelectOptionProps extends SgdsBaseProps {
|
|
|
1118
1139
|
// ── Select ─────────────────────────────────────────────────────────────
|
|
1119
1140
|
|
|
1120
1141
|
export interface SgdsSelectProps extends SgdsBaseProps {
|
|
1142
|
+
/** Disables native and sgds validation for the select. */
|
|
1143
|
+
noValidate?: boolean;
|
|
1121
1144
|
/** The input's label */
|
|
1122
1145
|
label?: string;
|
|
1123
1146
|
/** The input's hint text below the label */
|
|
@@ -1172,6 +1195,10 @@ value: string;
|
|
|
1172
1195
|
onSgdsFocus?: SgdsEventHandler;
|
|
1173
1196
|
"onsgds-blur"?: SgdsEventHandler;
|
|
1174
1197
|
onSgdsBlur?: SgdsEventHandler;
|
|
1198
|
+
"onsgds-invalid"?: SgdsEventHandler;
|
|
1199
|
+
onSgdsInvalid?: SgdsEventHandler;
|
|
1200
|
+
"onsgds-valid"?: SgdsEventHandler;
|
|
1201
|
+
onSgdsValid?: SgdsEventHandler;
|
|
1175
1202
|
"onsgds-show"?: SgdsEventHandler;
|
|
1176
1203
|
onSgdsShow?: SgdsEventHandler;
|
|
1177
1204
|
"onsgds-after-show"?: SgdsEventHandler;
|
|
@@ -1689,10 +1716,10 @@ declare module "react" {
|
|
|
1689
1716
|
"sgds-alert-link": React.DetailedHTMLProps<SgdsAlertLinkProps, HTMLElement>;
|
|
1690
1717
|
"sgds-alert": React.DetailedHTMLProps<SgdsAlertProps, HTMLElement>;
|
|
1691
1718
|
"sgds-badge": React.DetailedHTMLProps<SgdsBadgeProps, HTMLElement>;
|
|
1692
|
-
"sgds-breadcrumb-item": React.DetailedHTMLProps<SgdsBreadcrumbItemProps, HTMLElement>;
|
|
1693
|
-
"sgds-breadcrumb": React.DetailedHTMLProps<SgdsBreadcrumbProps, HTMLElement>;
|
|
1694
1719
|
"sgds-button": React.DetailedHTMLProps<SgdsButtonProps, HTMLElement>;
|
|
1695
1720
|
"sgds-card": React.DetailedHTMLProps<SgdsCardProps, HTMLElement>;
|
|
1721
|
+
"sgds-breadcrumb-item": React.DetailedHTMLProps<SgdsBreadcrumbItemProps, HTMLElement>;
|
|
1722
|
+
"sgds-breadcrumb": React.DetailedHTMLProps<SgdsBreadcrumbProps, HTMLElement>;
|
|
1696
1723
|
"sgds-checkbox-group": React.DetailedHTMLProps<SgdsCheckboxGroupProps, HTMLElement>;
|
|
1697
1724
|
"sgds-checkbox": React.DetailedHTMLProps<SgdsCheckboxProps, HTMLElement>;
|
|
1698
1725
|
"sgds-close-button": React.DetailedHTMLProps<SgdsCloseButtonProps, HTMLElement>;
|
|
@@ -1772,10 +1799,10 @@ declare global {
|
|
|
1772
1799
|
"sgds-alert-link": HTMLElement;
|
|
1773
1800
|
"sgds-alert": HTMLElement;
|
|
1774
1801
|
"sgds-badge": HTMLElement;
|
|
1775
|
-
"sgds-breadcrumb-item": HTMLElement;
|
|
1776
|
-
"sgds-breadcrumb": HTMLElement;
|
|
1777
1802
|
"sgds-button": HTMLElement;
|
|
1778
1803
|
"sgds-card": HTMLElement;
|
|
1804
|
+
"sgds-breadcrumb-item": HTMLElement;
|
|
1805
|
+
"sgds-breadcrumb": HTMLElement;
|
|
1779
1806
|
"sgds-checkbox-group": HTMLElement;
|
|
1780
1807
|
"sgds-checkbox": HTMLElement;
|
|
1781
1808
|
"sgds-close-button": HTMLElement;
|
package/utils/validatorMixin.js
CHANGED
|
@@ -19,9 +19,7 @@ const SgdsFormValidatorMixin = (superClass) => {
|
|
|
19
19
|
connectedCallback() {
|
|
20
20
|
var _a;
|
|
21
21
|
super.connectedCallback();
|
|
22
|
-
|
|
23
|
-
return;
|
|
24
|
-
/** Idempotency guarantee */
|
|
22
|
+
/** Idempotency guarantee — always create so reset can clear validity even with noValidate */
|
|
25
23
|
(_a = this.inputValidationController) !== null && _a !== void 0 ? _a : (this.inputValidationController = new InputValidationController(this));
|
|
26
24
|
}
|
|
27
25
|
async firstUpdated(changedProperties) {
|
|
@@ -78,19 +76,19 @@ const SgdsFormValidatorMixin = (superClass) => {
|
|
|
78
76
|
}
|
|
79
77
|
/**
|
|
80
78
|
* During form resetting,
|
|
81
|
-
* 1. ValidityState is reset
|
|
82
|
-
* 2. invalid reactive prop is updated after the reset
|
|
83
|
-
* 3.
|
|
84
|
-
*
|
|
85
|
-
*
|
|
79
|
+
* 1. ValidityState is reset (always, regardless of noValidate)
|
|
80
|
+
* 2. invalid reactive prop is updated after the reset (always)
|
|
81
|
+
* 3. Reset touched state to false for a pristine form (always)
|
|
82
|
+
* 4. Revalidates the ValidityState (but do not update invalid prop)
|
|
83
|
+
* to prepare for the next validity check (skipped when noValidate)
|
|
86
84
|
*/
|
|
87
85
|
_mixinResetValidity(input) {
|
|
88
|
-
if (this._mixinShouldSkipSgdsValidation())
|
|
89
|
-
return;
|
|
90
86
|
this.inputValidationController.resetValidity();
|
|
91
87
|
this.inputValidationController.updateInvalidState();
|
|
92
|
-
this.inputValidationController.validateInput(input);
|
|
93
88
|
this._isTouched ? (this._isTouched = false) : null;
|
|
89
|
+
if (this._mixinShouldSkipSgdsValidation())
|
|
90
|
+
return;
|
|
91
|
+
this.inputValidationController.validateInput(input);
|
|
94
92
|
}
|
|
95
93
|
_mixinValidate(input) {
|
|
96
94
|
if (this._mixinShouldSkipSgdsValidation())
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validatorMixin.js","sources":["../../src/utils/validatorMixin.ts"],"sourcesContent":["import { LitElement, PropertyValueMap } from \"lit\";\nimport { queryAsync } from \"lit/decorators.js\";\nimport { SgdsInput } from \"../components\";\nimport { InputValidationController } from \"./inputValidationController\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Constructor<T> = new (...args: any[]) => T;\n\n/**\n * @summary The FormValidationMixin used by the form components\n * @param superClass\n * @returns\n */\nexport const SgdsFormValidatorMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n class ToBeValidatedElement extends superClass {\n static formAssociated = true;\n inputValidationController: InputValidationController;\n input: HTMLInputElement | SgdsInput | HTMLTextAreaElement;\n private _isTouched = false;\n private _internals: ElementInternals;\n @queryAsync(\"sgds-input\") sgdsInput: Promise<SgdsInput>;\n @queryAsync(\"sgds-datepicker-input\") sgdsDatepickerInput: Promise<SgdsInput>;\n\n // TypeScript requires mixin constructors to have rest parameter of type any[]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(...args);\n this._internals = this.attachInternals();\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n\n
|
|
1
|
+
{"version":3,"file":"validatorMixin.js","sources":["../../src/utils/validatorMixin.ts"],"sourcesContent":["import { LitElement, PropertyValueMap } from \"lit\";\nimport { queryAsync } from \"lit/decorators.js\";\nimport { SgdsInput } from \"../components\";\nimport { InputValidationController } from \"./inputValidationController\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Constructor<T> = new (...args: any[]) => T;\n\n/**\n * @summary The FormValidationMixin used by the form components\n * @param superClass\n * @returns\n */\nexport const SgdsFormValidatorMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n class ToBeValidatedElement extends superClass {\n static formAssociated = true;\n inputValidationController: InputValidationController;\n input: HTMLInputElement | SgdsInput | HTMLTextAreaElement;\n private _isTouched = false;\n private _internals: ElementInternals;\n @queryAsync(\"sgds-input\") sgdsInput: Promise<SgdsInput>;\n @queryAsync(\"sgds-datepicker-input\") sgdsDatepickerInput: Promise<SgdsInput>;\n\n // TypeScript requires mixin constructors to have rest parameter of type any[]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(...args);\n this._internals = this.attachInternals();\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n\n /** Idempotency guarantee — always create so reset can clear validity even with noValidate */\n this.inputValidationController ??= new InputValidationController(this);\n }\n async firstUpdated(changedProperties: PropertyValueMap<this>) {\n super.firstUpdated(changedProperties);\n\n /* Either input or sgds-input. For example, quantity-toggle uses sgds-input */\n this.input =\n this.shadowRoot.querySelector(\"input\") ||\n (await this.sgdsInput) ||\n this.shadowRoot.querySelector(\"textarea\") ||\n (await this.sgdsDatepickerInput);\n\n this._mixinSetFormValue();\n\n if (this._mixinShouldSkipSgdsValidation()) return;\n\n this._mixinValidate(this.input);\n }\n\n /**\n * Native lifecycle of Form-Associated Custom Element Callbacks\n */\n formResetCallback() {\n if (this._mixinResetFormControl) {\n this._mixinResetFormControl();\n } else {\n this.value = this.defaultValue;\n this._mixinResetValidity(this.input);\n }\n this._mixinSetFormValue();\n }\n /**\n *\n * Methods use by classes using this mixin\n */\n\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run change handler\n */\n _mixinHandleChange(e: Event): void {\n this._mixinSetFormValue();\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.handleChange(e);\n }\n /**\n * OnChange of form component\n * 1. Make value of control accessible via FormData\n * 2. Run input handler\n */\n _mixinHandleInputChange(e: Event): void {\n this._mixinSetFormValue();\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.handleInput(e);\n }\n /**\n * During form resetting,\n * 1. ValidityState is reset (always, regardless of noValidate)\n * 2. invalid reactive prop is updated after the reset (always)\n * 3. Reset touched state to false for a pristine form (always)\n * 4. Revalidates the ValidityState (but do not update invalid prop)\n * to prepare for the next validity check (skipped when noValidate)\n */\n _mixinResetValidity(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n this.inputValidationController.resetValidity();\n this.inputValidationController.updateInvalidState();\n this._isTouched ? (this._isTouched = false) : null;\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.validateInput(input);\n }\n\n _mixinValidate(input: HTMLInputElement | SgdsInput | HTMLTextAreaElement) {\n if (this._mixinShouldSkipSgdsValidation()) return;\n this.inputValidationController.validateInput(input);\n }\n _mixinSetFormValue() {\n const value = this.value as string | FormData | File;\n this._internals.setFormValue(value);\n }\n _mixinCheckValidity(): boolean {\n if (this._mixinShouldSkipSgdsValidation()) return true;\n return this.inputValidationController.checkValidity();\n }\n _mixinReportValidity(): boolean {\n if (this._mixinShouldSkipSgdsValidation()) return true;\n return this.inputValidationController.reportValidity();\n }\n _mixinGetValidity(): ValidityState {\n return this._internals.validity;\n }\n _mixinGetValidationMessage(): string {\n return this._internals.validationMessage;\n }\n _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void {\n if (this._mixinShouldSkipSgdsValidation()) return;\n return this.inputValidationController.setValidity(flags, message, anchor);\n }\n // Only check for noValidate prop\n _mixinShouldSkipSgdsValidation() {\n const form = this.closest(\"form\");\n\n return form?.noValidate || this.noValidate;\n }\n\n /** DECLARED INSTANCE METHODS AND PROPERTIES*/\n\n /**\n * Resets a form control to its initial state\n */\n declare _mixinResetFormControl: () => void;\n declare value: string;\n declare defaultValue: string;\n declare defaultChecked: boolean;\n declare noValidate: boolean;\n }\n\n return ToBeValidatedElement as Constructor<ToBeValidatedElementInterface> & T;\n};\n\nexport declare class ToBeValidatedElementInterface {\n inputValidationController: InputValidationController;\n input: HTMLInputElement;\n _mixinHandleChange(e: Event): void;\n _mixinHandleInputChange(e: Event): void;\n _mixinResetValidity(input: HTMLInputElement | SgdsInput): void;\n _mixinValidate(input: HTMLInputElement | SgdsInput): void;\n _mixinSetFormValue(): void;\n _mixinCheckValidity(): boolean;\n _mixinReportValidity(): boolean;\n _mixinSetValidity(flags?: ValidityStateFlags, message?: string, anchor?: HTMLElement): void;\n _mixinGetValidity(): ValidityState;\n _mixinGetValidationMessage(): string;\n _mixinShouldSkipSgdsValidation(): boolean;\n}\n"],"names":[],"mappings":";;;;AAQA;;;;AAIG;AACU,MAAA,sBAAsB,GAAG,CAAoC,UAAa,KAAI;IACzF,MAAM,oBAAqB,SAAQ,UAAU,CAAA;;;AAW3C,QAAA,WAAA,CAAY,GAAG,IAAW,EAAA;AACxB,YAAA,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YART,IAAU,CAAA,UAAA,GAAG,KAAK,CAAC;AASzB,YAAA,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;SAC1C;QAED,iBAAiB,GAAA;;YACf,KAAK,CAAC,iBAAiB,EAAE,CAAC;;AAG1B,YAAA,CAAA,EAAA,GAAA,IAAI,CAAC,yBAAyB,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