@nysds/nys-checkbox 1.19.4 → 1.20.1
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/dist/index.d.ts +2 -0
- package/dist/nys-checkbox.d.ts +150 -0
- package/dist/nys-checkbox.figma.d.ts +1 -0
- package/dist/nys-checkbox.js +348 -189
- package/dist/nys-checkbox.js.map +1 -1
- package/dist/nys-checkboxgroup.d.ts +178 -0
- package/package.json +6 -4
package/dist/nys-checkbox.js
CHANGED
|
@@ -1,37 +1,150 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { property as
|
|
3
|
-
import { ifDefined as
|
|
1
|
+
import { LitElement as f, unsafeCSS as m, html as y, nothing as C } from "lit";
|
|
2
|
+
import { property as s, state as x } from "lit/decorators.js";
|
|
3
|
+
import { ifDefined as u } from "lit/directives/if-defined.js";
|
|
4
|
+
import "@nysds/nys-label";
|
|
5
|
+
import "@nysds/nys-errormessage";
|
|
6
|
+
import "@nysds/nys-icon";
|
|
7
|
+
import "@nysds/nys-textinput";
|
|
4
8
|
/*!
|
|
5
9
|
* █▄ █ █ █ █▀▀▀█ █▀▀▄ █▀▀▀█
|
|
6
10
|
* █ █ █ █▄▄▄█ ▀▀▀▄▄ █ █ ▀▀▀▄▄
|
|
7
11
|
* █ ▀█ █ █▄▄▄█ █▄▄▀ █▄▄▄█
|
|
8
12
|
*
|
|
9
|
-
* Checkbox Component v1.
|
|
13
|
+
* Checkbox Component v1.20.1
|
|
10
14
|
* Part of the New York State Design System
|
|
11
15
|
* Repository: https://github.com/its-hcd/nysds
|
|
12
16
|
* License: MIT
|
|
13
17
|
*/
|
|
14
|
-
const f = ':host{--_nys-checkbox-size: var(--nys-size-400, 32px);--_nys-checkbox-border-radius: var(--nys-radius-md, 4px);--_nys-checkbox-border-width: var(--nys-border-width-md, 2px);--_nys-checkbox-outline-color: var(--nys-color-focus, #004dd1);--_nys-checkbox-outline-width: var(--nys-border-width-md, 2px);--_nys-checkbox-outline-offset: var(--nys-space-2px, 2px);--_nys-checkbox-gap: var(--nys-space-150, 12px);--_nys-checkboxgroup-gap: var(--nys-space-200, 16px);--_nys-checkbox-font-family: var( --nys-font-family-ui, var( --nys-font-family-sans, "Proxima Nova", "Helvetica Neue", "Helvetica", "Arial", sans-serif ) );--_nys-checkbox-font-size: var(--nys-font-size-ui-md, 16px);--_nys-checkbox-font-weight: var(--nys-font-weight-regular, 400);--_nys-checkbox-font-weight--standalone: var(--nys-font-weight-semibold, 600);--_nys-checkbox-line-height: var(--nys-font-lineheight-ui-md, 24px);--_nys-checkbox-color: var( --nys-color-ink, var(--nys-color-neutral-900, #1b1b1b) );--_nys-checkbox-background-color: var(--nys-color-ink-reverse, #ffffff);--_nys-checkbox-border-color: var(--nys-color-neutral-600, #62666a);--_nys-checkbox-background-color--hover: var(--nys-color-neutral-50, #ededed);--_nys-checkbox-border-color--hover: var(--nys-color-ink, #1b1b1b);--_nys-checkbox-background-color--active: var( --nys-color-neutral-100, #d0d0ce );--_nys-checkbox-border-color--active: var(--nys-color-ink, #1b1b1b);--_nys-checkbox-background-color--checked: var(--nys-color-theme, #154973);--_nys-checkbox-border-color--checked: var(--nys-color-theme, #154973);--_nys-checkbox-background-color--checked--hover: var( --nys-color-theme-strong, #0e324f );--_nys-checkbox-border-color--checked--hover: var( --nys-color-theme-strong, #0e324f );--_nys-checkbox-background-color--checked--active: var( --nys-color-theme-stronger, #081b2b );--_nys-checkbox-border-color--checked--active: var( --nys-color-theme-stronger, #081b2b );--_nys-checkbox-background-color--disabled: var( --nys-color-ink-reverse, #f0f0f0 );--_nys-checkbox-border-color--disabled: var(--nys-color-neutral-400, #757575);--_nys-checkbox-color--disabled: var(--nys-color-text-disabled, #bec0c1);--_nys-checkbox-background-color--checked--disabled: var( --nys-color-neutral-100, #d0d0ce );--_nys-checkbox-border-color--checked--disabled: var( --nys-color-neutral-100, #d0d0ce )}:host([size=sm]){--_nys-checkbox-size: var(--nys-size-300, 24px);--_nys-checkbox-border-radius: var(--nys-radius-sm, 2px);--_nys-checkboxgroup-gap: var(--nys-space-100, 8px);--_nys-checkbox-gap: var(--nys-space-100, 8px)}:host([size=md]){--_nys-checkbox-size: var(--nys-size-400, 32px);--_nys-checkbox-border-radius: var(--nys-radius-md, 4px)}:host([tile]){--_nys-checkbox-border-width--tile: var(--nys-border-width-sm, 1px);--_nys-checkbox-border-radius--tile: var(--nys-radius-md, 4px);--_nys-checkbox-border-color--tile: var(--nys-color-neutral-100, #d0d0ce);--_nys-checkbox-background-color--tile: var(--nys-color-ink-reverse, #ffffff);--_nys-checkbox-padding--x--tile: var(--nys-space-250, 20px);--_nys-checkbox-padding--y--tile: var(--nys-space-200, 16px);--_nys-checkbox-border-color--tile--hover: var( --nys-color-neutral-700, #4a4d4f );--_nys-checkbox-background-color--tile--hover: var( --nys-color-ink-reverse, #ffffff );--_nys-checkbox-border-color--tile--active: var( --nys-color-neutral-900, #1b1b1b );--_nys-checkbox-background-color--tile--active: var( --nys-color-ink-reverse, #ffffff );--_nys-checkbox-border-color--tile--checked: var( --nys-color-theme-mid, #457aa5 );--_nys-checkbox-background-color--tile--checked: var( --nys-color-theme-faint, #f7fafd );--_nys-checkbox-background-color--tile--disabled: var( --nys-color-ink-reverse, #f0f0f0 );--_nys-checkbox-border-color--tile--disabled: var( --nys-color-neutral-100, #d0d0ce )}:host([tile][size=sm]){--_nys-checkbox-padding--x--tile: var(--nys-space-200, 16px);--_nys-checkbox-padding--y--tile: var(--nys-space-150, 12px)}:host([tile][showError]){--_nys-checkbox-border-color--tile: var(--nys-color-danger, #b52c2c);--_nys-checkbox-border-color--tile--hover: var(--nys-color-danger, #b52c2c);--_nys-checkbox-border-color--tile--active: var(--nys-color-danger, #b52c2c);--_nys-checkbox-border-color--tile--checked: var(--nys-color-danger, #b52c2c)}#single-error-message{--_nys-errormessage-margin-top: var(--nys-space-50, 4px)}.nys-checkboxgroup{display:flex;flex-direction:column;gap:var(--nys-space-200, 16px);font-family:var(--_nys-checkbox-font-family);font-size:var(--_nys-checkbox-font-size);line-height:var(--_nys-checkbox-line-height)}.nys-checkboxgroup__content{display:flex;flex-direction:column;gap:var(--_nys-checkboxgroup-gap)}.nys-checkbox{display:flex;flex-direction:column;border-radius:var(--_nys-checkbox-border-radius--tile);border:var(--_nys-checkbox-border-width--tile) solid var(--_nys-checkbox-border-color--tile);background:var(--_nys-checkbox-background-color--tile);padding:var(--_nys-checkbox-padding--y--tile) var(--_nys-checkbox-padding--x--tile)}.nys-checkbox .nys-checkbox__main-container{display:flex;font-family:var(--_nys-checkbox-font-family);font-size:var(--_nys-checkbox-font-size);line-height:var(--_nys-checkbox-line-height);align-items:center;gap:var(--_nys-checkbox-gap)}.nys-checkbox .nys-checkbox__main-container.has-description{align-items:flex-start}.nys-checkbox__checkbox-wrapper{position:relative;display:flex;justify-content:center;align-items:center;max-height:var(--_nys-checkbox-size)}.nys-checkbox__icon{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);pointer-events:none;color:var(--nys-color-ink-reverse, #ffffff)}.nys-checkbox__checkbox{appearance:none;background-repeat:no-repeat;background-position:center;width:var(--_nys-checkbox-size);min-width:var(--_nys-checkbox-size);min-height:var(--_nys-checkbox-size);height:var(--_nys-checkbox-size);max-width:var(--_nys-checkbox-size);max-height:var(--_nys-checkbox-size);border:solid var(--_nys-checkbox-border-width) var(--_nys-checkbox-border-color);background-color:var(--_nys-checkbox-background-color);border-radius:var(--_nys-checkbox-border-radius);outline-offset:var(--_nys-checkbox-outline-offset);outline:none;margin:0}.nys-checkbox:hover,.nys-checkbox:hover *{cursor:pointer}.nys-checkbox__checkbox:not(:disabled):checked{background-color:var(--_nys-checkbox-background-color--checked);border-color:var(--_nys-checkbox-border-color--checked)}:host([tile]) .nys-checkbox:has(.nys-checkbox__checkbox:not(:disabled):checked){border-color:var(--_nys-checkbox-border-color--tile--checked);background-color:var(--_nys-checkbox-background-color--tile--checked)}.nys-checkbox__checkbox:disabled:checked{background-color:var(--_nys-checkbox-background-color--checked--disabled);border-color:var(--_nys-checkbox-border-color--checked--disabled)}:host([tile]) .nys-checkbox:has(.nys-checkbox__checkbox:disabled:checked){border-color:var(--_nys-checkbox-border-color--tile--disabled);background-color:var(--_nys-checkbox-background-color--tile--disabled)}.nys-checkbox__checkbox:disabled{background-color:var(--_nys-checkbox-background-color--disabled);border-color:var(--_nys-checkbox-border-color--disabled);cursor:not-allowed}.nys-checkbox:has(.nys-checkbox__checkbox:disabled) *{color:var(--_nys-checkbox-color--disabled);cursor:not-allowed;--_nys-label-cursor: not-allowed;--_nys-label-color: var(--_nys-checkbox-color--disabled)}:host([tile]) .nys-checkbox:has(.nys-checkbox__checkbox:disabled){background-color:var(--_nys-checkbox-background-color--disabled);border-color:var(--_nys-checkbox-border-color--disabled);cursor:not-allowed}.nys-checkbox:hover .nys-checkbox__checkbox:not(:disabled):not(:checked),.nys-checkbox__checkbox:hover:not(:disabled):not(:checked){background-color:var(--_nys-checkbox-background-color--hover);border-color:var(--_nys-checkbox-border-color--hover)}:host([tile]) .nys-checkbox:hover:has(.nys-checkbox__checkbox:not(:disabled):not(:checked)){border-color:var(--_nys-checkbox-border-color--tile--hover);background-color:var(--_nys-checkbox-background-color--tile--hover);outline:solid var(--_nys-checkbox-border-width--tile) var(--_nys-checkbox-border-color--tile--hover)}.nys-checkbox:hover .nys-checkbox__checkbox:not(:disabled):checked,.nys-checkbox__checkbox:hover:not(:disabled):checked{border-color:var(--_nys-checkbox-border-color--checked--hover);background-color:var(--_nys-checkbox-background-color--checked--hover)}:host([tile]) .nys-checkbox:hover:has(.nys-checkbox__checkbox:not(:disabled):checked){outline:solid var(--_nys-checkbox-border-width--tile) var(--_nys-checkbox-border-color--tile--checked)}.nys-checkbox:active .nys-checkbox__checkbox:not(:disabled):not(:checked),.nys-checkbox__checkbox:active:not(:disabled):not(:checked){background-color:var(--_nys-checkbox-background-color--active);border-color:var(--_nys-checkbox-border-color--active)}:host([tile]) .nys-checkbox:has(.nys-checkbox__checkbox:active:not(:disabled):not(:checked)){border-color:var(--_nys-checkbox-border-color--tile--active);background-color:var(--_nys-checkbox-background-color--tile--active);outline:solid var(--_nys-checkbox-border-width--tile) var(--_nys-checkbox-border-color--tile--active)}.nys-checkbox:active .nys-checkbox__checkbox:not(:disabled):checked,.nys-checkbox__checkbox:active:not(:disabled):checked{border-color:var(--_nys-checkbox-border-color--checked--active);background-color:var(--_nys-checkbox-background-color--checked--active)}:host(:not([tile])) .nys-checkbox__checkbox:focus{outline:solid var(--_nys-checkbox-outline-width) var(--_nys-checkbox-outline-color)}:host([tile]) .nys-checkbox:has(*:focus-visible),:host([tile][showError]) .nys-checkbox:has(*:focus){outline:solid var(--_nys-checkbox-border-width--tile) var(--_nys-checkbox-outline-color)!important;border-color:var(--_nys-checkbox-outline-color)!important}:host(:not([tile])) .nys-checkbox__main-container>nys-label{--_nys-label-font-weight: var(--_nys-checkbox-font-weight)}:host(:not([tile])) .nys-checkbox__main-container>nys-label.standalone{--_nys-label-font-weight: var(--_nys-checkbox-font-weight--standalone)}:host([tile]) .nys-checkbox__main-container>nys-label{--_nys-description-font-style: normal}.nys-checkbox__required{color:var(--nys-color-danger, #b52c2c)}.nys-checkbox__requiredwrapper{display:flex;gap:3px}fieldset{all:unset;display:contents}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;border:0}.nys-checkbox__other-container{display:flex;padding-inline-start:calc(var(--_nys-checkbox-size) + var(--_nys-checkbox-gap))}';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
/*!
|
|
19
|
+
* New York State Design System v1.20.1
|
|
20
|
+
* Description: A design system for New York State's digital products.
|
|
21
|
+
* Repository: https://github.com/its-hcd/nysds
|
|
22
|
+
* License: MIT
|
|
23
|
+
*/
|
|
24
|
+
let S = 0;
|
|
25
|
+
function q(n) {
|
|
26
|
+
return `${n}-${Date.now()}-${S++}`;
|
|
27
|
+
}
|
|
28
|
+
function $(n) {
|
|
29
|
+
return n.filter((e) => !!e);
|
|
30
|
+
}
|
|
31
|
+
const I = {
|
|
32
|
+
labelledby: "ariaLabelledByElements",
|
|
33
|
+
describedby: "ariaDescribedByElements"
|
|
34
|
+
}, A = {
|
|
35
|
+
labelledby: "aria-label",
|
|
36
|
+
describedby: "aria-description"
|
|
37
|
+
};
|
|
38
|
+
function v(n, e, t) {
|
|
39
|
+
const r = $(t), o = I[e], c = A[e], i = n;
|
|
40
|
+
o in n && (i[o] = r.length ? r : null);
|
|
41
|
+
const b = r.map((k) => k.textContent?.trim() ?? "").filter(Boolean).join(" ");
|
|
42
|
+
b ? n.setAttribute(c, b) : n.removeAttribute(c);
|
|
43
|
+
}
|
|
44
|
+
const O = (n) => {
|
|
45
|
+
class e extends n {
|
|
46
|
+
get idPrefix() {
|
|
47
|
+
return this.localName || "nys-element";
|
|
48
|
+
}
|
|
49
|
+
ensureId() {
|
|
50
|
+
this.id || (this.id = q(this.idPrefix));
|
|
51
|
+
}
|
|
52
|
+
connectedCallback() {
|
|
53
|
+
super.connectedCallback(), this.ensureId();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return e;
|
|
57
|
+
}, V = (n) => {
|
|
58
|
+
class e extends O(n) {
|
|
59
|
+
constructor() {
|
|
60
|
+
super(...arguments), this.__internals = null;
|
|
61
|
+
}
|
|
62
|
+
get internals() {
|
|
63
|
+
if (this.__internals) return this.__internals;
|
|
64
|
+
if (typeof this.attachInternals == "function")
|
|
65
|
+
try {
|
|
66
|
+
this.__internals = this.attachInternals();
|
|
67
|
+
} catch {
|
|
68
|
+
this.__internals = null;
|
|
69
|
+
}
|
|
70
|
+
return this.__internals;
|
|
71
|
+
}
|
|
72
|
+
get defaultRole() {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
setHostAria(r, o) {
|
|
76
|
+
const c = this.internals;
|
|
77
|
+
if (c && r in c) {
|
|
78
|
+
c[r] = o;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const i = L(r);
|
|
82
|
+
o === null ? this.removeAttribute(i) : this.setAttribute(i, o);
|
|
83
|
+
}
|
|
84
|
+
reflectDefaultSemantics() {
|
|
85
|
+
const r = this.defaultRole;
|
|
86
|
+
r && this.setHostAria("role", r);
|
|
87
|
+
}
|
|
88
|
+
connectedCallback() {
|
|
89
|
+
super.connectedCallback(), this.reflectDefaultSemantics();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return e;
|
|
93
|
+
};
|
|
94
|
+
function L(n) {
|
|
95
|
+
if (n === "role") return "role";
|
|
96
|
+
const e = n.replace(/^aria/, "");
|
|
97
|
+
return "aria-" + e.charAt(0).toLowerCase() + e.slice(1);
|
|
98
|
+
}
|
|
99
|
+
const z = (n) => {
|
|
100
|
+
const e = class extends V(n) {
|
|
101
|
+
setFormValue(o) {
|
|
102
|
+
this.internals?.setFormValue(o ?? null);
|
|
103
|
+
}
|
|
104
|
+
setValidityFromState(o, c, i) {
|
|
105
|
+
const b = this.internals;
|
|
106
|
+
if (!b) return;
|
|
107
|
+
const k = Object.values(o).some(Boolean);
|
|
108
|
+
k ? b.setValidity(o, c ?? "Invalid value", i) : b.setValidity({}), this.setHostAria("ariaInvalid", k ? "true" : "false");
|
|
109
|
+
}
|
|
110
|
+
clearValidity() {
|
|
111
|
+
this.internals?.setValidity({}), this.setHostAria("ariaInvalid", "false");
|
|
112
|
+
}
|
|
113
|
+
checkValidity() {
|
|
114
|
+
return this.internals?.checkValidity() ?? !0;
|
|
115
|
+
}
|
|
116
|
+
reportValidity() {
|
|
117
|
+
return this.internals?.reportValidity() ?? !0;
|
|
118
|
+
}
|
|
119
|
+
formResetCallback() {
|
|
120
|
+
this.clearValidity();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
return e.formAssociated = !0, e;
|
|
124
|
+
}, g = /* @__PURE__ */ z(f), E = ':host{--_nys-checkbox-size: var(--nys-size-400, 32px);--_nys-checkbox-border-radius: var(--nys-radius-md, 4px);--_nys-checkbox-border-width: var(--nys-border-width-md, 2px);--_nys-checkbox-outline-color: var(--nys-color-focus, #004dd1);--_nys-checkbox-outline-width: var(--nys-border-width-md, 2px);--_nys-checkbox-outline-offset: var(--nys-space-2px, 2px);--_nys-checkbox-gap: var(--nys-space-150, 12px);--_nys-checkboxgroup-gap: var(--nys-space-200, 16px);--_nys-checkbox-font-family: var( --nys-font-family-ui, var( --nys-font-family-sans, "Proxima Nova", "Helvetica Neue", "Helvetica", "Arial", sans-serif ) );--_nys-checkbox-font-size: var(--nys-font-size-ui-md, 16px);--_nys-checkbox-font-weight: var(--nys-font-weight-regular, 400);--_nys-checkbox-font-weight--standalone: var(--nys-font-weight-semibold, 600);--_nys-checkbox-line-height: var(--nys-font-lineheight-ui-md, 24px);--_nys-checkbox-color: var( --nys-color-ink, var(--nys-color-neutral-900, #1b1b1b) );--_nys-checkbox-background-color: var(--nys-color-ink-reverse, #ffffff);--_nys-checkbox-border-color: var(--nys-color-neutral-600, #62666a);--_nys-checkbox-background-color--hover: var(--nys-color-neutral-50, #ededed);--_nys-checkbox-border-color--hover: var(--nys-color-ink, #1b1b1b);--_nys-checkbox-background-color--active: var( --nys-color-neutral-100, #d0d0ce );--_nys-checkbox-border-color--active: var(--nys-color-ink, #1b1b1b);--_nys-checkbox-background-color--checked: var(--nys-color-theme, #154973);--_nys-checkbox-border-color--checked: var(--nys-color-theme, #154973);--_nys-checkbox-background-color--checked--hover: var( --nys-color-theme-strong, #0e324f );--_nys-checkbox-border-color--checked--hover: var( --nys-color-theme-strong, #0e324f );--_nys-checkbox-background-color--checked--active: var( --nys-color-theme-stronger, #081b2b );--_nys-checkbox-border-color--checked--active: var( --nys-color-theme-stronger, #081b2b );--_nys-checkbox-background-color--disabled: var( --nys-color-ink-reverse, #f0f0f0 );--_nys-checkbox-border-color--disabled: var(--nys-color-neutral-400, #757575);--_nys-checkbox-color--disabled: var(--nys-color-text-disabled, #bec0c1);--_nys-checkbox-background-color--checked--disabled: var( --nys-color-neutral-100, #d0d0ce );--_nys-checkbox-border-color--checked--disabled: var( --nys-color-neutral-100, #d0d0ce )}:host([size=sm]){--_nys-checkbox-size: var(--nys-size-300, 24px);--_nys-checkbox-border-radius: var(--nys-radius-sm, 2px);--_nys-checkboxgroup-gap: var(--nys-space-100, 8px);--_nys-checkbox-gap: var(--nys-space-100, 8px)}:host([size=md]){--_nys-checkbox-size: var(--nys-size-400, 32px);--_nys-checkbox-border-radius: var(--nys-radius-md, 4px)}:host([tile]){--_nys-checkbox-border-width--tile: var(--nys-border-width-sm, 1px);--_nys-checkbox-border-radius--tile: var(--nys-radius-md, 4px);--_nys-checkbox-border-color--tile: var(--nys-color-neutral-100, #d0d0ce);--_nys-checkbox-background-color--tile: var(--nys-color-ink-reverse, #ffffff);--_nys-checkbox-padding--x--tile: var(--nys-space-250, 20px);--_nys-checkbox-padding--y--tile: var(--nys-space-200, 16px);--_nys-checkbox-border-color--tile--hover: var( --nys-color-neutral-700, #4a4d4f );--_nys-checkbox-background-color--tile--hover: var( --nys-color-ink-reverse, #ffffff );--_nys-checkbox-border-color--tile--active: var( --nys-color-neutral-900, #1b1b1b );--_nys-checkbox-background-color--tile--active: var( --nys-color-ink-reverse, #ffffff );--_nys-checkbox-border-color--tile--checked: var( --nys-color-theme-mid, #457aa5 );--_nys-checkbox-background-color--tile--checked: var( --nys-color-theme-faint, #f7fafd );--_nys-checkbox-background-color--tile--disabled: var( --nys-color-ink-reverse, #f0f0f0 );--_nys-checkbox-border-color--tile--disabled: var( --nys-color-neutral-100, #d0d0ce )}:host([tile][size=sm]){--_nys-checkbox-padding--x--tile: var(--nys-space-200, 16px);--_nys-checkbox-padding--y--tile: var(--nys-space-150, 12px)}:host([tile][showError]){--_nys-checkbox-border-color--tile: var(--nys-color-danger, #b52c2c);--_nys-checkbox-border-color--tile--hover: var(--nys-color-danger, #b52c2c);--_nys-checkbox-border-color--tile--active: var(--nys-color-danger, #b52c2c);--_nys-checkbox-border-color--tile--checked: var(--nys-color-danger, #b52c2c)}.single-error-message{--_nys-errormessage-margin-top: var(--nys-space-50, 4px)}.nys-checkboxgroup{display:flex;flex-direction:column;gap:var(--nys-space-200, 16px);font-family:var(--_nys-checkbox-font-family);font-size:var(--_nys-checkbox-font-size);line-height:var(--_nys-checkbox-line-height)}.nys-checkboxgroup__content{display:flex;flex-direction:column;gap:var(--_nys-checkboxgroup-gap)}.nys-checkbox{display:flex;flex-direction:column;border-radius:var(--_nys-checkbox-border-radius--tile);border:var(--_nys-checkbox-border-width--tile) solid var(--_nys-checkbox-border-color--tile);background:var(--_nys-checkbox-background-color--tile);padding:var(--_nys-checkbox-padding--y--tile) var(--_nys-checkbox-padding--x--tile)}.nys-checkbox .nys-checkbox__main-container{display:flex;font-family:var(--_nys-checkbox-font-family);font-size:var(--_nys-checkbox-font-size);line-height:var(--_nys-checkbox-line-height);align-items:center;gap:var(--_nys-checkbox-gap)}.nys-checkbox .nys-checkbox__main-container.has-description{align-items:flex-start}.nys-checkbox__checkbox-wrapper{position:relative;display:flex;justify-content:center;align-items:center;max-height:var(--_nys-checkbox-size)}.nys-checkbox__icon{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);pointer-events:none;color:var(--nys-color-ink-reverse, #ffffff)}.nys-checkbox__checkbox{appearance:none;background-repeat:no-repeat;background-position:center;width:var(--_nys-checkbox-size);min-width:var(--_nys-checkbox-size);min-height:var(--_nys-checkbox-size);height:var(--_nys-checkbox-size);max-width:var(--_nys-checkbox-size);max-height:var(--_nys-checkbox-size);border:solid var(--_nys-checkbox-border-width) var(--_nys-checkbox-border-color);background-color:var(--_nys-checkbox-background-color);border-radius:var(--_nys-checkbox-border-radius);outline-offset:var(--_nys-checkbox-outline-offset);outline:none;margin:0}.nys-checkbox:hover,.nys-checkbox:hover *{cursor:pointer}.nys-checkbox__checkbox:not(:disabled):checked{background-color:var(--_nys-checkbox-background-color--checked);border-color:var(--_nys-checkbox-border-color--checked)}:host([tile]) .nys-checkbox:has(.nys-checkbox__checkbox:not(:disabled):checked){border-color:var(--_nys-checkbox-border-color--tile--checked);background-color:var(--_nys-checkbox-background-color--tile--checked)}.nys-checkbox__checkbox:disabled:checked{background-color:var(--_nys-checkbox-background-color--checked--disabled);border-color:var(--_nys-checkbox-border-color--checked--disabled)}:host([tile]) .nys-checkbox:has(.nys-checkbox__checkbox:disabled:checked){border-color:var(--_nys-checkbox-border-color--tile--disabled);background-color:var(--_nys-checkbox-background-color--tile--disabled)}.nys-checkbox__checkbox:disabled{background-color:var(--_nys-checkbox-background-color--disabled);border-color:var(--_nys-checkbox-border-color--disabled);cursor:not-allowed}.nys-checkbox:has(.nys-checkbox__checkbox:disabled) *{color:var(--_nys-checkbox-color--disabled);cursor:not-allowed;--_nys-label-cursor: not-allowed;--_nys-label-color: var(--_nys-checkbox-color--disabled)}:host([tile]) .nys-checkbox:has(.nys-checkbox__checkbox:disabled){background-color:var(--_nys-checkbox-background-color--disabled);border-color:var(--_nys-checkbox-border-color--disabled);cursor:not-allowed}.nys-checkbox:hover .nys-checkbox__checkbox:not(:disabled):not(:checked),.nys-checkbox__checkbox:hover:not(:disabled):not(:checked){background-color:var(--_nys-checkbox-background-color--hover);border-color:var(--_nys-checkbox-border-color--hover)}:host([tile]) .nys-checkbox:hover:has(.nys-checkbox__checkbox:not(:disabled):not(:checked)){border-color:var(--_nys-checkbox-border-color--tile--hover);background-color:var(--_nys-checkbox-background-color--tile--hover);outline:solid var(--_nys-checkbox-border-width--tile) var(--_nys-checkbox-border-color--tile--hover)}.nys-checkbox:hover .nys-checkbox__checkbox:not(:disabled):checked,.nys-checkbox__checkbox:hover:not(:disabled):checked{border-color:var(--_nys-checkbox-border-color--checked--hover);background-color:var(--_nys-checkbox-background-color--checked--hover)}:host([tile]) .nys-checkbox:hover:has(.nys-checkbox__checkbox:not(:disabled):checked){outline:solid var(--_nys-checkbox-border-width--tile) var(--_nys-checkbox-border-color--tile--checked)}.nys-checkbox:active .nys-checkbox__checkbox:not(:disabled):not(:checked),.nys-checkbox__checkbox:active:not(:disabled):not(:checked){background-color:var(--_nys-checkbox-background-color--active);border-color:var(--_nys-checkbox-border-color--active)}:host([tile]) .nys-checkbox:has(.nys-checkbox__checkbox:active:not(:disabled):not(:checked)){border-color:var(--_nys-checkbox-border-color--tile--active);background-color:var(--_nys-checkbox-background-color--tile--active);outline:solid var(--_nys-checkbox-border-width--tile) var(--_nys-checkbox-border-color--tile--active)}.nys-checkbox:active .nys-checkbox__checkbox:not(:disabled):checked,.nys-checkbox__checkbox:active:not(:disabled):checked{border-color:var(--_nys-checkbox-border-color--checked--active);background-color:var(--_nys-checkbox-background-color--checked--active)}:host(:not([tile])) .nys-checkbox__checkbox:focus{outline:solid var(--_nys-checkbox-outline-width) var(--_nys-checkbox-outline-color)}:host([tile]) .nys-checkbox:has(*:focus-visible),:host([tile][showError]) .nys-checkbox:has(*:focus){outline:solid var(--_nys-checkbox-border-width--tile) var(--_nys-checkbox-outline-color)!important;border-color:var(--_nys-checkbox-outline-color)!important}:host(:not([tile])) .nys-checkbox__main-container>nys-label{--_nys-label-font-weight: var(--_nys-checkbox-font-weight)}:host(:not([tile])) .nys-checkbox__main-container>nys-label.standalone{--_nys-label-font-weight: var(--_nys-checkbox-font-weight--standalone)}:host([tile]) .nys-checkbox__main-container>nys-label{--_nys-description-font-style: normal}.nys-checkbox__required{color:var(--nys-color-danger, #b52c2c)}.nys-checkbox__requiredwrapper{display:flex;gap:3px}fieldset{all:unset;display:contents}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;border:0}.nys-checkbox__other-container{display:flex;padding-inline-start:calc(var(--_nys-checkbox-size) + var(--_nys-checkbox-gap))}';
|
|
125
|
+
var R = Object.defineProperty, d = (n, e, t, r) => {
|
|
126
|
+
for (var o = void 0, c = n.length - 1, i; c >= 0; c--)
|
|
127
|
+
(i = n[c]) && (o = i(e, t, o) || o);
|
|
128
|
+
return o && R(e, t, o), o;
|
|
19
129
|
};
|
|
20
|
-
|
|
21
|
-
const u = class u extends x {
|
|
22
|
-
// allows use of elementInternals' API
|
|
130
|
+
const p = class p extends g {
|
|
23
131
|
constructor() {
|
|
24
|
-
super(), this.id = "", this.name = "", this.required = !1, this.optional = !1, this.showError = !1, this.errorMessage = "", this.label = "", this.description = "", this.tile = !1, this.tooltip = "", this.form = null, this.size = "md", this._slottedDescriptionText = "", this._hasOtherError = !1, this._otherErrorCheckbox = null, this._hasSharedNames = !1
|
|
132
|
+
super(...arguments), this.id = "", this.name = "", this.required = !1, this.optional = !1, this.showError = !1, this.errorMessage = "", this.label = "", this.description = "", this.tile = !1, this.tooltip = "", this.form = null, this.size = "md", this._slottedDescriptionText = "", this._hasOtherError = !1, this._otherErrorCheckbox = null, this._hasSharedNames = !1;
|
|
25
133
|
}
|
|
26
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Lifecycle methods
|
|
136
|
+
* --------------------------------------------------------------------------
|
|
137
|
+
* Form association, ElementInternals, and id generation are provided by
|
|
138
|
+
* NysFormControlElement (@nysds/internals).
|
|
139
|
+
*/
|
|
27
140
|
connectedCallback() {
|
|
28
|
-
super.connectedCallback(), this.
|
|
141
|
+
super.connectedCallback(), this.addEventListener("nys-change", this._handleCheckboxChange), this.addEventListener("nys-other-input", this._handleOtherInput), this.addEventListener("invalid", this._handleInvalid), this.addEventListener("nys-error", this._handleChildError), this.addEventListener("nys-error-clear", this._handleChildErrorClear);
|
|
29
142
|
}
|
|
30
143
|
disconnectedCallback() {
|
|
31
144
|
super.disconnectedCallback(), this.removeEventListener("nys-change", this._handleCheckboxChange), this.removeEventListener("nys-other-input", this._handleOtherInput), this.removeEventListener("invalid", this._handleInvalid), this.removeEventListener("nys-error", this._handleChildError), this.removeEventListener("nys-error-clear", this._handleChildErrorClear);
|
|
32
145
|
}
|
|
33
146
|
firstUpdated() {
|
|
34
|
-
this._setGroupExist(), this._updateCheckboxSize(), this._updateCheckboxTile(), this._updateCheckboxShowError()
|
|
147
|
+
this._setGroupExist(), this._updateCheckboxSize(), this._updateCheckboxTile(), this._updateCheckboxShowError();
|
|
35
148
|
}
|
|
36
149
|
updated(e) {
|
|
37
150
|
e.has("required") && this.required && this._setupCheckboxRequired(), e.has("size") && this._updateCheckboxSize(), e.has("tile") && this._updateCheckboxTile(), e.has("showError") && this._updateCheckboxShowError(), e.has("form") && this._updateCheckboxForm();
|
|
@@ -56,7 +169,7 @@ const u = class u extends x {
|
|
|
56
169
|
// Initial update on checkbox required attribute
|
|
57
170
|
async _setupCheckboxRequired() {
|
|
58
171
|
const e = this.querySelector("nys-checkbox"), t = this.errorMessage || "This field is required", r = e ? await e.getInputElement() : null;
|
|
59
|
-
this.
|
|
172
|
+
this.setValidityFromState(
|
|
60
173
|
{ valueMissing: !0 },
|
|
61
174
|
t,
|
|
62
175
|
r || this
|
|
@@ -65,21 +178,21 @@ const u = class u extends x {
|
|
|
65
178
|
// Updates the required attribute of each checkbox in the group
|
|
66
179
|
async _manageRequire() {
|
|
67
180
|
if (!this.required) {
|
|
68
|
-
this.
|
|
181
|
+
this.clearValidity(), this.showError = !1;
|
|
69
182
|
return;
|
|
70
183
|
}
|
|
71
184
|
const e = this.errorMessage || "You must make a selection to proceed.", t = Array.from(
|
|
72
185
|
this.querySelectorAll("nys-checkbox")
|
|
73
|
-
), r = this._hasAtLeastOneChecked(),
|
|
74
|
-
this.
|
|
186
|
+
), r = this._hasAtLeastOneChecked(), o = t ? await t[0].getInputElement().catch(() => null) : null;
|
|
187
|
+
this.clearValidity(), this.showError = !1, r ? this._hasOtherError && this._otherErrorCheckbox && (this._setCustomOtherError(), this.showError = !0) : this._hasOtherError ? (this._setCustomOtherError(), this.showError = !0) : (this.setValidityFromState(
|
|
75
188
|
{ valueMissing: !0 },
|
|
76
189
|
e,
|
|
77
|
-
|
|
190
|
+
o ?? this
|
|
78
191
|
), this.showError = !0);
|
|
79
192
|
}
|
|
80
193
|
_setCustomOtherError() {
|
|
81
194
|
const t = this._otherErrorCheckbox?.shadowRoot?.querySelector("nys-textinput") || this._otherErrorCheckbox;
|
|
82
|
-
this.
|
|
195
|
+
this.setValidityFromState(
|
|
83
196
|
{ customError: !0 },
|
|
84
197
|
"Please complete this field.",
|
|
85
198
|
t
|
|
@@ -117,19 +230,19 @@ const u = class u extends x {
|
|
|
117
230
|
formResetCallback() {
|
|
118
231
|
this.querySelectorAll("nys-checkbox").forEach((t) => {
|
|
119
232
|
t.formResetCallback();
|
|
120
|
-
}), this.
|
|
233
|
+
}), this.setFormValue(""), this.showError = !1, this.clearValidity(), this.requestUpdate();
|
|
121
234
|
}
|
|
122
235
|
async _handleInvalid(e) {
|
|
123
|
-
if (e.preventDefault(), this.
|
|
124
|
-
const
|
|
236
|
+
if (e.preventDefault(), this.internals?.validity.customError) {
|
|
237
|
+
const c = Array.from(
|
|
125
238
|
this.querySelectorAll("nys-checkbox")
|
|
126
239
|
).find(
|
|
127
|
-
(
|
|
240
|
+
(i) => i.other && i.checked
|
|
128
241
|
);
|
|
129
|
-
if (
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
132
|
-
await
|
|
242
|
+
if (c) {
|
|
243
|
+
const i = c.shadowRoot?.querySelector("nys-textinput");
|
|
244
|
+
if (i) {
|
|
245
|
+
await i.updateComplete, i.focus();
|
|
133
246
|
return;
|
|
134
247
|
}
|
|
135
248
|
}
|
|
@@ -137,17 +250,17 @@ const u = class u extends x {
|
|
|
137
250
|
this.showError = !0, await this._manageRequire();
|
|
138
251
|
const t = this.querySelector("nys-checkbox"), r = t ? await t.getInputElement() : null;
|
|
139
252
|
if (r) {
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
if (
|
|
253
|
+
const o = this.internals?.form;
|
|
254
|
+
o ? Array.from(o.elements).find((b) => {
|
|
255
|
+
if (b.tagName.toLowerCase() === "nys-checkboxgroup") {
|
|
143
256
|
if (Array.from(
|
|
144
257
|
this.querySelectorAll("nys-checkbox")
|
|
145
258
|
).filter(
|
|
146
|
-
(
|
|
259
|
+
(w) => w.checked
|
|
147
260
|
).length === 0)
|
|
148
|
-
return
|
|
261
|
+
return b;
|
|
149
262
|
} else
|
|
150
|
-
return typeof
|
|
263
|
+
return typeof b.checkValidity == "function" && !b.checkValidity();
|
|
151
264
|
}) === this && r.focus() : r.focus();
|
|
152
265
|
}
|
|
153
266
|
}
|
|
@@ -161,8 +274,8 @@ const u = class u extends x {
|
|
|
161
274
|
this.querySelectorAll("nys-checkbox")
|
|
162
275
|
);
|
|
163
276
|
if (this._hasSharedNames) {
|
|
164
|
-
const r = e, { name:
|
|
165
|
-
this.name =
|
|
277
|
+
const r = e, { name: o } = r.detail, c = t.filter((i) => i.checked).map((i) => i.value);
|
|
278
|
+
this.name = o, this.setFormValue(c.join(", "));
|
|
166
279
|
}
|
|
167
280
|
this._checkOtherInputs(t), this._hasOtherError || this._manageRequire();
|
|
168
281
|
}
|
|
@@ -173,13 +286,13 @@ const u = class u extends x {
|
|
|
173
286
|
}
|
|
174
287
|
_handleChildErrorClear(e) {
|
|
175
288
|
const r = e.detail?.sourceCheckbox;
|
|
176
|
-
this._otherErrorCheckbox && r !== this._otherErrorCheckbox || (this._hasOtherError = !1, this._otherErrorCheckbox = null, this.
|
|
289
|
+
this._otherErrorCheckbox && r !== this._otherErrorCheckbox || (this._hasOtherError = !1, this._otherErrorCheckbox = null, this.clearValidity(), this.showError = !1, this.required && !this._hasAtLeastOneChecked() && this._manageRequire());
|
|
177
290
|
}
|
|
178
291
|
_handleOtherInput() {
|
|
179
292
|
const t = Array.from(
|
|
180
293
|
this.querySelectorAll("nys-checkbox")
|
|
181
294
|
).filter((r) => r.checked).map((r) => r.value);
|
|
182
|
-
this.
|
|
295
|
+
this.setFormValue(t.join(", "));
|
|
183
296
|
}
|
|
184
297
|
async _checkOtherInputs(e) {
|
|
185
298
|
for (const t of e)
|
|
@@ -192,7 +305,7 @@ const u = class u extends x {
|
|
|
192
305
|
return;
|
|
193
306
|
}
|
|
194
307
|
}
|
|
195
|
-
this._hasOtherError && (this._hasOtherError = !1, this._otherErrorCheckbox = null, this.required ? this._manageRequire() : (this.
|
|
308
|
+
this._hasOtherError && (this._hasOtherError = !1, this._otherErrorCheckbox = null, this.required ? this._manageRequire() : (this.clearValidity(), this.showError = !1));
|
|
196
309
|
}
|
|
197
310
|
/** Drupal-like naming support **/
|
|
198
311
|
_checkSharedNames(e) {
|
|
@@ -201,96 +314,103 @@ const u = class u extends x {
|
|
|
201
314
|
return e.every((r) => r.name === t);
|
|
202
315
|
}
|
|
203
316
|
render() {
|
|
204
|
-
return
|
|
317
|
+
return y`
|
|
205
318
|
<fieldset
|
|
206
|
-
aria-
|
|
319
|
+
aria-labelledby=${u(
|
|
320
|
+
this.label ? this.id + "--label" : void 0
|
|
321
|
+
)}
|
|
322
|
+
aria-label=${u(
|
|
323
|
+
this.label ? void 0 : `${this._slottedDescriptionText || this.description || ""}`.trim() || void 0
|
|
324
|
+
)}
|
|
207
325
|
class="nys-checkboxgroup"
|
|
208
326
|
role="radiogroup"
|
|
209
327
|
>
|
|
210
328
|
<nys-label
|
|
329
|
+
id="${this.id}--label"
|
|
211
330
|
label=${this.label}
|
|
212
331
|
description=${this.description}
|
|
213
332
|
flag=${this.required ? "required" : this.optional ? "optional" : ""}
|
|
214
333
|
tooltip=${this.tooltip}
|
|
215
334
|
>
|
|
216
|
-
<slot
|
|
335
|
+
<slot
|
|
336
|
+
name="description"
|
|
337
|
+
slot="description"
|
|
338
|
+
@slotchange=${this._getSlotDescriptionForAria}
|
|
339
|
+
>${this.description}</slot
|
|
340
|
+
>
|
|
217
341
|
</nys-label>
|
|
218
342
|
<div class="nys-checkboxgroup__content">
|
|
219
343
|
<slot></slot>
|
|
220
344
|
</div>
|
|
221
345
|
<nys-errormessage
|
|
346
|
+
id=${this.id + "--error"}
|
|
222
347
|
?showError=${this.showError}
|
|
223
|
-
errorMessage=${this.
|
|
348
|
+
errorMessage=${this.internals?.validationMessage || this.errorMessage}
|
|
224
349
|
.showDivider=${!this.tile}
|
|
225
350
|
></nys-errormessage>
|
|
226
351
|
</fieldset>
|
|
227
352
|
`;
|
|
228
353
|
}
|
|
229
354
|
};
|
|
230
|
-
|
|
231
|
-
...
|
|
355
|
+
p.styles = m(E), p.shadowRootOptions = {
|
|
356
|
+
...f.shadowRootOptions,
|
|
232
357
|
delegatesFocus: !0
|
|
233
|
-
}, u.formAssociated = !0;
|
|
234
|
-
let n = u;
|
|
235
|
-
a([
|
|
236
|
-
o({ type: String, reflect: !0 })
|
|
237
|
-
], n.prototype, "id");
|
|
238
|
-
a([
|
|
239
|
-
o({ type: String, reflect: !0 })
|
|
240
|
-
], n.prototype, "name");
|
|
241
|
-
a([
|
|
242
|
-
o({ type: Boolean, reflect: !0 })
|
|
243
|
-
], n.prototype, "required");
|
|
244
|
-
a([
|
|
245
|
-
o({ type: Boolean, reflect: !0 })
|
|
246
|
-
], n.prototype, "optional");
|
|
247
|
-
a([
|
|
248
|
-
o({ type: Boolean, reflect: !0 })
|
|
249
|
-
], n.prototype, "showError");
|
|
250
|
-
a([
|
|
251
|
-
o({ type: String })
|
|
252
|
-
], n.prototype, "errorMessage");
|
|
253
|
-
a([
|
|
254
|
-
o({ type: String })
|
|
255
|
-
], n.prototype, "label");
|
|
256
|
-
a([
|
|
257
|
-
o({ type: String })
|
|
258
|
-
], n.prototype, "description");
|
|
259
|
-
a([
|
|
260
|
-
o({ type: Boolean, reflect: !0 })
|
|
261
|
-
], n.prototype, "tile");
|
|
262
|
-
a([
|
|
263
|
-
o({ type: String })
|
|
264
|
-
], n.prototype, "tooltip");
|
|
265
|
-
a([
|
|
266
|
-
o({ type: String, reflect: !0 })
|
|
267
|
-
], n.prototype, "form");
|
|
268
|
-
a([
|
|
269
|
-
o({ type: String, reflect: !0 })
|
|
270
|
-
], n.prototype, "size");
|
|
271
|
-
a([
|
|
272
|
-
_()
|
|
273
|
-
], n.prototype, "_slottedDescriptionText");
|
|
274
|
-
a([
|
|
275
|
-
_()
|
|
276
|
-
], n.prototype, "_hasOtherError");
|
|
277
|
-
a([
|
|
278
|
-
_()
|
|
279
|
-
], n.prototype, "_otherErrorCheckbox");
|
|
280
|
-
a([
|
|
281
|
-
_()
|
|
282
|
-
], n.prototype, "_hasSharedNames");
|
|
283
|
-
customElements.get("nys-checkboxgroup") || customElements.define("nys-checkboxgroup", n);
|
|
284
|
-
var w = Object.defineProperty, h = (b, e, t, r) => {
|
|
285
|
-
for (var s = void 0, l = b.length - 1, c; l >= 0; l--)
|
|
286
|
-
(c = b[l]) && (s = c(e, t, s) || s);
|
|
287
|
-
return s && w(e, t, s), s;
|
|
288
358
|
};
|
|
289
|
-
let
|
|
290
|
-
|
|
291
|
-
|
|
359
|
+
let l = p;
|
|
360
|
+
d([
|
|
361
|
+
s({ type: String, reflect: !0 })
|
|
362
|
+
], l.prototype, "id");
|
|
363
|
+
d([
|
|
364
|
+
s({ type: String, reflect: !0 })
|
|
365
|
+
], l.prototype, "name");
|
|
366
|
+
d([
|
|
367
|
+
s({ type: Boolean, reflect: !0 })
|
|
368
|
+
], l.prototype, "required");
|
|
369
|
+
d([
|
|
370
|
+
s({ type: Boolean, reflect: !0 })
|
|
371
|
+
], l.prototype, "optional");
|
|
372
|
+
d([
|
|
373
|
+
s({ type: Boolean, reflect: !0 })
|
|
374
|
+
], l.prototype, "showError");
|
|
375
|
+
d([
|
|
376
|
+
s({ type: String })
|
|
377
|
+
], l.prototype, "errorMessage");
|
|
378
|
+
d([
|
|
379
|
+
s({ type: String })
|
|
380
|
+
], l.prototype, "label");
|
|
381
|
+
d([
|
|
382
|
+
s({ type: String })
|
|
383
|
+
], l.prototype, "description");
|
|
384
|
+
d([
|
|
385
|
+
s({ type: Boolean, reflect: !0 })
|
|
386
|
+
], l.prototype, "tile");
|
|
387
|
+
d([
|
|
388
|
+
s({ type: String })
|
|
389
|
+
], l.prototype, "tooltip");
|
|
390
|
+
d([
|
|
391
|
+
s({ type: String, reflect: !0 })
|
|
392
|
+
], l.prototype, "form");
|
|
393
|
+
d([
|
|
394
|
+
s({ type: String, reflect: !0 })
|
|
395
|
+
], l.prototype, "size");
|
|
396
|
+
d([
|
|
397
|
+
x()
|
|
398
|
+
], l.prototype, "_slottedDescriptionText");
|
|
399
|
+
d([
|
|
400
|
+
x()
|
|
401
|
+
], l.prototype, "_hasOtherError");
|
|
402
|
+
d([
|
|
403
|
+
x()
|
|
404
|
+
], l.prototype, "_otherErrorCheckbox");
|
|
405
|
+
customElements.get("nys-checkboxgroup") || customElements.define("nys-checkboxgroup", l);
|
|
406
|
+
var M = Object.defineProperty, h = (n, e, t, r) => {
|
|
407
|
+
for (var o = void 0, c = n.length - 1, i; c >= 0; c--)
|
|
408
|
+
(i = n[c]) && (o = i(e, t, o) || o);
|
|
409
|
+
return o && M(e, t, o), o;
|
|
410
|
+
};
|
|
411
|
+
const _ = class _ extends g {
|
|
292
412
|
constructor() {
|
|
293
|
-
super(), this.checked = !1, this.disabled = !1, this.required = !1, this.label = "", this.description = "", this.id = "", this.name = "", this.value = "", this.form = null, this.showError = !1, this.errorMessage = "", this.groupExist = !1, this.tile = !1, this.tooltip = "", this.size = "md", this.other = !1, this.showOtherError = !1, this._mobileQuery = window.matchMedia("(max-width: 479px)"), this.isMobile = this._mobileQuery.matches, this._hasUserInteracted = !1, this._manageLabelClick = () => {
|
|
413
|
+
super(...arguments), this.checked = !1, this.disabled = !1, this.required = !1, this.label = "", this.description = "", this.id = "", this.name = "", this.value = "", this.form = null, this.showError = !1, this.errorMessage = "", this.groupExist = !1, this.tile = !1, this.tooltip = "", this.size = "md", this.other = !1, this.showOtherError = !1, this.labelledby = "", this.hideLabel = !1, this._mobileQuery = window.matchMedia("(max-width: 479px)"), this.isMobile = this._mobileQuery.matches, this._hasUserInteracted = !1, this._manageLabelClick = () => {
|
|
294
414
|
const e = this.shadowRoot?.querySelector(
|
|
295
415
|
".nys-checkbox__main-container"
|
|
296
416
|
), t = this.shadowRoot?.querySelector("input");
|
|
@@ -299,40 +419,68 @@ const k = class k extends x {
|
|
|
299
419
|
});
|
|
300
420
|
}, this._handleMobileQuery = () => {
|
|
301
421
|
this.isMobile = this._mobileQuery.matches;
|
|
302
|
-
}
|
|
422
|
+
};
|
|
303
423
|
}
|
|
304
424
|
// need this flag for "eager mode"
|
|
305
425
|
async getInputElement() {
|
|
306
426
|
return await this.updateComplete, this.shadowRoot?.querySelector("input") || null;
|
|
307
427
|
}
|
|
308
|
-
|
|
428
|
+
/**
|
|
429
|
+
* Lifecycle methods
|
|
430
|
+
* --------------------------------------------------------------------------
|
|
431
|
+
* Form association, ElementInternals, and id generation are provided by
|
|
432
|
+
* NysFormControlElement (@nysds/internals).
|
|
433
|
+
*/
|
|
309
434
|
connectedCallback() {
|
|
310
|
-
super.connectedCallback(), this.
|
|
435
|
+
super.connectedCallback(), this.addEventListener("invalid", this._handleInvalid), this.addEventListener("blur", this._handleBlur), this._mobileQuery.addEventListener("change", this._handleMobileQuery);
|
|
311
436
|
}
|
|
312
437
|
disconnectedCallback() {
|
|
313
438
|
super.disconnectedCallback(), this.removeEventListener("invalid", this._handleInvalid), this.removeEventListener("blur", this._handleBlur), this._mobileQuery.removeEventListener("change", this._handleMobileQuery);
|
|
314
439
|
}
|
|
315
440
|
firstUpdated() {
|
|
316
|
-
this._setValue(), this._manageRequire(), this._manageLabelClick();
|
|
441
|
+
this._setValue(), this._manageRequire(), this._manageLabelClick(), this.labelledby && this._syncExternalLabel();
|
|
442
|
+
}
|
|
443
|
+
willUpdate(e) {
|
|
444
|
+
if (e.has("labelledby") && !this.labelledby) {
|
|
445
|
+
const t = this.shadowRoot?.querySelector("input");
|
|
446
|
+
t && v(t, "labelledby", []);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
updated(e) {
|
|
450
|
+
e.has("labelledby") && this.labelledby && this._syncExternalLabel();
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Point the native <input> at a light-DOM element that IDREF attributes cannot
|
|
454
|
+
* reach across the shadow boundary. associateControlRefs sets the control's own
|
|
455
|
+
* ariaLabelledByElements (honored in Chromium) plus a string aria-label fallback
|
|
456
|
+
* for engines that do not yet resolve element references.
|
|
457
|
+
*
|
|
458
|
+
* Only ever called with an external labelledby set: with no external target the
|
|
459
|
+
* native input keeps the internal same-root aria-labelledby IDREF that render()
|
|
460
|
+
* emits, and must not be touched.
|
|
461
|
+
*/
|
|
462
|
+
_syncExternalLabel() {
|
|
463
|
+
const e = this.shadowRoot?.querySelector("input");
|
|
464
|
+
if (!e) return;
|
|
465
|
+
const t = this.getRootNode().getElementById(
|
|
466
|
+
this.labelledby
|
|
467
|
+
);
|
|
468
|
+
v(e, "labelledby", [t]);
|
|
317
469
|
}
|
|
318
470
|
/**
|
|
319
471
|
* Form Integration
|
|
320
472
|
* --------------------------------------------------------------------------
|
|
321
473
|
*/
|
|
322
474
|
_setValue() {
|
|
323
|
-
this.groupExist || this.
|
|
475
|
+
this.groupExist || this.setFormValue(this.checked ? this.value : null);
|
|
324
476
|
}
|
|
325
477
|
_manageRequire() {
|
|
326
478
|
const e = this.shadowRoot?.querySelector("input"), t = this.errorMessage || "This field is required";
|
|
327
|
-
e && (this.required && !this.checked ?
|
|
479
|
+
e && (this.required && !this.checked ? this.setValidityFromState({ valueMissing: !0 }, t, e) : this.clearValidity());
|
|
328
480
|
}
|
|
329
481
|
_setValidityMessage(e = "") {
|
|
330
482
|
const t = this.shadowRoot?.querySelector("input");
|
|
331
|
-
t && (this.showError = !!e, this.errorMessage?.trim() && e !== "" && (e = this.errorMessage), this.
|
|
332
|
-
e ? { customError: !0 } : {},
|
|
333
|
-
e,
|
|
334
|
-
t
|
|
335
|
-
));
|
|
483
|
+
t && (this.showError = !!e, this.errorMessage?.trim() && e !== "" && (e = this.errorMessage), e ? this.setValidityFromState({ customError: !0 }, e, t) : this.clearValidity());
|
|
336
484
|
}
|
|
337
485
|
_validate() {
|
|
338
486
|
const e = this.shadowRoot?.querySelector("input");
|
|
@@ -343,9 +491,9 @@ const k = class k extends x {
|
|
|
343
491
|
}
|
|
344
492
|
// Called automatically when the parent form is reset
|
|
345
493
|
formResetCallback() {
|
|
346
|
-
this.checked = !1, this.
|
|
494
|
+
this.checked = !1, this.setFormValue(null);
|
|
347
495
|
const e = this.shadowRoot?.querySelector("input");
|
|
348
|
-
e && (e.checked = !1), this.showError = !1, this.errorMessage = "", this.
|
|
496
|
+
e && (e.checked = !1), this.showError = !1, this.errorMessage = "", this.clearValidity(), this.requestUpdate();
|
|
349
497
|
}
|
|
350
498
|
/**
|
|
351
499
|
* Functions
|
|
@@ -362,9 +510,9 @@ const k = class k extends x {
|
|
|
362
510
|
e.preventDefault(), this.showError = !0, this._validate();
|
|
363
511
|
const t = this.shadowRoot?.querySelector("input");
|
|
364
512
|
if (t) {
|
|
365
|
-
const r = this.
|
|
513
|
+
const r = this.internals?.form;
|
|
366
514
|
r ? Array.from(r.elements).find(
|
|
367
|
-
(
|
|
515
|
+
(i) => typeof i.checkValidity == "function" && !i.checkValidity()
|
|
368
516
|
) === this && t.focus() : t.focus();
|
|
369
517
|
}
|
|
370
518
|
}
|
|
@@ -405,7 +553,7 @@ const k = class k extends x {
|
|
|
405
553
|
// Handle checkbox change event
|
|
406
554
|
async _handleChange(e) {
|
|
407
555
|
const { checked: t } = e.target, r = this.checked;
|
|
408
|
-
this.checked = t, this.groupExist || this.
|
|
556
|
+
this.checked = t, this.groupExist || this.setFormValue(this.checked ? this.value : null), this.other && r && !t && (this.showOtherError = !1, this._hasUserInteracted = !1, this._dispatchClearError()), this._validate(), this._emitChangeEvent();
|
|
409
557
|
}
|
|
410
558
|
_handleFocus() {
|
|
411
559
|
this.dispatchEvent(new Event("nys-focus"));
|
|
@@ -417,7 +565,7 @@ const k = class k extends x {
|
|
|
417
565
|
this._hasUserInteracted = !0, this._validateOtherAndEmitError();
|
|
418
566
|
}
|
|
419
567
|
async _handleKeydown(e) {
|
|
420
|
-
e.code === "Space" && (e.preventDefault(), this.disabled || (this.checked = !this.checked, this.
|
|
568
|
+
e.code === "Space" && (e.preventDefault(), this.disabled || (this.checked = !this.checked, this.setFormValue(this.checked ? this.value : null), await this.updateComplete, this._validate(), this._emitChangeEvent()));
|
|
421
569
|
}
|
|
422
570
|
_handleTextInput(e) {
|
|
423
571
|
let r = e.target.value;
|
|
@@ -454,7 +602,7 @@ const k = class k extends x {
|
|
|
454
602
|
);
|
|
455
603
|
}
|
|
456
604
|
render() {
|
|
457
|
-
return
|
|
605
|
+
return y`
|
|
458
606
|
<div class="nys-checkbox">
|
|
459
607
|
<div
|
|
460
608
|
class="nys-checkbox__main-container ${this._hasDescription ? "has-description" : ""}"
|
|
@@ -464,44 +612,48 @@ const k = class k extends x {
|
|
|
464
612
|
id=${this.id + "--native"}
|
|
465
613
|
class="nys-checkbox__checkbox"
|
|
466
614
|
type="checkbox"
|
|
467
|
-
name="${
|
|
615
|
+
name="${u(this.name ? this.name : void 0)}"
|
|
468
616
|
.checked=${this.checked}
|
|
469
617
|
?disabled=${this.disabled}
|
|
470
618
|
.value=${this.value}
|
|
471
619
|
?required="${this.required}"
|
|
472
|
-
form=${
|
|
620
|
+
form=${u(this.form || void 0)}
|
|
473
621
|
aria-checked="${this.checked}"
|
|
474
622
|
aria-disabled="${this.disabled ? "true" : "false"}"
|
|
475
623
|
aria-required="${this.required}"
|
|
476
|
-
aria-
|
|
624
|
+
aria-invalid=${this.showError ? "true" : "false"}
|
|
625
|
+
aria-errormessage=${this.id + "--error"}
|
|
626
|
+
aria-describedby=${u(
|
|
627
|
+
this.showError ? this.id + "--error" : void 0
|
|
628
|
+
)}
|
|
477
629
|
@change="${this._handleChange}"
|
|
478
630
|
@focus="${this._handleFocus}"
|
|
479
631
|
@keydown="${this._handleKeydown}"
|
|
480
|
-
aria-
|
|
632
|
+
aria-labelledby=${u(
|
|
633
|
+
!this.labelledby && (this.label || this.other) ? this.id + "--label" : void 0
|
|
634
|
+
)}
|
|
481
635
|
/>
|
|
482
|
-
${this.checked ?
|
|
636
|
+
${this.checked ? y`<nys-icon
|
|
483
637
|
name="check"
|
|
484
638
|
size="${this.size === "md" ? "4xl" : this.size === "sm" ? "2xl" : "4xl"}"
|
|
485
639
|
class="nys-checkbox__icon"
|
|
486
640
|
></nys-icon>` : ""}
|
|
487
641
|
</div>
|
|
488
|
-
${(this.label || this.other)
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
class=${this._isStandalone ? "standalone" : ""}
|
|
496
|
-
>
|
|
497
|
-
<slot name="description" slot="description"
|
|
498
|
-
>${this.description}</slot
|
|
642
|
+
${this.hideLabel || this.labelledby || !(this.label || this.other) ? C : y`<nys-label
|
|
643
|
+
id="${this.id}--label"
|
|
644
|
+
tooltip=${this.tooltip}
|
|
645
|
+
label="${this.label || (this.other ? "Other" : "")}"
|
|
646
|
+
description=${u(this.description || void 0)}
|
|
647
|
+
flag=${u(this.required ? "required" : void 0)}
|
|
648
|
+
class=${this._isStandalone ? "standalone" : ""}
|
|
499
649
|
>
|
|
500
|
-
|
|
501
|
-
|
|
650
|
+
<slot name="description" slot="description"
|
|
651
|
+
>${this.description}</slot
|
|
652
|
+
>
|
|
653
|
+
</nys-label>`}
|
|
502
654
|
</div>
|
|
503
655
|
<div class="nys-checkbox__other-container">
|
|
504
|
-
${this.other && this.checked ?
|
|
656
|
+
${this.other && this.checked ? y`
|
|
505
657
|
<nys-textinput
|
|
506
658
|
.value=${this.value}
|
|
507
659
|
id=${"radiobutton-other-" + this.id}
|
|
@@ -515,77 +667,84 @@ const k = class k extends x {
|
|
|
515
667
|
` : ""}
|
|
516
668
|
</div>
|
|
517
669
|
</div>
|
|
518
|
-
${this.parentElement?.tagName.toLowerCase() !== "nys-checkboxgroup" ?
|
|
519
|
-
id
|
|
670
|
+
${this.parentElement?.tagName.toLowerCase() !== "nys-checkboxgroup" ? y`<nys-errormessage
|
|
671
|
+
id=${this.id + "--error"}
|
|
672
|
+
class="single-error-message"
|
|
520
673
|
?showError=${this.showError}
|
|
521
|
-
errorMessage=${this.
|
|
674
|
+
errorMessage=${this.internals?.validationMessage || this.errorMessage}
|
|
522
675
|
.showDivider=${!this.tile}
|
|
523
676
|
></nys-errormessage>` : ""}
|
|
524
677
|
`;
|
|
525
678
|
}
|
|
526
679
|
};
|
|
527
|
-
|
|
528
|
-
...
|
|
680
|
+
_.styles = m(E), _.shadowRootOptions = {
|
|
681
|
+
...f.shadowRootOptions,
|
|
529
682
|
delegatesFocus: !0
|
|
530
|
-
}
|
|
531
|
-
let
|
|
683
|
+
};
|
|
684
|
+
let a = _;
|
|
685
|
+
h([
|
|
686
|
+
s({ type: Boolean, reflect: !0 })
|
|
687
|
+
], a.prototype, "checked");
|
|
688
|
+
h([
|
|
689
|
+
s({ type: Boolean, reflect: !0 })
|
|
690
|
+
], a.prototype, "disabled");
|
|
532
691
|
h([
|
|
533
|
-
|
|
534
|
-
],
|
|
692
|
+
s({ type: Boolean, reflect: !0 })
|
|
693
|
+
], a.prototype, "required");
|
|
535
694
|
h([
|
|
536
|
-
|
|
537
|
-
],
|
|
695
|
+
s({ type: String })
|
|
696
|
+
], a.prototype, "label");
|
|
538
697
|
h([
|
|
539
|
-
|
|
540
|
-
],
|
|
698
|
+
s({ type: String })
|
|
699
|
+
], a.prototype, "description");
|
|
541
700
|
h([
|
|
542
|
-
|
|
543
|
-
],
|
|
701
|
+
s({ type: String, reflect: !0 })
|
|
702
|
+
], a.prototype, "id");
|
|
544
703
|
h([
|
|
545
|
-
|
|
546
|
-
],
|
|
704
|
+
s({ type: String, reflect: !0 })
|
|
705
|
+
], a.prototype, "name");
|
|
547
706
|
h([
|
|
548
|
-
|
|
549
|
-
],
|
|
707
|
+
s({ type: String })
|
|
708
|
+
], a.prototype, "value");
|
|
550
709
|
h([
|
|
551
|
-
|
|
552
|
-
],
|
|
710
|
+
s({ type: String, reflect: !0 })
|
|
711
|
+
], a.prototype, "form");
|
|
553
712
|
h([
|
|
554
|
-
|
|
555
|
-
],
|
|
713
|
+
s({ type: Boolean, reflect: !0 })
|
|
714
|
+
], a.prototype, "showError");
|
|
556
715
|
h([
|
|
557
|
-
|
|
558
|
-
],
|
|
716
|
+
s({ type: String })
|
|
717
|
+
], a.prototype, "errorMessage");
|
|
559
718
|
h([
|
|
560
|
-
|
|
561
|
-
],
|
|
719
|
+
s({ type: Boolean })
|
|
720
|
+
], a.prototype, "groupExist");
|
|
562
721
|
h([
|
|
563
|
-
|
|
564
|
-
],
|
|
722
|
+
s({ type: Boolean, reflect: !0 })
|
|
723
|
+
], a.prototype, "tile");
|
|
565
724
|
h([
|
|
566
|
-
|
|
567
|
-
],
|
|
725
|
+
s({ type: String })
|
|
726
|
+
], a.prototype, "tooltip");
|
|
568
727
|
h([
|
|
569
|
-
|
|
570
|
-
],
|
|
728
|
+
s({ type: String, reflect: !0 })
|
|
729
|
+
], a.prototype, "size");
|
|
571
730
|
h([
|
|
572
|
-
|
|
573
|
-
],
|
|
731
|
+
s({ type: Boolean, reflect: !0 })
|
|
732
|
+
], a.prototype, "other");
|
|
574
733
|
h([
|
|
575
|
-
|
|
576
|
-
],
|
|
734
|
+
s({ type: Boolean })
|
|
735
|
+
], a.prototype, "showOtherError");
|
|
577
736
|
h([
|
|
578
|
-
|
|
579
|
-
],
|
|
737
|
+
s({ type: String })
|
|
738
|
+
], a.prototype, "labelledby");
|
|
580
739
|
h([
|
|
581
|
-
|
|
582
|
-
],
|
|
740
|
+
s({ type: Boolean })
|
|
741
|
+
], a.prototype, "hideLabel");
|
|
583
742
|
h([
|
|
584
|
-
|
|
585
|
-
],
|
|
586
|
-
customElements.get("nys-checkbox") || customElements.define("nys-checkbox",
|
|
743
|
+
x()
|
|
744
|
+
], a.prototype, "isMobile");
|
|
745
|
+
customElements.get("nys-checkbox") || customElements.define("nys-checkbox", a);
|
|
587
746
|
export {
|
|
588
|
-
|
|
589
|
-
|
|
747
|
+
a as NysCheckbox,
|
|
748
|
+
l as NysCheckboxgroup
|
|
590
749
|
};
|
|
591
750
|
//# sourceMappingURL=nys-checkbox.js.map
|