@govtechsg/sgds-web-component 3.0.5 → 3.1.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Checkbox/checkbox-group.js +1 -1
- package/components/Checkbox/checkbox.js +1 -1
- package/components/Checkbox/index.umd.js +195 -31
- package/components/Checkbox/index.umd.js.map +1 -1
- package/components/Checkbox/sgds-checkbox-group.d.ts +49 -10
- package/components/Checkbox/sgds-checkbox-group.js +161 -25
- 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 +39 -6
- package/components/Checkbox/sgds-checkbox.js.map +1 -1
- package/components/ComboBox/index.umd.js +39 -6
- package/components/ComboBox/index.umd.js.map +1 -1
- package/components/Datepicker/index.umd.js +1 -10
- package/components/Datepicker/index.umd.js.map +1 -1
- package/components/Input/index.umd.js +1 -10
- package/components/Input/index.umd.js.map +1 -1
- package/components/Input/sgds-input.d.ts +0 -2
- package/components/Input/sgds-input.js +1 -10
- package/components/Input/sgds-input.js.map +1 -1
- package/components/QuantityToggle/index.umd.js +1 -10
- package/components/QuantityToggle/index.umd.js.map +1 -1
- package/components/index.umd.js +196 -41
- package/components/index.umd.js.map +1 -1
- package/css/grid.css +55 -16
- package/index.umd.js +196 -41
- package/index.umd.js.map +1 -1
- package/package.json +1 -4
- package/react/components/Checkbox/checkbox-group.cjs.js +1 -1
- package/react/components/Checkbox/checkbox-group.js +1 -1
- package/react/components/Checkbox/checkbox.cjs.js +1 -1
- package/react/components/Checkbox/checkbox.js +1 -1
- package/react/components/Checkbox/sgds-checkbox-group.cjs.js +160 -24
- package/react/components/Checkbox/sgds-checkbox-group.cjs.js.map +1 -1
- package/react/components/Checkbox/sgds-checkbox-group.js +161 -25
- package/react/components/Checkbox/sgds-checkbox-group.js.map +1 -1
- package/react/components/Checkbox/sgds-checkbox.cjs.js +38 -5
- package/react/components/Checkbox/sgds-checkbox.cjs.js.map +1 -1
- package/react/components/Checkbox/sgds-checkbox.js +39 -6
- package/react/components/Checkbox/sgds-checkbox.js.map +1 -1
- package/react/components/Input/sgds-input.cjs.js +1 -10
- package/react/components/Input/sgds-input.cjs.js.map +1 -1
- package/react/components/Input/sgds-input.js +1 -10
- package/react/components/Input/sgds-input.js.map +1 -1
- package/themes/root.css +17 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@govtechsg/sgds-web-component",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.1.0-rc.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./index.umd.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -22,11 +22,8 @@
|
|
|
22
22
|
],
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@govtechsg/sgds": "^2.3.2",
|
|
26
25
|
"@lit/context": "^1.1.3",
|
|
27
26
|
"@lit/react": "^1.0.6",
|
|
28
|
-
"@open-wc/scoped-elements": "2.2.0",
|
|
29
|
-
"@storybook/addon-a11y": "^8.2.8",
|
|
30
27
|
"bootstrap": "^5.1.3",
|
|
31
28
|
"date-fns": "^3.3.1",
|
|
32
29
|
"imask": "^7.4.0",
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var lit = require('lit');
|
|
7
7
|
|
|
8
|
-
var css_248z = lit.css`:host{--sgds-checkbox-group-gap:var(--sgds-spacer-2)}fieldset{border:0;gap:var(--sgds-form-gap-md);margin:0;min-width:0;padding:0}.label-hint-container,fieldset{display:flex;flex-direction:column}.label-hint-container{gap:var(--sgds-form-gap-sm)}.label-hint-container .form-label{color:var(--sgds-form-color-default);font-size:var(--sgds-font-size-2);font-weight:var(--sgds-font-weight-regular)}.checkbox-container{display:flex;flex-direction:column;gap:var(--sgds-form-gap-md)}`;
|
|
8
|
+
var css_248z = lit.css`:host{--sgds-checkbox-group-gap:var(--sgds-spacer-2)}fieldset{border:0;gap:var(--sgds-form-gap-md);margin:0;min-width:0;padding:0}.label-hint-container,fieldset{display:flex;flex-direction:column}.label-hint-container{gap:var(--sgds-form-gap-sm)}.label-hint-container .form-label{color:var(--sgds-form-color-default);font-size:var(--sgds-font-size-2);font-weight:var(--sgds-font-weight-regular)}.checkbox-container{display:flex;flex-direction:column;gap:var(--sgds-form-gap-md)}.checkbox-group-validation-input{display:none}`;
|
|
9
9
|
|
|
10
10
|
exports["default"] = css_248z;
|
|
11
11
|
//# sourceMappingURL=checkbox-group.cjs.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { css } from 'lit';
|
|
3
3
|
|
|
4
|
-
var css_248z = css`:host{--sgds-checkbox-group-gap:var(--sgds-spacer-2)}fieldset{border:0;gap:var(--sgds-form-gap-md);margin:0;min-width:0;padding:0}.label-hint-container,fieldset{display:flex;flex-direction:column}.label-hint-container{gap:var(--sgds-form-gap-sm)}.label-hint-container .form-label{color:var(--sgds-form-color-default);font-size:var(--sgds-font-size-2);font-weight:var(--sgds-font-weight-regular)}.checkbox-container{display:flex;flex-direction:column;gap:var(--sgds-form-gap-md)}`;
|
|
4
|
+
var css_248z = css`:host{--sgds-checkbox-group-gap:var(--sgds-spacer-2)}fieldset{border:0;gap:var(--sgds-form-gap-md);margin:0;min-width:0;padding:0}.label-hint-container,fieldset{display:flex;flex-direction:column}.label-hint-container{gap:var(--sgds-form-gap-sm)}.label-hint-container .form-label{color:var(--sgds-form-color-default);font-size:var(--sgds-font-size-2);font-weight:var(--sgds-font-weight-regular)}.checkbox-container{display:flex;flex-direction:column;gap:var(--sgds-form-gap-md)}.checkbox-group-validation-input{display:none}`;
|
|
5
5
|
|
|
6
6
|
export { css_248z as default };
|
|
7
7
|
//# sourceMappingURL=checkbox-group.js.map
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var lit = require('lit');
|
|
7
7
|
|
|
8
|
-
var css_248z = lit.css`input{margin:0}.form-check{display:flex;gap:var(--sgds-form-gap-md);padding:var(--sgds-form-padding-inline-sm) 0}.form-check-input,.form-check-input-container{height:var(--sgds-form-height-sm);width:var(--sgds-form-width-xs)}.form-check-input{appearance:none;background-color:var(--sgds-form-surface-default);background-image:var(--sgds-radio-bg-image);background-position:50%;background-repeat:no-repeat;background-size:auto;border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-default);border-radius:var(--sgds-form-border-radius-md)}:host(:not([disabled]):not([invalid]):not([checked]):not([indeterminate])) .form-check-input:hover{border:var(--sgds-form-border-width-thick) solid var(--sgds-border-color-emphasis)}.form-check-input:focus,.form-check-input:focus-visible{border:var(--sgds-form-border-width-thick) solid var(--sgds-border-color-emphasis);box-shadow:var(--sgds-form-box-shadow-focus);outline:0}.form-check-input:checked,.form-check-input[checked]{--sgds-radio-bg-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="17" height="16" fill="none"><path d="M14.347 3.979a.522.522 0 0 1 0 .739L7.043 12.02a.521.521 0 0 1-.738 0L2.653 8.369a.522.522 0 1 1 .739-.738l3.282 3.283 6.934-6.935a.52.52 0 0 1 .739 0Z" fill="%23fff"/></svg>');background-color:var(--sgds-form-primary-surface-default);border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-transparent)}.form-check-input:checked:focus,.form-check-input:checked:hover,.form-check-input[checked]:focus-visible,.form-check-input[checked]:hover{background-color:var(--sgds-form-primary-surface-emphasis)}.form-check-input:indeterminate,.form-check-input[indeterminate]{--sgds-radio-bg-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="17" height="16" fill="none"><path fill-rule="evenodd" clip-rule="evenodd" d="M2.5 8a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5Z" fill="%23fff"/></svg>');background-color:var(--sgds-form-primary-surface-default);border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-transparent)}.form-check-input:indeterminate:focus,.form-check-input:indeterminate:hover,.form-check-input[indeterminate]:focus-visible,.form-check-input[indeterminate]:hover{background-color:var(--sgds-form-primary-surface-emphasis)}:host([disabled]) .form-check{cursor:not-allowed;opacity:var(--sgds-opacity-50)}.form-check-input.is-invalid{border:var(--sgds-form-border-width-thick) solid var(--sgds-form-danger-border-color-default)}.form-check-input:checked.is-invalid,.form-check-input:indeterminate.is-invalid,.form-check-input[checked].is-invalid,.form-check-input[indeterminate].is-invalid{background-color:var(--sgds-form-danger-surface-default);border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-transparent)}.form-check-label{width:100%}`;
|
|
8
|
+
var css_248z = lit.css`input{margin:0}.form-check{display:flex;gap:var(--sgds-form-gap-md);margin-bottom:var(--sgds-margin-3-xs);padding:var(--sgds-form-padding-inline-sm) 0}.form-check-input,.form-check-input-container{height:var(--sgds-form-height-sm);width:var(--sgds-form-width-xs)}.form-check-input{appearance:none;background-color:var(--sgds-form-surface-default);background-image:var(--sgds-radio-bg-image);background-position:50%;background-repeat:no-repeat;background-size:auto;border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-default);border-radius:var(--sgds-form-border-radius-md)}:host(:not([disabled]):not([invalid]):not([checked]):not([indeterminate])) .form-check-input:hover{border:var(--sgds-form-border-width-thick) solid var(--sgds-border-color-emphasis)}.form-check-input:focus,.form-check-input:focus-visible{border:var(--sgds-form-border-width-thick) solid var(--sgds-border-color-emphasis);box-shadow:var(--sgds-form-box-shadow-focus);outline:0}.form-check-input:checked,.form-check-input[checked]{--sgds-radio-bg-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="17" height="16" fill="none"><path d="M14.347 3.979a.522.522 0 0 1 0 .739L7.043 12.02a.521.521 0 0 1-.738 0L2.653 8.369a.522.522 0 1 1 .739-.738l3.282 3.283 6.934-6.935a.52.52 0 0 1 .739 0Z" fill="%23fff"/></svg>');background-color:var(--sgds-form-primary-surface-default);border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-transparent)}.form-check-input:checked:focus,.form-check-input:checked:hover,.form-check-input[checked]:focus-visible,.form-check-input[checked]:hover{background-color:var(--sgds-form-primary-surface-emphasis)}.form-check-input:indeterminate,.form-check-input[indeterminate]{--sgds-radio-bg-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="17" height="16" fill="none"><path fill-rule="evenodd" clip-rule="evenodd" d="M2.5 8a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5Z" fill="%23fff"/></svg>');background-color:var(--sgds-form-primary-surface-default);border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-transparent)}.form-check-input:indeterminate:focus,.form-check-input:indeterminate:hover,.form-check-input[indeterminate]:focus-visible,.form-check-input[indeterminate]:hover{background-color:var(--sgds-form-primary-surface-emphasis)}:host([disabled]) .form-check{cursor:not-allowed;opacity:var(--sgds-opacity-50)}.form-check-input.is-invalid{border:var(--sgds-form-border-width-thick) solid var(--sgds-form-danger-border-color-default)}.form-check-input:checked.is-invalid,.form-check-input:indeterminate.is-invalid,.form-check-input[checked].is-invalid,.form-check-input[indeterminate].is-invalid{background-color:var(--sgds-form-danger-surface-default);border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-transparent)}.form-check-label{width:100%}`;
|
|
9
9
|
|
|
10
10
|
exports["default"] = css_248z;
|
|
11
11
|
//# sourceMappingURL=checkbox.cjs.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { css } from 'lit';
|
|
3
3
|
|
|
4
|
-
var css_248z = css`input{margin:0}.form-check{display:flex;gap:var(--sgds-form-gap-md);padding:var(--sgds-form-padding-inline-sm) 0}.form-check-input,.form-check-input-container{height:var(--sgds-form-height-sm);width:var(--sgds-form-width-xs)}.form-check-input{appearance:none;background-color:var(--sgds-form-surface-default);background-image:var(--sgds-radio-bg-image);background-position:50%;background-repeat:no-repeat;background-size:auto;border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-default);border-radius:var(--sgds-form-border-radius-md)}:host(:not([disabled]):not([invalid]):not([checked]):not([indeterminate])) .form-check-input:hover{border:var(--sgds-form-border-width-thick) solid var(--sgds-border-color-emphasis)}.form-check-input:focus,.form-check-input:focus-visible{border:var(--sgds-form-border-width-thick) solid var(--sgds-border-color-emphasis);box-shadow:var(--sgds-form-box-shadow-focus);outline:0}.form-check-input:checked,.form-check-input[checked]{--sgds-radio-bg-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="17" height="16" fill="none"><path d="M14.347 3.979a.522.522 0 0 1 0 .739L7.043 12.02a.521.521 0 0 1-.738 0L2.653 8.369a.522.522 0 1 1 .739-.738l3.282 3.283 6.934-6.935a.52.52 0 0 1 .739 0Z" fill="%23fff"/></svg>');background-color:var(--sgds-form-primary-surface-default);border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-transparent)}.form-check-input:checked:focus,.form-check-input:checked:hover,.form-check-input[checked]:focus-visible,.form-check-input[checked]:hover{background-color:var(--sgds-form-primary-surface-emphasis)}.form-check-input:indeterminate,.form-check-input[indeterminate]{--sgds-radio-bg-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="17" height="16" fill="none"><path fill-rule="evenodd" clip-rule="evenodd" d="M2.5 8a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5Z" fill="%23fff"/></svg>');background-color:var(--sgds-form-primary-surface-default);border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-transparent)}.form-check-input:indeterminate:focus,.form-check-input:indeterminate:hover,.form-check-input[indeterminate]:focus-visible,.form-check-input[indeterminate]:hover{background-color:var(--sgds-form-primary-surface-emphasis)}:host([disabled]) .form-check{cursor:not-allowed;opacity:var(--sgds-opacity-50)}.form-check-input.is-invalid{border:var(--sgds-form-border-width-thick) solid var(--sgds-form-danger-border-color-default)}.form-check-input:checked.is-invalid,.form-check-input:indeterminate.is-invalid,.form-check-input[checked].is-invalid,.form-check-input[indeterminate].is-invalid{background-color:var(--sgds-form-danger-surface-default);border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-transparent)}.form-check-label{width:100%}`;
|
|
4
|
+
var css_248z = css`input{margin:0}.form-check{display:flex;gap:var(--sgds-form-gap-md);margin-bottom:var(--sgds-margin-3-xs);padding:var(--sgds-form-padding-inline-sm) 0}.form-check-input,.form-check-input-container{height:var(--sgds-form-height-sm);width:var(--sgds-form-width-xs)}.form-check-input{appearance:none;background-color:var(--sgds-form-surface-default);background-image:var(--sgds-radio-bg-image);background-position:50%;background-repeat:no-repeat;background-size:auto;border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-default);border-radius:var(--sgds-form-border-radius-md)}:host(:not([disabled]):not([invalid]):not([checked]):not([indeterminate])) .form-check-input:hover{border:var(--sgds-form-border-width-thick) solid var(--sgds-border-color-emphasis)}.form-check-input:focus,.form-check-input:focus-visible{border:var(--sgds-form-border-width-thick) solid var(--sgds-border-color-emphasis);box-shadow:var(--sgds-form-box-shadow-focus);outline:0}.form-check-input:checked,.form-check-input[checked]{--sgds-radio-bg-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="17" height="16" fill="none"><path d="M14.347 3.979a.522.522 0 0 1 0 .739L7.043 12.02a.521.521 0 0 1-.738 0L2.653 8.369a.522.522 0 1 1 .739-.738l3.282 3.283 6.934-6.935a.52.52 0 0 1 .739 0Z" fill="%23fff"/></svg>');background-color:var(--sgds-form-primary-surface-default);border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-transparent)}.form-check-input:checked:focus,.form-check-input:checked:hover,.form-check-input[checked]:focus-visible,.form-check-input[checked]:hover{background-color:var(--sgds-form-primary-surface-emphasis)}.form-check-input:indeterminate,.form-check-input[indeterminate]{--sgds-radio-bg-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="17" height="16" fill="none"><path fill-rule="evenodd" clip-rule="evenodd" d="M2.5 8a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5Z" fill="%23fff"/></svg>');background-color:var(--sgds-form-primary-surface-default);border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-transparent)}.form-check-input:indeterminate:focus,.form-check-input:indeterminate:hover,.form-check-input[indeterminate]:focus-visible,.form-check-input[indeterminate]:hover{background-color:var(--sgds-form-primary-surface-emphasis)}:host([disabled]) .form-check{cursor:not-allowed;opacity:var(--sgds-opacity-50)}.form-check-input.is-invalid{border:var(--sgds-form-border-width-thick) solid var(--sgds-form-danger-border-color-default)}.form-check-input:checked.is-invalid,.form-check-input:indeterminate.is-invalid,.form-check-input[checked].is-invalid,.form-check-input[indeterminate].is-invalid{background-color:var(--sgds-form-danger-surface-default);border:var(--sgds-form-border-width-default) solid var(--sgds-border-color-transparent)}.form-check-label{width:100%}`;
|
|
5
5
|
|
|
6
6
|
export { css_248z as default };
|
|
7
7
|
//# sourceMappingURL=checkbox.js.map
|
|
@@ -11,6 +11,11 @@ var feedback = require('../../styles/feedback.cjs.js');
|
|
|
11
11
|
var formLabel = require('../../styles/form-label.cjs.js');
|
|
12
12
|
var checkboxGroup = require('./checkbox-group.cjs.js');
|
|
13
13
|
var formHint = require('../../styles/form-hint.cjs.js');
|
|
14
|
+
var validatorMixin = require('../../utils/validatorMixin.cjs.js');
|
|
15
|
+
var formControlElement = require('../../base/form-control-element.cjs.js');
|
|
16
|
+
var classMap_js = require('lit/directives/class-map.js');
|
|
17
|
+
var live_js = require('lit/directives/live.js');
|
|
18
|
+
var watch = require('../../utils/watch.cjs.js');
|
|
14
19
|
|
|
15
20
|
/**
|
|
16
21
|
* @summary CheckboxGroup is the container that group multiple checkboxes under a single question field.
|
|
@@ -20,10 +25,9 @@ var formHint = require('../../styles/form-hint.cjs.js');
|
|
|
20
25
|
* @slot invalidIcon - The slot for invalid icon
|
|
21
26
|
*
|
|
22
27
|
*/
|
|
23
|
-
class SgdsCheckboxGroup extends
|
|
28
|
+
class SgdsCheckboxGroup extends validatorMixin.SgdsFormValidatorMixin(formControlElement["default"]) {
|
|
24
29
|
constructor() {
|
|
25
|
-
super();
|
|
26
|
-
this.hasInvalidCheckbox = false;
|
|
30
|
+
super(...arguments);
|
|
27
31
|
/** The checkbox group's label */
|
|
28
32
|
this.label = "";
|
|
29
33
|
/**Feedback text for error state when validated */
|
|
@@ -32,27 +36,126 @@ class SgdsCheckboxGroup extends sgdsElement["default"] {
|
|
|
32
36
|
this.hasFeedback = false;
|
|
33
37
|
/** The checkbox group's hint text */
|
|
34
38
|
this.hintText = "";
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.
|
|
39
|
+
/** Makes the checkbox group a required field. Only available for when multiselect is true */
|
|
40
|
+
this.required = false;
|
|
41
|
+
/** Consolidates the values of its child checked checkboxes into a single string with semi-colon delimiter. Only available when required is true */
|
|
42
|
+
this.value = "";
|
|
43
|
+
this._isTouched = false;
|
|
44
|
+
/**@internal */
|
|
45
|
+
this.defaultValue = "";
|
|
42
46
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
connectedCallback() {
|
|
48
|
+
super.connectedCallback();
|
|
49
|
+
this.defaultValue = this.value;
|
|
50
|
+
this.addEventListener("sgds-check", (e) => {
|
|
51
|
+
const { value } = e.detail;
|
|
52
|
+
!this.value.includes(value) && this._addValue(value);
|
|
53
|
+
});
|
|
54
|
+
this.addEventListener("sgds-uncheck", (e) => {
|
|
55
|
+
const { value } = e.detail;
|
|
56
|
+
this._removeValue(value);
|
|
57
|
+
});
|
|
58
|
+
this.addEventListener("sgds-blur", () => {
|
|
59
|
+
this._isTouched = true;
|
|
60
|
+
});
|
|
46
61
|
}
|
|
47
62
|
_renderHintText() {
|
|
48
63
|
const hintTextTemplate = lit.html ` <div class="form-text">${this.hintText}</div> `;
|
|
49
64
|
return this.hintText && hintTextTemplate;
|
|
50
65
|
}
|
|
51
|
-
|
|
52
|
-
this.
|
|
66
|
+
_addValue(newValue) {
|
|
67
|
+
const valueArray = this.value ? this.value.split(";") : [];
|
|
68
|
+
valueArray.push(newValue);
|
|
69
|
+
this.value = valueArray.join(";");
|
|
70
|
+
}
|
|
71
|
+
_removeValue(oldValue) {
|
|
72
|
+
const valueArray = this.value ? this.value.split(";") : [];
|
|
73
|
+
const newValueArray = valueArray.filter(v => v !== oldValue);
|
|
74
|
+
this.value = newValueArray.join(";");
|
|
75
|
+
}
|
|
76
|
+
_sanitizeSlot() {
|
|
77
|
+
const checkboxes = this._checkboxes;
|
|
78
|
+
checkboxes.forEach(checkbox => {
|
|
79
|
+
checkbox.checked = this.value.includes(checkbox.value);
|
|
80
|
+
checkbox.hasFeedback = this.hasFeedback ? "style" : null;
|
|
81
|
+
if (checkbox.required) {
|
|
82
|
+
console.error("Checkboxes in a group cannot have required or hasFeedback prop set to true");
|
|
83
|
+
checkbox.remove();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
this._disabledChildCheckboxes();
|
|
87
|
+
}
|
|
88
|
+
_disabledChildCheckboxes() {
|
|
89
|
+
if (this.disabled) {
|
|
90
|
+
const checkboxes = this._checkboxes;
|
|
91
|
+
checkboxes.forEach(checkbox => (checkbox.disabled = this.disabled));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
_handleValueChange() {
|
|
95
|
+
const checkboxes = this._checkboxes;
|
|
96
|
+
checkboxes.forEach(checkbox => {
|
|
97
|
+
checkbox.checked = this.value.includes(checkbox.value);
|
|
98
|
+
});
|
|
99
|
+
this._updateInputValue();
|
|
100
|
+
this._updateInvalid();
|
|
101
|
+
}
|
|
102
|
+
_handleIsTouched() {
|
|
103
|
+
if (this._isTouched) {
|
|
104
|
+
this.invalid = !this.input.checkValidity();
|
|
105
|
+
this._updateInvalid();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
_updateInvalid() {
|
|
109
|
+
const checkboxes = this._checkboxes;
|
|
110
|
+
checkboxes.forEach(ch => (ch.invalid = this.invalid));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Checks for validity. Under the hood, HTMLFormElement's reportValidity method calls this method to check for component's validity state
|
|
114
|
+
* Note that the native error popup is prevented for SGDS form components by default. Instead the validation message shows up in the feedback container of SgdsInput
|
|
115
|
+
*/
|
|
116
|
+
reportValidity() {
|
|
117
|
+
return this._mixinReportValidity();
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Checks for validity without any native error popup message
|
|
121
|
+
*/
|
|
122
|
+
checkValidity() {
|
|
123
|
+
return this._mixinCheckValidity();
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Returns the ValidityState object
|
|
127
|
+
*/
|
|
128
|
+
get validity() {
|
|
129
|
+
return this._mixinGetValidity();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Returns the validation message based on the ValidityState
|
|
133
|
+
*/
|
|
134
|
+
get validationMessage() {
|
|
135
|
+
return this._mixinGetValidationMessage();
|
|
53
136
|
}
|
|
54
|
-
|
|
55
|
-
|
|
137
|
+
/**
|
|
138
|
+
* radio requries a custom _mixinResetFormControl as the update of input value
|
|
139
|
+
* requires to fire a reset event manually
|
|
140
|
+
* */
|
|
141
|
+
_mixinResetFormControl() {
|
|
142
|
+
this.value = this.input.value = this.defaultValue;
|
|
143
|
+
this._updateInputValue("reset");
|
|
144
|
+
this._mixinResetValidity(this.input);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* when input value is set programatically, need to manually dispatch a change event
|
|
148
|
+
* In order to prevent race conditions and ensure sequence of events, set input's value here instead of binding to value prop of input
|
|
149
|
+
*/
|
|
150
|
+
_updateInputValue(eventName = "change") {
|
|
151
|
+
this.input.value = this.value;
|
|
152
|
+
this.input.dispatchEvent(new InputEvent(eventName));
|
|
153
|
+
}
|
|
154
|
+
firstUpdated(changedProperties) {
|
|
155
|
+
super.firstUpdated(changedProperties);
|
|
156
|
+
if (this.value) {
|
|
157
|
+
this._updateInputValue();
|
|
158
|
+
}
|
|
56
159
|
}
|
|
57
160
|
render() {
|
|
58
161
|
return lit.html `
|
|
@@ -62,9 +165,21 @@ class SgdsCheckboxGroup extends sgdsElement["default"] {
|
|
|
62
165
|
${this._renderHintText()}
|
|
63
166
|
</div>
|
|
64
167
|
<div class="checkbox-container">
|
|
65
|
-
<slot></slot>
|
|
168
|
+
<slot @slotchange=${this._sanitizeSlot}></slot>
|
|
66
169
|
</div>
|
|
67
|
-
|
|
170
|
+
<input
|
|
171
|
+
type="text"
|
|
172
|
+
class="checkbox-group-validation-input ${classMap_js.classMap({
|
|
173
|
+
"is-invalid": this.hasFeedback && this.invalid
|
|
174
|
+
})}"
|
|
175
|
+
?required=${this.required}
|
|
176
|
+
tabindex="-1"
|
|
177
|
+
@change=${(e) => {
|
|
178
|
+
super._mixinHandleChange(e);
|
|
179
|
+
}}
|
|
180
|
+
.value=${live_js.live(this.value)}
|
|
181
|
+
/>
|
|
182
|
+
${this.invalid && this.hasFeedback
|
|
68
183
|
? lit.html `
|
|
69
184
|
<div class="invalid-feedback-container">
|
|
70
185
|
<slot name="invalidIcon">
|
|
@@ -90,11 +205,8 @@ tslib.__decorate([
|
|
|
90
205
|
decorators_js.queryAssignedElements({ flatten: true })
|
|
91
206
|
], SgdsCheckboxGroup.prototype, "checkboxes", void 0);
|
|
92
207
|
tslib.__decorate([
|
|
93
|
-
decorators_js.
|
|
94
|
-
], SgdsCheckboxGroup.prototype, "
|
|
95
|
-
tslib.__decorate([
|
|
96
|
-
decorators_js.state()
|
|
97
|
-
], SgdsCheckboxGroup.prototype, "validationMessage", void 0);
|
|
208
|
+
decorators_js.queryAsync("slot")
|
|
209
|
+
], SgdsCheckboxGroup.prototype, "checkboxesAsync", void 0);
|
|
98
210
|
tslib.__decorate([
|
|
99
211
|
decorators_js.property({ reflect: true })
|
|
100
212
|
], SgdsCheckboxGroup.prototype, "label", void 0);
|
|
@@ -107,6 +219,30 @@ tslib.__decorate([
|
|
|
107
219
|
tslib.__decorate([
|
|
108
220
|
decorators_js.property({ reflect: true })
|
|
109
221
|
], SgdsCheckboxGroup.prototype, "hintText", void 0);
|
|
222
|
+
tslib.__decorate([
|
|
223
|
+
decorators_js.property({ type: Boolean, reflect: true })
|
|
224
|
+
], SgdsCheckboxGroup.prototype, "required", void 0);
|
|
225
|
+
tslib.__decorate([
|
|
226
|
+
decorators_js.property({ type: String, reflect: true })
|
|
227
|
+
], SgdsCheckboxGroup.prototype, "value", void 0);
|
|
228
|
+
tslib.__decorate([
|
|
229
|
+
decorators_js.state()
|
|
230
|
+
], SgdsCheckboxGroup.prototype, "_isTouched", void 0);
|
|
231
|
+
tslib.__decorate([
|
|
232
|
+
decorators_js.state()
|
|
233
|
+
], SgdsCheckboxGroup.prototype, "defaultValue", void 0);
|
|
234
|
+
tslib.__decorate([
|
|
235
|
+
decorators_js.queryAssignedElements()
|
|
236
|
+
], SgdsCheckboxGroup.prototype, "_checkboxes", void 0);
|
|
237
|
+
tslib.__decorate([
|
|
238
|
+
watch.watch("value", { waitUntilFirstUpdate: true })
|
|
239
|
+
], SgdsCheckboxGroup.prototype, "_handleValueChange", null);
|
|
240
|
+
tslib.__decorate([
|
|
241
|
+
watch.watch("_isTouched", { waitUntilFirstUpdate: true })
|
|
242
|
+
], SgdsCheckboxGroup.prototype, "_handleIsTouched", null);
|
|
243
|
+
tslib.__decorate([
|
|
244
|
+
watch.watch("invalid", { waitUntilFirstUpdate: true })
|
|
245
|
+
], SgdsCheckboxGroup.prototype, "_updateInvalid", null);
|
|
110
246
|
|
|
111
247
|
exports.SgdsCheckboxGroup = SgdsCheckboxGroup;
|
|
112
248
|
exports["default"] = SgdsCheckboxGroup;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sgds-checkbox-group.cjs.js","sources":["../../../../src/components/Checkbox/sgds-checkbox-group.ts"],"sourcesContent":["import { html, nothing } from \"lit\";\nimport { queryAssignedElements, state, property } from \"lit/decorators.js\";\nimport SgdsElement from \"../../base/sgds-element\";\nimport feedbackStyles from \"../../styles/feedback.css\";\nimport formLabelStyles from \"../../styles/form-label.css\";\nimport checkboxGroupStyles from \"./checkbox-group.css\";\nimport formHintStyles from \"../../styles/form-hint.css\";\nimport SgdsCheckbox from \"./sgds-checkbox\";\n/**\n * @summary CheckboxGroup is the container that group multiple checkboxes under a single question field.\n * It handles the display of validation feedback of its checkboxes children.\n *\n * @slot default - Pass in `sgds-checkbox` into the default slot\n * @slot invalidIcon - The slot for invalid icon\n *\n */\nexport class SgdsCheckboxGroup extends SgdsElement {\n static styles = [...SgdsElement.styles, feedbackStyles, formLabelStyles, checkboxGroupStyles, formHintStyles];\n /**@internal */\n @queryAssignedElements({ flatten: true }) private checkboxes!: NodeListOf<SgdsCheckbox>;\n @state() private hasInvalidCheckbox = false;\n @state() private validationMessage: string;\n\n /** The checkbox group's label */\n @property({ reflect: true }) label = \"\";\n\n /**Feedback text for error state when validated */\n @property({ type: String, reflect: true }) invalidFeedback = \"\";\n\n /** Allows invalidFeedback, invalid styles to be visible. When SgdsCheckboxGroup is used, it overrides the value of hasFeedback on SgdsCheckbox with its own value. */\n @property({ type: Boolean, reflect: true }) hasFeedback = false;\n\n /** The checkbox group's hint text */\n @property({ reflect: true }) hintText = \"\";\n\n constructor() {\n super();\n this.addEventListener(\"sgds-validity-change\", (e: CustomEvent) => {\n this.hasInvalidCheckbox = e.detail.invalid;\n this.validationMessage = e.detail.validationMessage;\n });\n }\n\n private _checkInvalidState() {\n this.hasInvalidCheckbox = Array.from(this.checkboxes).some(checkbox => checkbox.invalid);\n }\n /** Overrides hasFeedback from individual SgdsCheckbox */\n private _forwardHasFeedback() {\n Array.from(this.checkboxes).forEach(checkbox => (checkbox.hasFeedback = this.hasFeedback));\n }\n\n protected _renderHintText() {\n const hintTextTemplate = html` <div class=\"form-text\">${this.hintText}</div> `;\n return this.hintText && hintTextTemplate;\n }\n\n firstUpdated() {\n this._forwardHasFeedback();\n }\n updated() {\n this._checkInvalidState();\n }\n render() {\n return html`\n <fieldset>\n <div class=\"label-hint-container\">\n <label class=\"form-label\">${this.label}</label>\n ${this._renderHintText()}\n </div>\n <div class=\"checkbox-container\">\n <slot></slot>\n </div>\n ${this.hasInvalidCheckbox && this.hasFeedback\n ? html`\n <div class=\"invalid-feedback-container\">\n <slot name=\"invalidIcon\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" fill=\"none\">\n <path\n d=\"M17.5 10C17.5 14.1421 14.1421 17.5 10 17.5C5.85786 17.5 2.5 14.1421 2.5 10C2.5 5.85786 5.85786 2.5 10 2.5C14.1421 2.5 17.5 5.85786 17.5 10ZM10 6.25C9.49805 6.25 9.10584 6.68339 9.15578 7.18285L9.48461 10.4711C9.51109 10.7359 9.7339 10.9375 10 10.9375C10.2661 10.9375 10.4889 10.7359 10.5154 10.4711L10.8442 7.18285C10.8942 6.68339 10.5019 6.25 10 6.25ZM10.0014 11.875C9.48368 11.875 9.06394 12.2947 9.06394 12.8125C9.06394 13.3303 9.48368 13.75 10.0014 13.75C10.5192 13.75 10.9389 13.3303 10.9389 12.8125C10.9389 12.2947 10.5192 11.875 10.0014 11.875Z\"\n fill=\"currentColor\"\n />\n </svg>\n </slot>\n <div id=\"checkbox-feedback\" tabindex=\"0\" class=\"invalid-feedback\">\n ${this.invalidFeedback ? this.invalidFeedback : this.validationMessage}\n </div>\n </div>\n `\n : nothing}\n </fieldset>\n `;\n }\n}\n\nexport default SgdsCheckboxGroup;\n"],"names":["SgdsElement","html","nothing","feedbackStyles","formLabelStyles","checkboxGroupStyles","formHintStyles","__decorate","queryAssignedElements","state","property"],"mappings":";;;;;;;;;;;;;;AAQA;;;;;;;AAOG;AACG,MAAO,iBAAkB,SAAQA,sBA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A,CAAA,CAAA,CAAA;AAGpBH,gBAAA,CAAA;IAA3CG,sBAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAAqB,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,aAAA,EAAA,KAAA,CAAA,CAAA,CAAA;AAGnCH,gBAAA,CAAA;AAA5B,IAAAG,sBAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAAe,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,UAAA,EAAA,KAAA,CAAA,CAAA;;;;;"}
|
|
1
|
+
{"version":3,"file":"sgds-checkbox-group.cjs.js","sources":["../../../../src/components/Checkbox/sgds-checkbox-group.ts"],"sourcesContent":["import { html, nothing, PropertyValues } from \"lit\";\nimport { queryAssignedElements, state, property, query, queryAsync } from \"lit/decorators.js\";\nimport SgdsElement from \"../../base/sgds-element\";\nimport feedbackStyles from \"../../styles/feedback.css\";\nimport formLabelStyles from \"../../styles/form-label.css\";\nimport checkboxGroupStyles from \"./checkbox-group.css\";\nimport formHintStyles from \"../../styles/form-hint.css\";\nimport SgdsCheckbox from \"./sgds-checkbox\";\nimport { SgdsFormValidatorMixin } from \"../../utils/validatorMixin\";\nimport FormControlElement from \"../../base/form-control-element\";\nimport { SgdsFormControl } from \"../../utils/formSubmitController\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport { live } from \"lit/directives/live.js\";\nimport { watch } from \"../../utils/watch\";\n/**\n * @summary CheckboxGroup is the container that group multiple checkboxes under a single question field.\n * It handles the display of validation feedback of its checkboxes children.\n *\n * @slot default - Pass in `sgds-checkbox` into the default slot\n * @slot invalidIcon - The slot for invalid icon\n *\n */\nexport class SgdsCheckboxGroup extends SgdsFormValidatorMixin(FormControlElement) implements SgdsFormControl {\n static styles = [...SgdsElement.styles, feedbackStyles, formLabelStyles, checkboxGroupStyles, formHintStyles];\n /**@internal */\n @queryAssignedElements({ flatten: true }) private checkboxes!: NodeListOf<SgdsCheckbox>;\n // @state() private hasInvalidCheckbox = false;\n @queryAsync(\"slot\") private checkboxesAsync!: Promise<HTMLSlotElement>;\n\n /** The checkbox group's label */\n @property({ reflect: true }) label = \"\";\n\n /**Feedback text for error state when validated */\n @property({ type: String, reflect: true }) invalidFeedback = \"\";\n\n /** Allows invalidFeedback, invalid styles to be visible. When SgdsCheckboxGroup is used, it overrides the value of hasFeedback on SgdsCheckbox with its own value. */\n @property({ type: Boolean, reflect: true }) hasFeedback = false;\n\n /** The checkbox group's hint text */\n @property({ reflect: true }) hintText = \"\";\n\n /** Makes the checkbox group a required field. Only available for when multiselect is true */\n @property({ type: Boolean, reflect: true }) required = false;\n\n /** Consolidates the values of its child checked checkboxes into a single string with semi-colon delimiter. Only available when required is true */\n @property({ type: String, reflect: true }) value = \"\";\n\n @state() private _isTouched = false;\n\n /**@internal */\n @state() defaultValue = \"\";\n\n connectedCallback() {\n super.connectedCallback();\n this.defaultValue = this.value;\n this.addEventListener(\"sgds-check\", (e: CustomEvent) => {\n const { value } = e.detail;\n !this.value.includes(value) && this._addValue(value);\n });\n this.addEventListener(\"sgds-uncheck\", (e: CustomEvent) => {\n const { value } = e.detail;\n this._removeValue(value);\n });\n this.addEventListener(\"sgds-blur\", () => {\n this._isTouched = true;\n });\n }\n\n protected _renderHintText() {\n const hintTextTemplate = html` <div class=\"form-text\">${this.hintText}</div> `;\n return this.hintText && hintTextTemplate;\n }\n\n @queryAssignedElements()\n private _checkboxes!: Array<SgdsCheckbox>;\n\n private _addValue(newValue: string) {\n const valueArray = this.value ? this.value.split(\";\") : [];\n valueArray.push(newValue);\n this.value = valueArray.join(\";\");\n }\n private _removeValue(oldValue: string) {\n const valueArray = this.value ? this.value.split(\";\") : [];\n const newValueArray = valueArray.filter(v => v !== oldValue);\n this.value = newValueArray.join(\";\");\n }\n\n private _sanitizeSlot() {\n const checkboxes = this._checkboxes;\n checkboxes.forEach(checkbox => {\n checkbox.checked = this.value.includes(checkbox.value);\n checkbox.hasFeedback = this.hasFeedback ? \"style\" : null;\n if (checkbox.required) {\n console.error(\"Checkboxes in a group cannot have required or hasFeedback prop set to true\");\n checkbox.remove();\n }\n });\n this._disabledChildCheckboxes();\n }\n\n private _disabledChildCheckboxes() {\n if (this.disabled) {\n const checkboxes = this._checkboxes;\n checkboxes.forEach(checkbox => (checkbox.disabled = this.disabled));\n }\n }\n\n @watch(\"value\", { waitUntilFirstUpdate: true })\n _handleValueChange() {\n const checkboxes = this._checkboxes;\n checkboxes.forEach(checkbox => {\n checkbox.checked = this.value.includes(checkbox.value);\n });\n this._updateInputValue();\n this._updateInvalid();\n }\n\n @watch(\"_isTouched\", { waitUntilFirstUpdate: true })\n _handleIsTouched() {\n if (this._isTouched) {\n this.invalid = !this.input.checkValidity();\n this._updateInvalid();\n }\n }\n @watch(\"invalid\", { waitUntilFirstUpdate: true })\n _updateInvalid() {\n const checkboxes = this._checkboxes;\n checkboxes.forEach(ch => (ch.invalid = this.invalid));\n }\n\n /**\n * Checks for validity. Under the hood, HTMLFormElement's reportValidity method calls this method to check for component's validity state\n * Note that the native error popup is prevented for SGDS form components by default. Instead the validation message shows up in the feedback container of SgdsInput\n */\n public reportValidity(): boolean {\n return this._mixinReportValidity();\n }\n /**\n * Checks for validity without any native error popup message\n */\n public checkValidity(): boolean {\n return this._mixinCheckValidity();\n }\n\n /**\n * Returns the ValidityState object\n */\n public get validity(): ValidityState {\n return this._mixinGetValidity();\n }\n /**\n * Returns the validation message based on the ValidityState\n */\n public get validationMessage() {\n return this._mixinGetValidationMessage();\n }\n /**\n * radio requries a custom _mixinResetFormControl as the update of input value\n * requires to fire a reset event manually\n * */\n private _mixinResetFormControl() {\n this.value = this.input.value = this.defaultValue;\n this._updateInputValue(\"reset\");\n this._mixinResetValidity(this.input);\n }\n /**\n * when input value is set programatically, need to manually dispatch a change event\n * In order to prevent race conditions and ensure sequence of events, set input's value here instead of binding to value prop of input\n */\n private _updateInputValue(eventName = \"change\") {\n this.input.value = this.value;\n this.input.dispatchEvent(new InputEvent(eventName));\n }\n firstUpdated(changedProperties) {\n super.firstUpdated(changedProperties);\n if (this.value) {\n this._updateInputValue();\n }\n }\n\n render() {\n return html`\n <fieldset>\n <div class=\"label-hint-container\">\n <label class=\"form-label\">${this.label}</label>\n ${this._renderHintText()}\n </div>\n <div class=\"checkbox-container\">\n <slot @slotchange=${this._sanitizeSlot}></slot>\n </div>\n <input\n type=\"text\"\n class=\"checkbox-group-validation-input ${classMap({\n \"is-invalid\": this.hasFeedback && this.invalid\n })}\"\n ?required=${this.required}\n tabindex=\"-1\"\n @change=${(e: Event) => {\n super._mixinHandleChange(e);\n }}\n .value=${live(this.value)}\n />\n ${this.invalid && this.hasFeedback\n ? html`\n <div class=\"invalid-feedback-container\">\n <slot name=\"invalidIcon\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" fill=\"none\">\n <path\n d=\"M17.5 10C17.5 14.1421 14.1421 17.5 10 17.5C5.85786 17.5 2.5 14.1421 2.5 10C2.5 5.85786 5.85786 2.5 10 2.5C14.1421 2.5 17.5 5.85786 17.5 10ZM10 6.25C9.49805 6.25 9.10584 6.68339 9.15578 7.18285L9.48461 10.4711C9.51109 10.7359 9.7339 10.9375 10 10.9375C10.2661 10.9375 10.4889 10.7359 10.5154 10.4711L10.8442 7.18285C10.8942 6.68339 10.5019 6.25 10 6.25ZM10.0014 11.875C9.48368 11.875 9.06394 12.2947 9.06394 12.8125C9.06394 13.3303 9.48368 13.75 10.0014 13.75C10.5192 13.75 10.9389 13.3303 10.9389 12.8125C10.9389 12.2947 10.5192 11.875 10.0014 11.875Z\"\n fill=\"currentColor\"\n />\n </svg>\n </slot>\n <div id=\"checkbox-feedback\" tabindex=\"0\" class=\"invalid-feedback\">\n ${this.invalidFeedback ? this.invalidFeedback : this.validationMessage}\n </div>\n </div>\n `\n : nothing}\n </fieldset>\n `;\n }\n}\n\nexport default SgdsCheckboxGroup;\n\ntype CheckedMode = \"click\" | \"key\";\n"],"names":["SgdsFormValidatorMixin","FormControlElement","html","classMap","live","nothing","SgdsElement","feedbackStyles","formLabelStyles","checkboxGroupStyles","formHintStyles","__decorate","queryAssignedElements","queryAsync","property","state","watch"],"mappings":";;;;;;;;;;;;;;;;;;;AAcA;;;;;;;AAOG;MACU,iBAAkB,SAAQA,qCAAsB,CAACC,6BAAkB,CAAC,CAAA;AAAjF,IAAA,WAAA,GAAA;;;QAQ+B,IAAK,CAAA,KAAA,GAAG,EAAE,CAAC;;QAGG,IAAe,CAAA,eAAA,GAAG,EAAE,CAAC;;QAGpB,IAAW,CAAA,WAAA,GAAG,KAAK,CAAC;;QAGnC,IAAQ,CAAA,QAAA,GAAG,EAAE,CAAC;;QAGC,IAAQ,CAAA,QAAA,GAAG,KAAK,CAAC;;QAGlB,IAAK,CAAA,KAAA,GAAG,EAAE,CAAC;QAErC,IAAU,CAAA,UAAA,GAAG,KAAK,CAAC;;QAG3B,IAAY,CAAA,YAAA,GAAG,EAAE,CAAC;KA4K5B;IA1KC,iBAAiB,GAAA;QACf,KAAK,CAAC,iBAAiB,EAAE,CAAC;AAC1B,QAAA,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC;QAC/B,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,CAAC,CAAc,KAAI;AACrD,YAAA,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC;AAC3B,YAAA,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACvD,SAAC,CAAC,CAAC;QACH,IAAI,CAAC,gBAAgB,CAAC,cAAc,EAAE,CAAC,CAAc,KAAI;AACvD,YAAA,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC;AAC3B,YAAA,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAC3B,SAAC,CAA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OAAO,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;AAQ9C,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,oBAAA,EAAA,IAAA,CAAA,CAAA;AAGDL,gBAAA,CAAA;IADCK,WAAK,CAAC,YAAY,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;AAMnD,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,kBAAA,EAAA,IAAA,CAAA,CAAA;AAEDL,gBAAA,CAAA;IADCK,WAAK,CAAC,SAAS,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;AAIhD,CAAA,EAAA,iBAAA,CAAA,SAAA,EAAA,gBAAA,EAAA,IAAA,CAAA;;;;;"}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { __decorate } from 'tslib';
|
|
3
3
|
import { html, nothing } from 'lit';
|
|
4
|
-
import { queryAssignedElements,
|
|
4
|
+
import { queryAssignedElements, queryAsync, property, state } from 'lit/decorators.js';
|
|
5
5
|
import SgdsElement from '../../base/sgds-element.js';
|
|
6
6
|
import css_248z from '../../styles/feedback.js';
|
|
7
7
|
import css_248z$1 from '../../styles/form-label.js';
|
|
8
8
|
import css_248z$2 from './checkbox-group.js';
|
|
9
9
|
import css_248z$3 from '../../styles/form-hint.js';
|
|
10
|
+
import { SgdsFormValidatorMixin } from '../../utils/validatorMixin.js';
|
|
11
|
+
import FormControlElement from '../../base/form-control-element.js';
|
|
12
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
13
|
+
import { live } from 'lit/directives/live.js';
|
|
14
|
+
import { watch } from '../../utils/watch.js';
|
|
10
15
|
|
|
11
16
|
/**
|
|
12
17
|
* @summary CheckboxGroup is the container that group multiple checkboxes under a single question field.
|
|
@@ -16,10 +21,9 @@ import css_248z$3 from '../../styles/form-hint.js';
|
|
|
16
21
|
* @slot invalidIcon - The slot for invalid icon
|
|
17
22
|
*
|
|
18
23
|
*/
|
|
19
|
-
class SgdsCheckboxGroup extends
|
|
24
|
+
class SgdsCheckboxGroup extends SgdsFormValidatorMixin(FormControlElement) {
|
|
20
25
|
constructor() {
|
|
21
|
-
super();
|
|
22
|
-
this.hasInvalidCheckbox = false;
|
|
26
|
+
super(...arguments);
|
|
23
27
|
/** The checkbox group's label */
|
|
24
28
|
this.label = "";
|
|
25
29
|
/**Feedback text for error state when validated */
|
|
@@ -28,27 +32,126 @@ class SgdsCheckboxGroup extends SgdsElement {
|
|
|
28
32
|
this.hasFeedback = false;
|
|
29
33
|
/** The checkbox group's hint text */
|
|
30
34
|
this.hintText = "";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.
|
|
35
|
+
/** Makes the checkbox group a required field. Only available for when multiselect is true */
|
|
36
|
+
this.required = false;
|
|
37
|
+
/** Consolidates the values of its child checked checkboxes into a single string with semi-colon delimiter. Only available when required is true */
|
|
38
|
+
this.value = "";
|
|
39
|
+
this._isTouched = false;
|
|
40
|
+
/**@internal */
|
|
41
|
+
this.defaultValue = "";
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
connectedCallback() {
|
|
44
|
+
super.connectedCallback();
|
|
45
|
+
this.defaultValue = this.value;
|
|
46
|
+
this.addEventListener("sgds-check", (e) => {
|
|
47
|
+
const { value } = e.detail;
|
|
48
|
+
!this.value.includes(value) && this._addValue(value);
|
|
49
|
+
});
|
|
50
|
+
this.addEventListener("sgds-uncheck", (e) => {
|
|
51
|
+
const { value } = e.detail;
|
|
52
|
+
this._removeValue(value);
|
|
53
|
+
});
|
|
54
|
+
this.addEventListener("sgds-blur", () => {
|
|
55
|
+
this._isTouched = true;
|
|
56
|
+
});
|
|
42
57
|
}
|
|
43
58
|
_renderHintText() {
|
|
44
59
|
const hintTextTemplate = html ` <div class="form-text">${this.hintText}</div> `;
|
|
45
60
|
return this.hintText && hintTextTemplate;
|
|
46
61
|
}
|
|
47
|
-
|
|
48
|
-
this.
|
|
62
|
+
_addValue(newValue) {
|
|
63
|
+
const valueArray = this.value ? this.value.split(";") : [];
|
|
64
|
+
valueArray.push(newValue);
|
|
65
|
+
this.value = valueArray.join(";");
|
|
66
|
+
}
|
|
67
|
+
_removeValue(oldValue) {
|
|
68
|
+
const valueArray = this.value ? this.value.split(";") : [];
|
|
69
|
+
const newValueArray = valueArray.filter(v => v !== oldValue);
|
|
70
|
+
this.value = newValueArray.join(";");
|
|
71
|
+
}
|
|
72
|
+
_sanitizeSlot() {
|
|
73
|
+
const checkboxes = this._checkboxes;
|
|
74
|
+
checkboxes.forEach(checkbox => {
|
|
75
|
+
checkbox.checked = this.value.includes(checkbox.value);
|
|
76
|
+
checkbox.hasFeedback = this.hasFeedback ? "style" : null;
|
|
77
|
+
if (checkbox.required) {
|
|
78
|
+
console.error("Checkboxes in a group cannot have required or hasFeedback prop set to true");
|
|
79
|
+
checkbox.remove();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
this._disabledChildCheckboxes();
|
|
83
|
+
}
|
|
84
|
+
_disabledChildCheckboxes() {
|
|
85
|
+
if (this.disabled) {
|
|
86
|
+
const checkboxes = this._checkboxes;
|
|
87
|
+
checkboxes.forEach(checkbox => (checkbox.disabled = this.disabled));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
_handleValueChange() {
|
|
91
|
+
const checkboxes = this._checkboxes;
|
|
92
|
+
checkboxes.forEach(checkbox => {
|
|
93
|
+
checkbox.checked = this.value.includes(checkbox.value);
|
|
94
|
+
});
|
|
95
|
+
this._updateInputValue();
|
|
96
|
+
this._updateInvalid();
|
|
97
|
+
}
|
|
98
|
+
_handleIsTouched() {
|
|
99
|
+
if (this._isTouched) {
|
|
100
|
+
this.invalid = !this.input.checkValidity();
|
|
101
|
+
this._updateInvalid();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
_updateInvalid() {
|
|
105
|
+
const checkboxes = this._checkboxes;
|
|
106
|
+
checkboxes.forEach(ch => (ch.invalid = this.invalid));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Checks for validity. Under the hood, HTMLFormElement's reportValidity method calls this method to check for component's validity state
|
|
110
|
+
* Note that the native error popup is prevented for SGDS form components by default. Instead the validation message shows up in the feedback container of SgdsInput
|
|
111
|
+
*/
|
|
112
|
+
reportValidity() {
|
|
113
|
+
return this._mixinReportValidity();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Checks for validity without any native error popup message
|
|
117
|
+
*/
|
|
118
|
+
checkValidity() {
|
|
119
|
+
return this._mixinCheckValidity();
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Returns the ValidityState object
|
|
123
|
+
*/
|
|
124
|
+
get validity() {
|
|
125
|
+
return this._mixinGetValidity();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Returns the validation message based on the ValidityState
|
|
129
|
+
*/
|
|
130
|
+
get validationMessage() {
|
|
131
|
+
return this._mixinGetValidationMessage();
|
|
49
132
|
}
|
|
50
|
-
|
|
51
|
-
|
|
133
|
+
/**
|
|
134
|
+
* radio requries a custom _mixinResetFormControl as the update of input value
|
|
135
|
+
* requires to fire a reset event manually
|
|
136
|
+
* */
|
|
137
|
+
_mixinResetFormControl() {
|
|
138
|
+
this.value = this.input.value = this.defaultValue;
|
|
139
|
+
this._updateInputValue("reset");
|
|
140
|
+
this._mixinResetValidity(this.input);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* when input value is set programatically, need to manually dispatch a change event
|
|
144
|
+
* In order to prevent race conditions and ensure sequence of events, set input's value here instead of binding to value prop of input
|
|
145
|
+
*/
|
|
146
|
+
_updateInputValue(eventName = "change") {
|
|
147
|
+
this.input.value = this.value;
|
|
148
|
+
this.input.dispatchEvent(new InputEvent(eventName));
|
|
149
|
+
}
|
|
150
|
+
firstUpdated(changedProperties) {
|
|
151
|
+
super.firstUpdated(changedProperties);
|
|
152
|
+
if (this.value) {
|
|
153
|
+
this._updateInputValue();
|
|
154
|
+
}
|
|
52
155
|
}
|
|
53
156
|
render() {
|
|
54
157
|
return html `
|
|
@@ -58,9 +161,21 @@ class SgdsCheckboxGroup extends SgdsElement {
|
|
|
58
161
|
${this._renderHintText()}
|
|
59
162
|
</div>
|
|
60
163
|
<div class="checkbox-container">
|
|
61
|
-
<slot></slot>
|
|
164
|
+
<slot @slotchange=${this._sanitizeSlot}></slot>
|
|
62
165
|
</div>
|
|
63
|
-
|
|
166
|
+
<input
|
|
167
|
+
type="text"
|
|
168
|
+
class="checkbox-group-validation-input ${classMap({
|
|
169
|
+
"is-invalid": this.hasFeedback && this.invalid
|
|
170
|
+
})}"
|
|
171
|
+
?required=${this.required}
|
|
172
|
+
tabindex="-1"
|
|
173
|
+
@change=${(e) => {
|
|
174
|
+
super._mixinHandleChange(e);
|
|
175
|
+
}}
|
|
176
|
+
.value=${live(this.value)}
|
|
177
|
+
/>
|
|
178
|
+
${this.invalid && this.hasFeedback
|
|
64
179
|
? html `
|
|
65
180
|
<div class="invalid-feedback-container">
|
|
66
181
|
<slot name="invalidIcon">
|
|
@@ -86,11 +201,8 @@ __decorate([
|
|
|
86
201
|
queryAssignedElements({ flatten: true })
|
|
87
202
|
], SgdsCheckboxGroup.prototype, "checkboxes", void 0);
|
|
88
203
|
__decorate([
|
|
89
|
-
|
|
90
|
-
], SgdsCheckboxGroup.prototype, "
|
|
91
|
-
__decorate([
|
|
92
|
-
state()
|
|
93
|
-
], SgdsCheckboxGroup.prototype, "validationMessage", void 0);
|
|
204
|
+
queryAsync("slot")
|
|
205
|
+
], SgdsCheckboxGroup.prototype, "checkboxesAsync", void 0);
|
|
94
206
|
__decorate([
|
|
95
207
|
property({ reflect: true })
|
|
96
208
|
], SgdsCheckboxGroup.prototype, "label", void 0);
|
|
@@ -103,6 +215,30 @@ __decorate([
|
|
|
103
215
|
__decorate([
|
|
104
216
|
property({ reflect: true })
|
|
105
217
|
], SgdsCheckboxGroup.prototype, "hintText", void 0);
|
|
218
|
+
__decorate([
|
|
219
|
+
property({ type: Boolean, reflect: true })
|
|
220
|
+
], SgdsCheckboxGroup.prototype, "required", void 0);
|
|
221
|
+
__decorate([
|
|
222
|
+
property({ type: String, reflect: true })
|
|
223
|
+
], SgdsCheckboxGroup.prototype, "value", void 0);
|
|
224
|
+
__decorate([
|
|
225
|
+
state()
|
|
226
|
+
], SgdsCheckboxGroup.prototype, "_isTouched", void 0);
|
|
227
|
+
__decorate([
|
|
228
|
+
state()
|
|
229
|
+
], SgdsCheckboxGroup.prototype, "defaultValue", void 0);
|
|
230
|
+
__decorate([
|
|
231
|
+
queryAssignedElements()
|
|
232
|
+
], SgdsCheckboxGroup.prototype, "_checkboxes", void 0);
|
|
233
|
+
__decorate([
|
|
234
|
+
watch("value", { waitUntilFirstUpdate: true })
|
|
235
|
+
], SgdsCheckboxGroup.prototype, "_handleValueChange", null);
|
|
236
|
+
__decorate([
|
|
237
|
+
watch("_isTouched", { waitUntilFirstUpdate: true })
|
|
238
|
+
], SgdsCheckboxGroup.prototype, "_handleIsTouched", null);
|
|
239
|
+
__decorate([
|
|
240
|
+
watch("invalid", { waitUntilFirstUpdate: true })
|
|
241
|
+
], SgdsCheckboxGroup.prototype, "_updateInvalid", null);
|
|
106
242
|
|
|
107
243
|
export { SgdsCheckboxGroup, SgdsCheckboxGroup as default };
|
|
108
244
|
//# sourceMappingURL=sgds-checkbox-group.js.map
|