@jack-henry/jh-elements 2.0.0-beta.10
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/LICENSE +201 -0
- package/NOTICE +26 -0
- package/README.md +13 -0
- package/components/badge/badge.js +73 -0
- package/components/button/button.js +953 -0
- package/components/card/card.js +343 -0
- package/components/checkbox/checkbox.js +601 -0
- package/components/checkbox-group/checkbox-group.js +241 -0
- package/components/divider/divider.js +91 -0
- package/components/icon/icon.js +96 -0
- package/components/input/input.js +1247 -0
- package/components/input-email/input-email.js +18 -0
- package/components/input-password/input-password.js +153 -0
- package/components/input-search/input-search.js +41 -0
- package/components/input-telephone/input-telephone.js +18 -0
- package/components/input-textarea/input-textarea.js +379 -0
- package/components/input-url/input-url.js +31 -0
- package/components/list-group/list-group.js +103 -0
- package/components/list-item/list-item.js +350 -0
- package/components/menu/menu.js +60 -0
- package/components/notification/notification.js +327 -0
- package/components/progress/progress.js +417 -0
- package/components/radio/radio.js +422 -0
- package/components/radio-group/radio-group.js +400 -0
- package/components/switch/switch.js +315 -0
- package/components/table/table.js +367 -0
- package/components/table-data-cell/table-data-cell.js +107 -0
- package/components/table-header-cell/table-header-cell.js +321 -0
- package/components/table-row/table-row.js +52 -0
- package/components/tag/tag.js +422 -0
- package/components/tag-group/tag-group.js +57 -0
- package/components/toast/toast.js +172 -0
- package/components/toast-controller/toast-controller.js +122 -0
- package/components/tooltip/tooltip.js +498 -0
- package/custom-elements.json +6892 -0
- package/index.d.ts +69 -0
- package/jsconfig.json +9 -0
- package/package.json +52 -0
- package/utils/themeProvider.js +32 -0
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2025 Jack Henry
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import { LitElement, css, html } from 'lit';
|
|
6
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
7
|
+
|
|
8
|
+
let id = 0;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @cssprop --jh-checkbox-opacity-disabled - The checkbox opacity when disabled. Defaults to `--jh-opacity-disabled`.
|
|
12
|
+
* @cssprop --jh-checkbox-input-border-radius - The checkbox border radius. Defaults to `--jh-border-radius-50`.
|
|
13
|
+
* @cssprop --jh-checkbox-color-focus - The checkbox outline when it receives keyboard focus. Defaults to `--jh-border-focus-color`.
|
|
14
|
+
* @cssprop --jh-checkbox-helper-color-text - The helper text color. Defaults to `--jh-color-content-secondary-enabled`.
|
|
15
|
+
* @cssprop --jh-checkbox-label-color-text - The label text color. Defaults to `--jh-color-content-primary-enabled`.
|
|
16
|
+
* @cssprop --jh-checkbox-input-color-background-unselected-enabled - The checkbox background-color when unselected. Defaults to `--jh-color-container-primary-enabled`.
|
|
17
|
+
* @cssprop --jh-checkbox-input-color-border-unselected-enabled - The checkbox border-color when unselected. Defaults to `--jh-border-control-color`.
|
|
18
|
+
* @cssprop --jh-checkbox-input-color-background-unselected-focus - The checkbox background-color when unselected and focused. Defaults to `--jh-color-container-primary-enabled`.
|
|
19
|
+
* @cssprop --jh-checkbox-input-color-border-unselected-focus - The checkbox border-color when unselected and focused. Defaults to `--jh-color-content-brand-hover`.
|
|
20
|
+
* @cssprop --jh-checkbox-input-color-background-unselected-hover - The checkbox background-color when unselected and hovered. Defaults to `--jh-color-container-primary-enabled`.
|
|
21
|
+
* @cssprop --jh-checkbox-input-color-border-unselected-hover - The checkbox border-color when unselected and hovered. Defaults to `--jh-color-content-brand-hover`.
|
|
22
|
+
* @cssprop --jh-checkbox-input-color-background-unselected-active - The checkbox background-color when unselected and active. Defaults to `--jh-color-container-primary-enabled`.
|
|
23
|
+
* @cssprop --jh-checkbox-input-color-border-unselected-active - The checkbox border-color when unselected and active. Defaults to `--jh-color-content-brand-active`.
|
|
24
|
+
* @cssprop --jh-checkbox-input-color-background-unselected-disabled - The checkbox background-color when unselected and disabled. Defaults to `--jh-color-container-primary-enabled`.
|
|
25
|
+
* @cssprop --jh-checkbox-input-color-border-unselected-disabled - The checkbox border-color when unselected and disabled. Defaults to `--jh-border-control-color`.
|
|
26
|
+
* @cssprop --jh-checkbox-input-color-background-selected-enabled - The checkbox background-color when selected. Defaults to `--jh-color-content-brand-enabled`.
|
|
27
|
+
* @cssprop --jh-checkbox-input-color-border-selected-enabled - The checkbox border-color when selected. Defaults to `--jh-color-content-brand-enabled`.
|
|
28
|
+
* @cssprop --jh-checkbox-status-color-border-selected-enabled - The status mark color when selected. Defaults to `--jh-color-content-on-brand-enabled`.
|
|
29
|
+
* @cssprop --jh-checkbox-input-color-background-selected-focus - The checkbox background-color when selected and focused. Defaults to `--jh-color-content-brand-hover`.
|
|
30
|
+
* @cssprop --jh-checkbox-input-color-border-selected-focus - The checkbox border-color when selected and focused. Defaults to `--jh-color-content-brand-hover`.
|
|
31
|
+
* @cssprop --jh-checkbox-status-color-border-selected-focus - The status mark color when selected and focused. Defaults to `--jh-color-content-on-brand-hover`.
|
|
32
|
+
* @cssprop --jh-checkbox-input-color-background-selected-hover - The checkbox background-color when selected and hovered. Defaults to `--jh-color-content-brand-hover`.
|
|
33
|
+
* @cssprop --jh-checkbox-input-color-border-selected-hover - The checkbox border-color when selected and hovered. Defaults to `--jh-color-content-brand-hover`.
|
|
34
|
+
* @cssprop --jh-checkbox-status-color-border-selected-hover - The status mark color when selected and hovered. Defaults to `--jh-color-content-on-brand-hover`.
|
|
35
|
+
* @cssprop --jh-checkbox-input-color-background-selected-active - The checkbox background-color when selected and active. Defaults to `--jh-color-content-brand-active`.
|
|
36
|
+
* @cssprop --jh-checkbox-input-color-border-selected-active - The checkbox border-color when selected and active. Defaults to `--jh-color-content-brand-active`.
|
|
37
|
+
* @cssprop --jh-checkbox-status-color-border-selected-active - The status mark color when selected and active. Defaults to `--jh-color-content-on-brand-active`.
|
|
38
|
+
* @cssprop --jh-checkbox-input-color-background-selected-disabled - The checkbox background-color when selected and disabled. Defaults to `--jh-color-content-brand-enabled`.
|
|
39
|
+
* @cssprop --jh-checkbox-input-color-border-selected-disabled - The checkbox border-color when selected and disabled. Defaults to `--jh-color-content-brand-enabled`.
|
|
40
|
+
* @cssprop --jh-checkbox-status-color-border-selected-disabled - The status mark color when selected and disabled. Defaults to `--jh-color-content-on-brand-enabled`.
|
|
41
|
+
* @cssprop --jh-checkbox-input-color-background-indeterminate-enabled - The checkbox background-color when indeterminate. Defaults to `--jh-color-content-brand-enabled`.
|
|
42
|
+
* @cssprop --jh-checkbox-input-color-border-indeterminate-enabled - The border-color when indeterminate checkbox. Defaults to `--jh-color-content-brand-enabled`.
|
|
43
|
+
* @cssprop --jh-checkbox-status-color-border-indeterminate-enabled - The status mark color when indeterminate. Defaults to `--jh-color-content-on-brand-enabled`.
|
|
44
|
+
* @cssprop --jh-checkbox-input-color-background-indeterminate-focus - The checkbox background-color when indeterminate and focused. Defaults to `--jh-color-content-brand-hover`.
|
|
45
|
+
* @cssprop --jh-checkbox-input-color-border-indeterminate-focus - The checkbox border-color when indeterminate and focused. Defaults to `--jh-color-content-brand-hover`.
|
|
46
|
+
* @cssprop --jh-checkbox-status-color-border-indeterminate-focus - The checkbox color when indeterminate status mark when focused. Defaults to `--jh-color-content-on-brand-hover`.
|
|
47
|
+
* @cssprop --jh-checkbox-input-color-background-indeterminate-hover - The checkbox background-color when indeterminate and hovered. Defaults to `--jh-color-content-brand-hover`.
|
|
48
|
+
* @cssprop --jh-checkbox-input-color-border-indeterminate-hover - The checkbox border-color when indeterminate and hovered. Defaults to `--jh-color-content-brand-hover`.
|
|
49
|
+
* @cssprop --jh-checkbox-status-color-border-indeterminate-hover - The checkbox color when indeterminate status mark when hovered. Defaults to `--jh-color-content-on-brand-hover`.
|
|
50
|
+
* @cssprop --jh-checkbox-input-color-background-indeterminate-active - The checkbox background-color when indeterminate and active. Defaults to `--jh-color-content-brand-active`.
|
|
51
|
+
* @cssprop --jh-checkbox-input-color-border-indeterminate-active - The checkbox border-color when indeterminate and active. Defaults to `--jh-color-content-brand-active`.
|
|
52
|
+
* @cssprop --jh-checkbox-status-color-border-indeterminate-active - The checkbox color when indeterminate status mark when active. Defaults to `--jh-color-content-on-brand-active`.
|
|
53
|
+
* @cssprop --jh-checkbox-input-color-background-indeterminate-disabled - The checkbox background-color when indeterminate and disabled. Defaults to `--jh-color-content-brand-enabled`.
|
|
54
|
+
* @cssprop --jh-checkbox-input-color-border-indeterminate-disabled - The checkbox border-color when indeterminate and disabled. Defaults to `--jh-color-content-brand-enabled`.
|
|
55
|
+
* @cssprop --jh-checkbox-status-color-border-indeterminate-disabled - The checkbox color when indeterminate status mark when disabled. Defaults to `--jh-color-content-on-brand-enabled`.
|
|
56
|
+
*
|
|
57
|
+
* @event jh-change - Dispatched when the state of the checkbox has changed.
|
|
58
|
+
*
|
|
59
|
+
* @customElement jh-checkbox
|
|
60
|
+
*/
|
|
61
|
+
export class JhCheckbox extends LitElement {
|
|
62
|
+
static get formAssociated() {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
/** @type {?Boolean} */
|
|
66
|
+
#checked;
|
|
67
|
+
/** @type {?Number} */
|
|
68
|
+
#id;
|
|
69
|
+
/** @type {?Boolean} */
|
|
70
|
+
#indeterminate;
|
|
71
|
+
/** @type {ElementInternals} */
|
|
72
|
+
#internals;
|
|
73
|
+
/** @type {?string} */
|
|
74
|
+
#value;
|
|
75
|
+
|
|
76
|
+
static get styles() {
|
|
77
|
+
return css`
|
|
78
|
+
:host {
|
|
79
|
+
font-family: var(--jh-font-body-regular-1-font-family);
|
|
80
|
+
font-weight: var(--jh-font-body-regular-1-font-weight);
|
|
81
|
+
font-size: var(--jh-font-body-regular-1-font-size);
|
|
82
|
+
line-height: var(--jh-font-body-regular-1-line-height);
|
|
83
|
+
display: inline-flex;
|
|
84
|
+
position: relative;
|
|
85
|
+
}
|
|
86
|
+
input {
|
|
87
|
+
width: var(--jh-dimension-500);
|
|
88
|
+
height: var(--jh-dimension-500);
|
|
89
|
+
position: absolute;
|
|
90
|
+
opacity: 0;
|
|
91
|
+
cursor: pointer;
|
|
92
|
+
z-index: 2;
|
|
93
|
+
box-sizing: border-box;
|
|
94
|
+
}
|
|
95
|
+
span {
|
|
96
|
+
background-color: var(
|
|
97
|
+
--jh-checkbox-input-color-background-unselected-enabled,
|
|
98
|
+
var(--jh-color-container-primary-enabled)
|
|
99
|
+
);
|
|
100
|
+
border-width: var(--jh-border-control-width);
|
|
101
|
+
border-style: var(--jh-border-control-style);
|
|
102
|
+
border-color: var(
|
|
103
|
+
--jh-checkbox-input-color-border-unselected-enabled,
|
|
104
|
+
var(--jh-border-control-color)
|
|
105
|
+
);
|
|
106
|
+
border-radius: var(
|
|
107
|
+
--jh-checkbox-input-border-radius,
|
|
108
|
+
var(--jh-border-radius-50)
|
|
109
|
+
);
|
|
110
|
+
width: var(--jh-dimension-500);
|
|
111
|
+
height: var(--jh-dimension-500);
|
|
112
|
+
box-sizing: border-box;
|
|
113
|
+
display: inline-block;
|
|
114
|
+
position: relative;
|
|
115
|
+
}
|
|
116
|
+
span::before,
|
|
117
|
+
span::after {
|
|
118
|
+
content: '';
|
|
119
|
+
position: absolute;
|
|
120
|
+
}
|
|
121
|
+
.label-container {
|
|
122
|
+
margin-left: var(--jh-dimension-200);
|
|
123
|
+
flex: 1;
|
|
124
|
+
}
|
|
125
|
+
.label-text,
|
|
126
|
+
.helper-text {
|
|
127
|
+
word-break: break-word;
|
|
128
|
+
}
|
|
129
|
+
.label-text {
|
|
130
|
+
color: var(
|
|
131
|
+
--jh-checkbox-label-color-text,
|
|
132
|
+
var(--jh-color-content-primary-enabled)
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
.helper-text {
|
|
136
|
+
color: var(
|
|
137
|
+
--jh-checkbox-helper-color-text,
|
|
138
|
+
var(--jh-color-content-secondary-enabled)
|
|
139
|
+
);
|
|
140
|
+
font-family: var(--jh-font-helper-regular-font-family);
|
|
141
|
+
font-weight: var(--jh-font-helper-regular-font-weight);
|
|
142
|
+
font-size: var(--jh-font-helper-regular-font-size);
|
|
143
|
+
line-height: var(--jh-font-helper-regular-line-height);
|
|
144
|
+
margin: 0;
|
|
145
|
+
}
|
|
146
|
+
/* Unselected states */
|
|
147
|
+
input:focus-visible + span {
|
|
148
|
+
border-color: var(
|
|
149
|
+
--jh-checkbox-input-color-border-unselected-focus,
|
|
150
|
+
var(--jh-color-content-brand-hover)
|
|
151
|
+
);
|
|
152
|
+
background-color: var(
|
|
153
|
+
--jh-checkbox-input-color-background-unselected-focus,
|
|
154
|
+
var(--jh-color-container-primary-enabled)
|
|
155
|
+
);
|
|
156
|
+
outline-color: var(
|
|
157
|
+
--jh-checkbox-color-focus,
|
|
158
|
+
var(--jh-border-focus-color)
|
|
159
|
+
);
|
|
160
|
+
outline-style: var(--jh-border-focus-style);
|
|
161
|
+
outline-width: var(--jh-border-focus-width);
|
|
162
|
+
outline-offset: 1px;
|
|
163
|
+
}
|
|
164
|
+
input:hover + span {
|
|
165
|
+
border-color: var(
|
|
166
|
+
--jh-checkbox-input-color-border-unselected-hover,
|
|
167
|
+
var(--jh-color-content-brand-hover)
|
|
168
|
+
);
|
|
169
|
+
background-color: var(
|
|
170
|
+
--jh-checkbox-input-color-background-unselected-hover,
|
|
171
|
+
var(--jh-color-container-primary-enabled)
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
input:active + span {
|
|
175
|
+
border-color: var(
|
|
176
|
+
--jh-checkbox-input-color-border-unselected-active,
|
|
177
|
+
var(--jh-color-content-brand-active)
|
|
178
|
+
);
|
|
179
|
+
background-color: var(
|
|
180
|
+
--jh-checkbox-input-color-background-unselected-active,
|
|
181
|
+
var(--jh-color-container-primary-enabled)
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/* selected status mark with css */
|
|
186
|
+
input:checked + span::before {
|
|
187
|
+
background-color: var(
|
|
188
|
+
--jh-checkbox-status-color-border-selected-enabled,
|
|
189
|
+
var(--jh-color-content-on-brand-enabled)
|
|
190
|
+
);
|
|
191
|
+
border-radius: var(--jh-border-radius-50);
|
|
192
|
+
width: 12px;
|
|
193
|
+
height: 2px;
|
|
194
|
+
bottom: 4px;
|
|
195
|
+
left: 7px;
|
|
196
|
+
transform: rotate(-45deg);
|
|
197
|
+
transform-origin: left bottom;
|
|
198
|
+
}
|
|
199
|
+
input:checked + span::after {
|
|
200
|
+
background-color: var(
|
|
201
|
+
--jh-checkbox-status-color-border-selected-enabled,
|
|
202
|
+
var(--jh-color-content-on-brand-enabled)
|
|
203
|
+
);
|
|
204
|
+
border-radius: var(--jh-border-radius-50);
|
|
205
|
+
bottom: 4px;
|
|
206
|
+
left: 7px;
|
|
207
|
+
height: 7px;
|
|
208
|
+
width: 2px;
|
|
209
|
+
transform: rotate(-45deg);
|
|
210
|
+
transform-origin: left bottom;
|
|
211
|
+
}
|
|
212
|
+
/* selected states */
|
|
213
|
+
input:checked + span {
|
|
214
|
+
border-color: var(
|
|
215
|
+
--jh-checkbox-input-color-border-selected-enabled,
|
|
216
|
+
var(--jh-color-content-brand-enabled)
|
|
217
|
+
);
|
|
218
|
+
background-color: var(
|
|
219
|
+
--jh-checkbox-input-color-background-selected-enabled,
|
|
220
|
+
var(--jh-color-content-brand-enabled)
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
input:checked:focus-visible + span {
|
|
224
|
+
border-color: var(
|
|
225
|
+
--jh-checkbox-input-color-border-selected-focus,
|
|
226
|
+
var(--jh-color-content-brand-hover)
|
|
227
|
+
);
|
|
228
|
+
background-color: var(
|
|
229
|
+
--jh-checkbox-input-color-background-selected-focus,
|
|
230
|
+
var(--jh-color-content-brand-hover)
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
input:checked:focus-visible + span::before,
|
|
234
|
+
input:checked:focus-visible + span::after {
|
|
235
|
+
background-color: var(
|
|
236
|
+
--jh-checkbox-status-color-border-selected-focus,
|
|
237
|
+
var(--jh-color-content-on-brand-hover)
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
input:checked:hover + span {
|
|
241
|
+
border-color: var(
|
|
242
|
+
--jh-checkbox-input-color-border-selected-hover,
|
|
243
|
+
var(--jh-color-content-brand-hover)
|
|
244
|
+
);
|
|
245
|
+
background-color: var(
|
|
246
|
+
--jh-checkbox-input-color-background-selected-hover,
|
|
247
|
+
var(--jh-color-content-brand-hover)
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
input:checked:hover + span::before,
|
|
251
|
+
input:checked:hover + span::after {
|
|
252
|
+
background-color: var(
|
|
253
|
+
--jh-checkbox-status-color-border-selected-hover,
|
|
254
|
+
var(--jh-color-content-on-brand-hover)
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
input:checked:active + span {
|
|
258
|
+
border-color: var(
|
|
259
|
+
--jh-checkbox-input-color-border-selected-active,
|
|
260
|
+
var(--jh-color-content-brand-active)
|
|
261
|
+
);
|
|
262
|
+
background-color: var(
|
|
263
|
+
--jh-checkbox-input-color-background-selected-active,
|
|
264
|
+
var(--jh-color-content-brand-active)
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
input:checked:active + span::before,
|
|
268
|
+
input:checked:active + span::after {
|
|
269
|
+
background-color: var(
|
|
270
|
+
--jh-checkbox-status-color-border-selected-active,
|
|
271
|
+
var(--jh-color-content-on-brand-active)
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/* indeterminate status mark with css */
|
|
276
|
+
input:indeterminate + span::before {
|
|
277
|
+
background-color: var(
|
|
278
|
+
--jh-checkbox-status-color-border-indeterminate-enabled,
|
|
279
|
+
var(--jh-color-content-on-brand-enabled)
|
|
280
|
+
);
|
|
281
|
+
border-radius: var(--jh-border-radius-50);
|
|
282
|
+
width: 10px;
|
|
283
|
+
height: 2px;
|
|
284
|
+
top: 8px;
|
|
285
|
+
left: 4px;
|
|
286
|
+
transform: rotate(0deg);
|
|
287
|
+
}
|
|
288
|
+
input:indeterminate + span::after {
|
|
289
|
+
height: 0px;
|
|
290
|
+
width: 0px;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/* indeterminate states */
|
|
294
|
+
input:indeterminate + span {
|
|
295
|
+
border-color: var(
|
|
296
|
+
--jh-checkbox-input-color-border-indeterminate-enabled,
|
|
297
|
+
var(--jh-color-content-brand-enabled)
|
|
298
|
+
);
|
|
299
|
+
background-color: var(
|
|
300
|
+
--jh-checkbox-input-color-background-indeterminate-enabled,
|
|
301
|
+
var(--jh-color-content-brand-enabled)
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
input:indeterminate:focus-visible + span {
|
|
305
|
+
border-color: var(
|
|
306
|
+
--jh-checkbox-input-color-border-indeterminate-focus,
|
|
307
|
+
var(--jh-color-content-brand-hover)
|
|
308
|
+
);
|
|
309
|
+
background-color: var(
|
|
310
|
+
--jh-checkbox-input-color-background-indeterminate-focus,
|
|
311
|
+
var(--jh-color-content-brand-hover)
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
input:indeterminate:focus-visible + span::before {
|
|
315
|
+
background-color: var(
|
|
316
|
+
--jh-checkbox-status-color-border-indeterminate-focus,
|
|
317
|
+
var(--jh-color-content-on-brand-hover)
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
input:indeterminate:hover + span {
|
|
321
|
+
border-color: var(
|
|
322
|
+
--jh-checkbox-input-color-border-indeterminate-hover,
|
|
323
|
+
var(--jh-color-content-brand-hover)
|
|
324
|
+
);
|
|
325
|
+
background-color: var(
|
|
326
|
+
--jh-checkbox-input-color-background-indeterminate-hover,
|
|
327
|
+
var(--jh-color-content-brand-hover)
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
input:indeterminate:hover + span::before {
|
|
331
|
+
background-color: var(
|
|
332
|
+
--jh-checkbox-status-color-border-indeterminate-hover,
|
|
333
|
+
var(--jh-color-content-on-brand-hover)
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
input:indeterminate:active + span {
|
|
337
|
+
border-color: var(
|
|
338
|
+
--jh-checkbox-input-color-border-indeterminate-active,
|
|
339
|
+
var(--jh-color-content-brand-active)
|
|
340
|
+
);
|
|
341
|
+
background-color: var(
|
|
342
|
+
--jh-checkbox-input-color-background-indeterminate-active,
|
|
343
|
+
var(--jh-color-content-brand-active)
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
input:indeterminate:active + span::before {
|
|
347
|
+
background-color: var(
|
|
348
|
+
--jh-checkbox-status-color-border-indeterminate-active,
|
|
349
|
+
var(--jh-color-content-on-brand-active)
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/* disabled states */
|
|
354
|
+
input:disabled {
|
|
355
|
+
cursor: default;
|
|
356
|
+
}
|
|
357
|
+
input:disabled + span {
|
|
358
|
+
background-color: var(
|
|
359
|
+
--jh-checkbox-input-color-background-unselected-disabled,
|
|
360
|
+
var(--jh-color-container-primary-enabled)
|
|
361
|
+
);
|
|
362
|
+
border-color: var(
|
|
363
|
+
--jh-checkbox-input-color-border-unselected-disabled,
|
|
364
|
+
var(--jh-border-control-color)
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
:host([disabled]) {
|
|
368
|
+
opacity: var(
|
|
369
|
+
--jh-checkbox-opacity-disabled,
|
|
370
|
+
var(--jh-opacity-disabled)
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
input:checked:disabled + span {
|
|
374
|
+
border-color: var(
|
|
375
|
+
--jh-checkbox-input-color-border-selected-disabled,
|
|
376
|
+
var(--jh-color-content-brand-enabled)
|
|
377
|
+
);
|
|
378
|
+
background-color: var(
|
|
379
|
+
--jh-checkbox-input-color-background-selected-disabled,
|
|
380
|
+
var(--jh-color-content-brand-enabled)
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
input:checked:disabled + span::before,
|
|
384
|
+
input:checked:disabled + span::after {
|
|
385
|
+
background-color: var(
|
|
386
|
+
jh-checkbox-status-color-border-selected-disabled,
|
|
387
|
+
var(--jh-color-content-on-brand-enabled)
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
input:indeterminate:disabled + span {
|
|
391
|
+
border-color: var(
|
|
392
|
+
--jh-checkbox-input-color-border-indeterminate-disabled,
|
|
393
|
+
var(--jh-color-content-brand-enabled)
|
|
394
|
+
);
|
|
395
|
+
background-color: var(
|
|
396
|
+
--jh-checkbox-input-color-background-indeterminate-disabled,
|
|
397
|
+
var(--jh-color-content-brand-enabled)
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
input:indeterminate:disabled + span::before {
|
|
401
|
+
background-color: var(
|
|
402
|
+
jh-checkbox-status-color-border-indeterminate-disabled,
|
|
403
|
+
var(--jh-color-content-on-brand-enabled)
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
`;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
static get properties() {
|
|
410
|
+
return {
|
|
411
|
+
/** Sets the selected or 'checked' state on the checkbox. */
|
|
412
|
+
checked: {
|
|
413
|
+
type: Boolean,
|
|
414
|
+
reflect: true,
|
|
415
|
+
},
|
|
416
|
+
/** Sets the indeterminate state on the checkbox. */
|
|
417
|
+
indeterminate: {
|
|
418
|
+
type: Boolean,
|
|
419
|
+
reflect: true,
|
|
420
|
+
},
|
|
421
|
+
/** Disables the checkbox and prevents all user interactions. May cause checkbox to be ignored by assistive technologies(AT). */
|
|
422
|
+
disabled: {
|
|
423
|
+
type: Boolean,
|
|
424
|
+
reflect: true,
|
|
425
|
+
},
|
|
426
|
+
/**
|
|
427
|
+
* Sets the value of the data to be collected when selected.
|
|
428
|
+
*/
|
|
429
|
+
label: {
|
|
430
|
+
type: String,
|
|
431
|
+
},
|
|
432
|
+
/**
|
|
433
|
+
* Provides additional context or guidance for using the checkbox. For `helper-text` to be displayed, the `label` property must also be set.
|
|
434
|
+
*/
|
|
435
|
+
helperText: {
|
|
436
|
+
type: String,
|
|
437
|
+
attribute: 'helper-text',
|
|
438
|
+
},
|
|
439
|
+
/** Sets the name of the checkbox data when submitted in a form. */
|
|
440
|
+
name: {
|
|
441
|
+
type: String,
|
|
442
|
+
},
|
|
443
|
+
/** Sets the value of the checkbox. */
|
|
444
|
+
value: {
|
|
445
|
+
type: String,
|
|
446
|
+
},
|
|
447
|
+
/**
|
|
448
|
+
* Sets an `aria-label` to assist screen reader users when no visible label is present.
|
|
449
|
+
*/
|
|
450
|
+
accessibleLabel: {
|
|
451
|
+
type: String,
|
|
452
|
+
attribute: 'accessible-label',
|
|
453
|
+
},
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
constructor() {
|
|
458
|
+
super();
|
|
459
|
+
this.#internals = this.attachInternals();
|
|
460
|
+
/** @type {?boolean} */
|
|
461
|
+
this.checked = false;
|
|
462
|
+
/** @type {?boolean} */
|
|
463
|
+
this.indeterminate = false;
|
|
464
|
+
/** @type {?boolean} */
|
|
465
|
+
this.disabled = false;
|
|
466
|
+
/** @type {?string} */
|
|
467
|
+
this.label = null;
|
|
468
|
+
/** @type {?string} */
|
|
469
|
+
this.helperText = null;
|
|
470
|
+
/** @type {?string} */
|
|
471
|
+
this.name = null;
|
|
472
|
+
/** @type {?string} */
|
|
473
|
+
this.value = null;
|
|
474
|
+
/** @type {?string} */
|
|
475
|
+
this.accessibleLabel = null;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
connectedCallback() {
|
|
479
|
+
super.connectedCallback();
|
|
480
|
+
this.#id = id++;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Returns the checkbox's parent form element.
|
|
485
|
+
* @type {?HTMLFormElement}
|
|
486
|
+
*/
|
|
487
|
+
get form() {
|
|
488
|
+
return this.#internals.form;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/** @ignore */
|
|
492
|
+
get validity() {
|
|
493
|
+
return this.#internals.validity;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/** @type {?string} */
|
|
497
|
+
get value() {
|
|
498
|
+
return this.#value;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
set value(newValue) {
|
|
502
|
+
const oldValue = this.#value;
|
|
503
|
+
if (newValue !== oldValue) {
|
|
504
|
+
this.#value = newValue;
|
|
505
|
+
this.#updateFormValue(this.#value, this.checked, this.indeterminate);
|
|
506
|
+
}
|
|
507
|
+
this.requestUpdate('value', oldValue);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** @type {?Boolean} */
|
|
511
|
+
get checked() {
|
|
512
|
+
return this.#checked;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
set checked(newValue) {
|
|
516
|
+
const oldValue = this.#checked;
|
|
517
|
+
if (newValue !== oldValue) {
|
|
518
|
+
this.#checked = newValue;
|
|
519
|
+
this.#updateFormValue(this.value, this.#checked, this.indeterminate);
|
|
520
|
+
}
|
|
521
|
+
this.requestUpdate('checked', oldValue);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/** @type {?Boolean} */
|
|
525
|
+
get indeterminate() {
|
|
526
|
+
return this.#indeterminate;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
set indeterminate(newValue) {
|
|
530
|
+
const oldValue = this.#indeterminate;
|
|
531
|
+
if (newValue !== oldValue) {
|
|
532
|
+
this.#indeterminate = newValue;
|
|
533
|
+
this.#updateFormValue(this.value, this.checked, this.#indeterminate);
|
|
534
|
+
}
|
|
535
|
+
this.requestUpdate('indeterminate', oldValue);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
#updateFormValue(value, checked, indeterminate) {
|
|
539
|
+
if (!indeterminate) {
|
|
540
|
+
this.#internals.setFormValue(checked ? value || 'on' : null);
|
|
541
|
+
} else this.#internals.setFormValue(null);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
#handleChange(e) {
|
|
545
|
+
this.checked = e.target.checked;
|
|
546
|
+
this.indeterminate = false;
|
|
547
|
+
this.#updateFormValue(this.value, this.checked, this.indeterminate);
|
|
548
|
+
const options = {
|
|
549
|
+
bubbles: true,
|
|
550
|
+
composed: true,
|
|
551
|
+
cancelable: true,
|
|
552
|
+
};
|
|
553
|
+
this.dispatchEvent(new CustomEvent('jh-change', options));
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
render() {
|
|
557
|
+
let helperText;
|
|
558
|
+
let label;
|
|
559
|
+
|
|
560
|
+
if (this.helperText) {
|
|
561
|
+
helperText = html`
|
|
562
|
+
<p class="helper-text" id="checkbox-helper-text-${this.#id}">
|
|
563
|
+
${this.helperText}
|
|
564
|
+
</p>
|
|
565
|
+
`;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
if (this.label) {
|
|
569
|
+
label = html`
|
|
570
|
+
<div class="label-container">
|
|
571
|
+
<label class="label-text" for="checkbox-label-${this.#id}">
|
|
572
|
+
${this.label}
|
|
573
|
+
</label>
|
|
574
|
+
${helperText}
|
|
575
|
+
</div>
|
|
576
|
+
`;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
return html`
|
|
580
|
+
<input
|
|
581
|
+
tabindex="0"
|
|
582
|
+
@change=${this.#handleChange}
|
|
583
|
+
type="checkbox"
|
|
584
|
+
.checked=${this.checked}
|
|
585
|
+
.indeterminate=${this.indeterminate}
|
|
586
|
+
?disabled=${this.disabled}
|
|
587
|
+
aria-label=${ifDefined(this.accessibleLabel)}
|
|
588
|
+
value=${ifDefined(this.value)}
|
|
589
|
+
name=${ifDefined(this.name)}
|
|
590
|
+
id=${ifDefined(this.label ? `checkbox-label-${this.#id}` : null)}
|
|
591
|
+
aria-describedby=${ifDefined(
|
|
592
|
+
this.helperText ? `checkbox-helper-text-${this.#id}` : null
|
|
593
|
+
)}
|
|
594
|
+
/>
|
|
595
|
+
<span aria-hidden="true"></span>
|
|
596
|
+
${label}
|
|
597
|
+
`;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
customElements.define('jh-checkbox', JhCheckbox);
|