@crowdstrike/glide-core 0.29.2 → 0.30.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/dist/accordion.js +240 -1
- package/dist/accordion.styles.js +13 -7
- package/dist/button-group.button.js +143 -1
- package/dist/button-group.button.styles.js +43 -15
- package/dist/button-group.js +249 -1
- package/dist/button-group.styles.js +10 -5
- package/dist/button.js +206 -1
- package/dist/button.styles.js +12 -7
- package/dist/checkbox-group.js +479 -14
- package/dist/checkbox-group.styles.js +5 -2
- package/dist/checkbox.js +519 -32
- package/dist/checkbox.styles.js +10 -5
- package/dist/drawer.js +168 -1
- package/dist/drawer.styles.js +5 -2
- package/dist/dropdown.js +2423 -123
- package/dist/dropdown.option.js +536 -1
- package/dist/dropdown.option.styles.js +5 -2
- package/dist/dropdown.styles.js +14 -7
- package/dist/form-controls-layout.js +102 -1
- package/dist/form-controls-layout.styles.js +5 -2
- package/dist/icon-button.js +139 -1
- package/dist/icon-button.styles.js +19 -7
- package/dist/icons/checked.js +28 -1
- package/dist/icons/chevron.js +21 -1
- package/dist/icons/magnifying-glass.js +23 -1
- package/dist/icons/pencil.js +21 -1
- package/dist/icons/severity-critical.js +20 -1
- package/dist/icons/severity-informational.js +20 -1
- package/dist/icons/severity-medium.js +20 -1
- package/dist/icons/x.js +21 -1
- package/dist/inline-alert.js +118 -1
- package/dist/inline-alert.styles.js +5 -2
- package/dist/input.d.ts +8 -2
- package/dist/input.js +505 -41
- package/dist/input.styles.js +25 -4
- package/dist/label.js +303 -1
- package/dist/label.styles.js +11 -5
- package/dist/library/assert-slot.js +136 -1
- package/dist/library/expect-unhandled-rejection.js +14 -1
- package/dist/library/expect-window-error.js +26 -1
- package/dist/library/final.js +18 -1
- package/dist/library/form-control.js +1 -1
- package/dist/library/localize.js +10 -1
- package/dist/library/mouse.js +35 -1
- package/dist/library/on-resize.js +24 -1
- package/dist/library/required.js +35 -1
- package/dist/library/shadow-root-mode.js +4 -1
- package/dist/library/unique-id.js +3 -1
- package/dist/link.js +92 -1
- package/dist/link.styles.js +10 -5
- package/dist/menu.d.ts +3 -2
- package/dist/menu.js +1259 -1
- package/dist/menu.styles.js +34 -17
- package/dist/modal.d.ts +4 -0
- package/dist/modal.icon-button.js +60 -1
- package/dist/modal.icon-button.styles.js +5 -2
- package/dist/modal.js +473 -1
- package/dist/modal.styles.js +71 -22
- package/dist/option.d.ts +74 -0
- package/dist/option.js +498 -0
- package/dist/option.styles.js +140 -0
- package/dist/{menu.options.d.ts → options.d.ts} +5 -6
- package/dist/options.js +130 -0
- package/dist/options.styles.js +21 -0
- package/dist/popover.js +620 -1
- package/dist/popover.styles.js +11 -5
- package/dist/radio-group.js +624 -17
- package/dist/radio-group.radio.js +211 -1
- package/dist/radio-group.radio.styles.js +9 -4
- package/dist/radio-group.styles.js +5 -2
- package/dist/slider.js +1040 -61
- package/dist/slider.styles.js +9 -4
- package/dist/spinner.js +60 -1
- package/dist/spinner.styles.js +5 -2
- package/dist/split-button.js +116 -1
- package/dist/split-button.primary-button.js +100 -1
- package/dist/split-button.primary-button.styles.js +13 -6
- package/dist/split-button.primary-link.js +102 -1
- package/dist/split-button.secondary-button.d.ts +2 -3
- package/dist/split-button.secondary-button.js +121 -1
- package/dist/split-button.secondary-button.styles.js +12 -7
- package/dist/split-button.styles.js +9 -4
- package/dist/styles/focus-outline.js +9 -3
- package/dist/styles/fonts.css +6 -1
- package/dist/styles/opacity-and-scale-animation.js +6 -3
- package/dist/styles/skeleton.js +6 -3
- package/dist/styles/variables.css +410 -1
- package/dist/styles/visually-hidden.js +6 -3
- package/dist/tab.group.js +386 -1
- package/dist/tab.group.styles.js +5 -2
- package/dist/tab.js +133 -1
- package/dist/tab.panel.js +93 -1
- package/dist/tab.panel.styles.js +11 -5
- package/dist/tab.styles.js +9 -4
- package/dist/tag.js +207 -1
- package/dist/tag.styles.js +10 -5
- package/dist/textarea.js +353 -19
- package/dist/textarea.styles.js +23 -4
- package/dist/toast.js +130 -1
- package/dist/toast.toasts.js +248 -25
- package/dist/toast.toasts.styles.js +9 -4
- package/dist/toggle.js +178 -1
- package/dist/toggle.styles.js +25 -5
- package/dist/tooltip.container.js +130 -1
- package/dist/tooltip.container.styles.js +5 -2
- package/dist/tooltip.js +484 -1
- package/dist/tooltip.styles.js +21 -5
- package/dist/translations/en.js +36 -1
- package/dist/translations/fr.js +37 -1
- package/dist/translations/ja.js +37 -1
- package/package.json +8 -12
- package/dist/menu.button.d.ts +0 -42
- package/dist/menu.button.js +0 -1
- package/dist/menu.button.styles.js +0 -32
- package/dist/menu.link.d.ts +0 -44
- package/dist/menu.link.js +0 -1
- package/dist/menu.link.styles.js +0 -35
- package/dist/menu.options.js +0 -1
- package/dist/menu.options.styles.d.ts +0 -2
- package/dist/menu.options.styles.js +0 -20
- /package/dist/{menu.button.styles.d.ts → option.styles.d.ts} +0 -0
- /package/dist/{menu.link.styles.d.ts → options.styles.d.ts} +0 -0
package/dist/checkbox.js
CHANGED
@@ -1,14 +1,220 @@
|
|
1
|
-
var __decorate
|
2
|
-
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
import './label.js';
|
8
|
+
import './tooltip.js';
|
9
|
+
import { html, LitElement } from 'lit';
|
10
|
+
import { classMap } from 'lit/directives/class-map.js';
|
11
|
+
import { createRef, ref } from 'lit/directives/ref.js';
|
12
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
13
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
14
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
15
|
+
import { when } from 'lit/directives/when.js';
|
16
|
+
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
17
|
+
import packageJson from '../package.json' with { type: 'json' };
|
18
|
+
import checkedIcon from './icons/checked.js';
|
19
|
+
import styles from './checkbox.styles.js';
|
20
|
+
import shadowRootMode from './library/shadow-root-mode.js';
|
21
|
+
import final from './library/final.js';
|
22
|
+
import required from './library/required.js';
|
23
|
+
/**
|
24
|
+
* @attr {string} label
|
25
|
+
* @attr {boolean} [checked=false]
|
26
|
+
* @attr {boolean} [disabled=false]
|
27
|
+
* @attr {boolean} [hide-label=false]
|
28
|
+
* @attr {boolean} [indeterminate=false]
|
29
|
+
* @attr {string} [name='']
|
30
|
+
* @attr {'horizontal'|'vertical'} [orientation='horizontal']
|
31
|
+
* @attr {boolean} [required=false]
|
32
|
+
* @attr {string} [summary]
|
33
|
+
* @attr {string} [tooltip]
|
34
|
+
* @attr {string} [value='']
|
35
|
+
*
|
36
|
+
* @readonly
|
37
|
+
* @attr {string} [version]
|
38
|
+
*
|
39
|
+
* @slot {Element | string} [description] - Additional information or context
|
40
|
+
* @slot {Element} [private-icon]
|
41
|
+
*
|
42
|
+
* @fires {Event} change
|
43
|
+
* @fires {Event} invalid
|
44
|
+
*
|
45
|
+
* @readonly
|
46
|
+
* @prop {HTMLFormElement | null} form
|
47
|
+
*
|
48
|
+
* @readonly
|
49
|
+
* @prop {ValidityState} validity
|
50
|
+
*
|
51
|
+
* @method checkValidity
|
52
|
+
* @returns boolean
|
53
|
+
*
|
54
|
+
* @method formAssociatedCallback
|
55
|
+
* @method formResetCallback
|
56
|
+
*
|
57
|
+
* @method reportValidity
|
58
|
+
* @returns boolean
|
59
|
+
*
|
60
|
+
* @method resetValidityFeedback
|
61
|
+
*
|
62
|
+
* @method setCustomValidity
|
63
|
+
* @param {string} message
|
64
|
+
*
|
65
|
+
* @method setValidity
|
66
|
+
* @param {ValidityStateFlags} [flags]
|
67
|
+
* @param {string} [message]
|
68
|
+
*/
|
69
|
+
let Checkbox = class Checkbox extends LitElement {
|
70
|
+
static { this.formAssociated = true; }
|
71
|
+
static { this.shadowRootOptions = {
|
72
|
+
...LitElement.shadowRootOptions,
|
73
|
+
mode: shadowRootMode,
|
74
|
+
}; }
|
75
|
+
static { this.styles = styles; }
|
76
|
+
/**
|
77
|
+
* @default undefined
|
78
|
+
*/
|
79
|
+
get label() {
|
80
|
+
return this.#label;
|
81
|
+
}
|
82
|
+
set label(label) {
|
83
|
+
this.#label = label;
|
84
|
+
// Wait for the label to render. A rerender won't be scheduled by Lit
|
85
|
+
// until after this setter finishes. So awaiting `this.updateComplete`
|
86
|
+
// won't fly.
|
87
|
+
setTimeout(() => {
|
88
|
+
this.#updateLabelOverflow();
|
89
|
+
});
|
90
|
+
}
|
91
|
+
/**
|
92
|
+
@default false
|
93
|
+
*/
|
94
|
+
get checked() {
|
95
|
+
return this.#isChecked;
|
96
|
+
}
|
97
|
+
set checked(isChecked) {
|
98
|
+
const hasChanged = isChecked !== this.#isChecked;
|
99
|
+
this.#isChecked = isChecked;
|
100
|
+
if (hasChanged) {
|
101
|
+
this.dispatchEvent(new Event('private-checked-change', { bubbles: true }));
|
102
|
+
}
|
103
|
+
}
|
104
|
+
/**
|
105
|
+
* @default false
|
106
|
+
*/
|
107
|
+
get disabled() {
|
108
|
+
return this.#isDisabled;
|
109
|
+
}
|
110
|
+
set disabled(isDisabled) {
|
111
|
+
this.#isDisabled = isDisabled;
|
112
|
+
this.dispatchEvent(new Event('private-disabled-change', { bubbles: true }));
|
113
|
+
}
|
114
|
+
/**
|
115
|
+
* @default ''
|
116
|
+
*/
|
117
|
+
get value() {
|
118
|
+
return this.#value;
|
119
|
+
}
|
120
|
+
set value(value) {
|
121
|
+
const old = this.#value;
|
122
|
+
this.#value = value;
|
123
|
+
// `this.value` can be set programmatically. Checkbox Group needs to know when
|
124
|
+
// that happens so it can update its own `this.value`.
|
125
|
+
this.dispatchEvent(new CustomEvent('private-value-change', {
|
126
|
+
bubbles: true,
|
127
|
+
detail: {
|
128
|
+
// Without knowing what the old value was, Checkbox Group would be unable to
|
129
|
+
// find the value in its `this.value` array and remove it.
|
130
|
+
old,
|
131
|
+
new: value,
|
132
|
+
},
|
133
|
+
}));
|
134
|
+
}
|
135
|
+
get form() {
|
136
|
+
return this.#internals.form;
|
137
|
+
}
|
138
|
+
checkValidity() {
|
139
|
+
this.isCheckingValidity = true;
|
140
|
+
const isValid = this.#internals.checkValidity();
|
141
|
+
this.isCheckingValidity = false;
|
142
|
+
return isValid;
|
143
|
+
}
|
144
|
+
click() {
|
145
|
+
this.#inputElementRef.value?.click();
|
146
|
+
}
|
147
|
+
connectedCallback() {
|
148
|
+
super.connectedCallback();
|
149
|
+
// Checkbox can be arbitrarily shown and hidden as it is in Dropdown. So calling
|
150
|
+
// `#updateLabelOverflow` in the `label` setter isn't sufficient because the
|
151
|
+
// label's `scrollWidth` and `clientWidth` will both be zero until Checkbox is
|
152
|
+
// visible. So, rather than Checkbox expose a pseudo-private method, Checkbox
|
153
|
+
// simply monitors its own visibility.
|
154
|
+
this.#intersectionObserver = new IntersectionObserver(() => {
|
155
|
+
if (this.checkVisibility()) {
|
156
|
+
this.#updateLabelOverflow();
|
157
|
+
}
|
158
|
+
});
|
159
|
+
this.#intersectionObserver.observe(this);
|
160
|
+
}
|
161
|
+
disconnectedCallback() {
|
162
|
+
super.disconnectedCallback();
|
163
|
+
this.form?.removeEventListener('formdata', this.#onFormdata);
|
164
|
+
this.#intersectionObserver?.disconnect();
|
165
|
+
}
|
166
|
+
get validity() {
|
167
|
+
// If we're in a Checkbox Group, `disabled`, `required`, and whether or not
|
168
|
+
// the form has been submitted don't apply because Checkbox Group handles those
|
169
|
+
// states for the group as a whole.
|
170
|
+
if (this.privateVariant === 'minimal') {
|
171
|
+
return this.#internals.validity;
|
172
|
+
}
|
173
|
+
if (this.required && !this.checked) {
|
174
|
+
// A validation message is required but unused because we disable native validation
|
175
|
+
// feedback. And an empty string isn't allowed. Thus a single space.
|
176
|
+
this.#internals.setValidity({ customError: Boolean(this.validityMessage), valueMissing: true }, ' ', this.#inputElementRef.value);
|
177
|
+
return this.#internals.validity;
|
178
|
+
}
|
179
|
+
if (this.required &&
|
180
|
+
this.#internals.validity.valueMissing &&
|
181
|
+
this.checked) {
|
182
|
+
this.#internals.setValidity({});
|
183
|
+
return this.#internals.validity;
|
184
|
+
}
|
185
|
+
if (!this.required &&
|
186
|
+
this.#internals.validity.valueMissing &&
|
187
|
+
!this.checked) {
|
188
|
+
this.#internals.setValidity({});
|
189
|
+
return this.#internals.validity;
|
190
|
+
}
|
191
|
+
return this.#internals.validity;
|
192
|
+
}
|
193
|
+
focus(options) {
|
194
|
+
this.#inputElementRef.value?.focus(options);
|
195
|
+
}
|
196
|
+
formAssociatedCallback() {
|
197
|
+
this.form?.addEventListener('formdata', this.#onFormdata);
|
198
|
+
}
|
199
|
+
formResetCallback() {
|
200
|
+
this.checked = this.getAttribute('checked') === '';
|
201
|
+
this.indeterminate = this.getAttribute('indeterminate') === '';
|
202
|
+
}
|
203
|
+
render() {
|
204
|
+
return html `<div class="component" data-test="component">
|
205
|
+
${when(this.privateVariant === 'minimal', () => html `
|
3
206
|
<label
|
4
207
|
class="label-and-input-and-checkbox"
|
5
208
|
part="private-label-and-input-and-checkbox"
|
6
209
|
>
|
7
210
|
<div
|
8
|
-
class=${classMap({
|
211
|
+
class=${classMap({
|
212
|
+
'input-and-checkbox': true,
|
213
|
+
disabled: this.disabled,
|
214
|
+
})}
|
9
215
|
>
|
10
216
|
<input
|
11
|
-
aria-invalid=${this.#
|
217
|
+
aria-invalid=${this.#isShowValidationFeedback}
|
12
218
|
class="input"
|
13
219
|
data-test="input"
|
14
220
|
type="checkbox"
|
@@ -16,14 +222,17 @@ var __decorate=this&&this.__decorate||function(e,t,i,s){var a,r=arguments.length
|
|
16
222
|
.inert=${this.privateInternallyInert}
|
17
223
|
?disabled=${this.disabled}
|
18
224
|
?required=${this.required}
|
19
|
-
@change=${this.#
|
20
|
-
@input=${this.#
|
21
|
-
@keydown=${this.#
|
22
|
-
${ref(this.#
|
225
|
+
@change=${this.#onInputChangeOrInput}
|
226
|
+
@input=${this.#onInputChangeOrInput}
|
227
|
+
@keydown=${this.#onInputKeydown}
|
228
|
+
${ref(this.#inputElementRef)}
|
23
229
|
/>
|
24
230
|
|
25
231
|
<div
|
26
|
-
class=${classMap({
|
232
|
+
class=${classMap({
|
233
|
+
checkbox: true,
|
234
|
+
disabled: this.disabled,
|
235
|
+
})}
|
27
236
|
>
|
28
237
|
<div class="checked-icon">${checkedIcon}</div>
|
29
238
|
${icons.indeterminate}
|
@@ -40,27 +249,31 @@ var __decorate=this&&this.__decorate||function(e,t,i,s){var a,r=arguments.length
|
|
40
249
|
data-test="label-tooltip"
|
41
250
|
label=${ifDefined(this.label)}
|
42
251
|
offset=${this.privateLabelTooltipOffset}
|
43
|
-
?disabled=${!this.isLabelOverflow||
|
252
|
+
?disabled=${!this.isLabelOverflow ||
|
253
|
+
this.privateDisableLabelTooltip}
|
44
254
|
?open=${this.privateShowLabelTooltip}
|
45
255
|
screenreader-hidden
|
46
256
|
>
|
47
257
|
<div
|
48
|
-
class=${classMap({
|
258
|
+
class=${classMap({
|
259
|
+
label: true,
|
260
|
+
disabled: this.disabled,
|
261
|
+
})}
|
49
262
|
slot="target"
|
50
|
-
${ref(this.#
|
263
|
+
${ref(this.#labelElementRef)}
|
51
264
|
>
|
52
265
|
${this.label}
|
53
266
|
</div>
|
54
267
|
</glide-core-tooltip>
|
55
268
|
</div>
|
56
269
|
</label>
|
57
|
-
|
270
|
+
`, () => html `<glide-core-private-label
|
58
271
|
label=${ifDefined(this.label)}
|
59
272
|
orientation=${this.orientation}
|
60
|
-
split=${ifDefined(this.privateSplit??
|
273
|
+
split=${ifDefined(this.privateSplit ?? undefined)}
|
61
274
|
tooltip=${ifDefined(this.tooltip)}
|
62
275
|
?disabled=${this.disabled}
|
63
|
-
?error=${this.#
|
276
|
+
?error=${this.#isShowValidationFeedback}
|
64
277
|
?hide=${this.hideLabel}
|
65
278
|
?required=${this.required}
|
66
279
|
>
|
@@ -74,7 +287,7 @@ var __decorate=this&&this.__decorate||function(e,t,i,s){var a,r=arguments.length
|
|
74
287
|
<div class="input-and-checkbox" slot="control">
|
75
288
|
<input
|
76
289
|
aria-describedby="summary description"
|
77
|
-
aria-invalid=${this.#
|
290
|
+
aria-invalid=${this.#isShowValidationFeedback}
|
78
291
|
class="input"
|
79
292
|
data-test="input"
|
80
293
|
id="input"
|
@@ -82,28 +295,32 @@ var __decorate=this&&this.__decorate||function(e,t,i,s){var a,r=arguments.length
|
|
82
295
|
.checked=${this.checked}
|
83
296
|
?disabled=${this.disabled}
|
84
297
|
?required=${this.required}
|
85
|
-
@blur=${this.#
|
86
|
-
@change=${this.#
|
87
|
-
@input=${this.#
|
88
|
-
@keydown=${this.#
|
89
|
-
${ref(this.#
|
298
|
+
@blur=${this.#onBlur}
|
299
|
+
@change=${this.#onInputChangeOrInput}
|
300
|
+
@input=${this.#onInputChangeOrInput}
|
301
|
+
@keydown=${this.#onInputKeydown}
|
302
|
+
${ref(this.#inputElementRef)}
|
90
303
|
/>
|
91
304
|
|
92
305
|
<div
|
93
|
-
class=${classMap({
|
306
|
+
class=${classMap({
|
307
|
+
checkbox: true,
|
308
|
+
disabled: this.disabled,
|
309
|
+
error: this.#isShowValidationFeedback,
|
310
|
+
})}
|
94
311
|
>
|
95
312
|
<div class="checked-icon">${checkedIcon}</div>
|
96
313
|
${icons.indeterminate}
|
97
314
|
</div>
|
98
315
|
</div>
|
99
316
|
|
100
|
-
${when(this.summary,(
|
101
|
-
class=${classMap({summary
|
317
|
+
${when(this.summary, () => html `<div
|
318
|
+
class=${classMap({ summary: true, disabled: this.disabled })}
|
102
319
|
id="summary"
|
103
320
|
slot="summary"
|
104
321
|
>
|
105
322
|
${this.summary}
|
106
|
-
</div>`)
|
323
|
+
</div>`)}
|
107
324
|
|
108
325
|
<div id="description" slot="description">
|
109
326
|
<!--
|
@@ -111,7 +328,10 @@ var __decorate=this&&this.__decorate||function(e,t,i,s){var a,r=arguments.length
|
|
111
328
|
@type {Element | string}
|
112
329
|
-->
|
113
330
|
<slot
|
114
|
-
class=${classMap({
|
331
|
+
class=${classMap({
|
332
|
+
description: true,
|
333
|
+
hidden: Boolean(this.#isShowValidationFeedback && this.validityMessage),
|
334
|
+
})}
|
115
335
|
name="description"
|
116
336
|
>
|
117
337
|
<!--
|
@@ -120,17 +340,283 @@ var __decorate=this&&this.__decorate||function(e,t,i,s){var a,r=arguments.length
|
|
120
340
|
-->
|
121
341
|
</slot>
|
122
342
|
|
123
|
-
${when(this.#
|
343
|
+
${when(this.#isShowValidationFeedback && this.validityMessage, () => html `<span
|
124
344
|
class="validity-message"
|
125
345
|
data-test="validity-message"
|
126
346
|
>${unsafeHTML(this.validityMessage)}</span
|
127
|
-
>`)
|
347
|
+
>`)}
|
128
348
|
</div>
|
129
|
-
</glide-core-private-label>`)
|
130
|
-
</div
|
349
|
+
</glide-core-private-label>`)}
|
350
|
+
</div>`;
|
351
|
+
}
|
352
|
+
reportValidity() {
|
353
|
+
this.privateIsReportValidityOrSubmit = true;
|
354
|
+
const isValid = this.#internals.reportValidity();
|
355
|
+
// Ensures that getters referencing `this.validity.valid` are updated.
|
356
|
+
this.requestUpdate();
|
357
|
+
return isValid;
|
358
|
+
}
|
359
|
+
resetValidityFeedback() {
|
360
|
+
this.privateIsReportValidityOrSubmit = false;
|
361
|
+
}
|
362
|
+
setCustomValidity(message) {
|
363
|
+
this.validityMessage = message;
|
364
|
+
if (message === '') {
|
365
|
+
this.#internals.setValidity({ customError: false }, '', this.#inputElementRef.value);
|
366
|
+
}
|
367
|
+
else {
|
368
|
+
// A validation message is required but unused because we disable native validation
|
369
|
+
// feedback. And an empty string isn't allowed. Thus a single space.
|
370
|
+
this.#internals.setValidity({
|
371
|
+
customError: true,
|
372
|
+
valueMissing: this.#internals.validity.valueMissing,
|
373
|
+
}, ' ', this.#inputElementRef.value);
|
374
|
+
}
|
375
|
+
}
|
376
|
+
setValidity(flags, message) {
|
377
|
+
this.validityMessage = message;
|
378
|
+
this.#internals.setValidity(flags, ' ', this.#inputElementRef.value);
|
379
|
+
}
|
380
|
+
updated() {
|
381
|
+
if (this.#inputElementRef.value) {
|
382
|
+
// `indeterminate` needs to be updated both on initial render and after it has
|
383
|
+
// changed. This handles both cases.
|
384
|
+
this.#inputElementRef.value.indeterminate = this.indeterminate;
|
385
|
+
}
|
386
|
+
}
|
387
|
+
constructor() {
|
388
|
+
super();
|
389
|
+
this.privateInternallyInert = false;
|
390
|
+
this.hideLabel = false;
|
391
|
+
this.indeterminate = false;
|
392
|
+
this.orientation = 'horizontal';
|
393
|
+
this.name = '';
|
394
|
+
// Private because it's only meant to be used by Dropdown Option to offset the
|
395
|
+
// tooltip by the option's padding.
|
396
|
+
this.privateLabelTooltipOffset = 4;
|
397
|
+
// Private because it's only meant to be used by Dropdown Option.
|
398
|
+
this.privateShowLabelTooltip = false;
|
399
|
+
// Private because it's only meant to be used by Dropdown Option.
|
400
|
+
this.privateDisableLabelTooltip = false;
|
401
|
+
this.required = false;
|
402
|
+
// Used by Checkbox Group.
|
403
|
+
this.privateIsReportValidityOrSubmit = false;
|
404
|
+
this.version = packageJson.version;
|
405
|
+
this.isBlurring = false;
|
406
|
+
this.isCheckingValidity = false;
|
407
|
+
this.isLabelOverflow = false;
|
408
|
+
this.#inputElementRef = createRef();
|
409
|
+
this.#isChecked = false;
|
410
|
+
this.#isDisabled = false;
|
411
|
+
this.#labelElementRef = createRef();
|
412
|
+
this.#value = '';
|
413
|
+
// An arrow function field instead of a method so `this` is closed over and
|
414
|
+
// set to the component instead of `document`.
|
415
|
+
this.#onFormdata = ({ formData }) => {
|
416
|
+
if (this.checked && this.name && this.value && !this.disabled) {
|
417
|
+
formData.append(this.name, this.value);
|
418
|
+
}
|
419
|
+
};
|
420
|
+
this.#internals = this.attachInternals();
|
421
|
+
// Event handlers on the host aren't great because consumers can remove them.
|
422
|
+
// Unfortunately, the host is the only thing on which this event is dispatched
|
423
|
+
// because it's the host that is form-associated.
|
424
|
+
this.addEventListener('invalid', (event) => {
|
425
|
+
event?.preventDefault(); // Canceled so a native validation message isn't shown.
|
426
|
+
// We only want to focus the input if the "invalid" event resulted from either:
|
427
|
+
//
|
428
|
+
// 1. A form submission.
|
429
|
+
// 2. A call of `reportValidity()` that did not result from the input's "blur"
|
430
|
+
// event.
|
431
|
+
if (this.isCheckingValidity || this.isBlurring) {
|
432
|
+
return;
|
433
|
+
}
|
434
|
+
this.privateIsReportValidityOrSubmit = true;
|
435
|
+
const isFirstInvalidFormElement = this.form?.querySelector(':invalid') === this;
|
436
|
+
if (isFirstInvalidFormElement) {
|
437
|
+
// - `this.#internals.delegatesFocus` is preferred because it's declarative. But
|
438
|
+
// it's limited to focusing the first focusable element. That doesn't work for
|
439
|
+
// us because our first focusable element is the tooltip when it's present.
|
440
|
+
//
|
441
|
+
// - Canceling this event means the input won't get focus, even if we were to use
|
442
|
+
// `this.#internals.delegatesFocus`.
|
443
|
+
//
|
444
|
+
// - The browser will ignore this if Checkbox isn't the first invalid form control.
|
445
|
+
//
|
446
|
+
// TODO
|
447
|
+
// Try passing `focusVisible` after browsers support it. It may prevent the issue
|
448
|
+
// where the checkbox itself has a focus outline after this call.
|
449
|
+
//
|
450
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus#focusvisible
|
451
|
+
this.focus();
|
452
|
+
}
|
453
|
+
});
|
454
|
+
}
|
455
|
+
#inputElementRef;
|
456
|
+
#internals;
|
457
|
+
#intersectionObserver;
|
458
|
+
#isChecked;
|
459
|
+
#isDisabled;
|
460
|
+
#label;
|
461
|
+
#labelElementRef;
|
462
|
+
#value;
|
463
|
+
// An arrow function field instead of a method so `this` is closed over and
|
464
|
+
// set to the component instead of `document`.
|
465
|
+
#onFormdata;
|
466
|
+
get #isShowValidationFeedback() {
|
467
|
+
// If minimal, `disabled`, `required`, and whether the form has been submitted
|
468
|
+
// don't apply because the parent component handles those states itself.
|
469
|
+
if (this.privateVariant === 'minimal') {
|
470
|
+
return !this.validity.valid && this.privateIsReportValidityOrSubmit;
|
471
|
+
}
|
472
|
+
return (!this.disabled &&
|
473
|
+
!this.validity.valid &&
|
474
|
+
this.privateIsReportValidityOrSubmit);
|
475
|
+
}
|
476
|
+
#onBlur() {
|
477
|
+
this.isBlurring = true;
|
478
|
+
this.reportValidity();
|
479
|
+
this.isBlurring = false;
|
480
|
+
}
|
481
|
+
// Only "change" would need to be handled if not for some consumers needing
|
482
|
+
// to force Checkbox checked or unchecked until the user has completed some action.
|
483
|
+
//
|
484
|
+
// The way to force Checkbox checked or unchecked is to add an "input" or
|
485
|
+
// "change" handler and then immediately set `checked` back to its desired
|
486
|
+
// state inside that handler.
|
487
|
+
//
|
488
|
+
// To do that, consumers need to await `this.updateComplete` so `checked` isn't
|
489
|
+
// immediately reverted after Checkbox updates, which happens asynchronously and
|
490
|
+
// so would happen after their handler runs.
|
491
|
+
//
|
492
|
+
// To await `this.updateComplete`, however, an update has to be pending. That's
|
493
|
+
// why we're handling "input" as well: so that "input", like "change", results
|
494
|
+
// in an update that can be awaited.
|
495
|
+
//
|
496
|
+
// If "input" events were dispatched after "change" events, only handling
|
497
|
+
// "change" here would suffice because an update from "change" would already
|
498
|
+
// be pending by the time "input" is dispatched.
|
499
|
+
#onInputChangeOrInput(event) {
|
500
|
+
if (event.target instanceof HTMLInputElement) {
|
501
|
+
this.checked = event.target.checked;
|
502
|
+
}
|
503
|
+
// If the input is interacted with it's no longer indeterminate.
|
504
|
+
this.indeterminate = false;
|
505
|
+
if (event.type === 'change') {
|
506
|
+
// Unlike "input" events, "change" events aren't composed. So we have to
|
507
|
+
// manually dispatch them.
|
508
|
+
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
509
|
+
}
|
510
|
+
}
|
511
|
+
#onInputKeydown(event) {
|
512
|
+
if (event.key === 'Enter') {
|
513
|
+
this.form?.requestSubmit();
|
514
|
+
}
|
515
|
+
}
|
516
|
+
#updateLabelOverflow() {
|
517
|
+
if (this.#labelElementRef.value) {
|
518
|
+
this.isLabelOverflow =
|
519
|
+
this.#labelElementRef.value.scrollWidth >
|
520
|
+
this.#labelElementRef.value.clientWidth;
|
521
|
+
}
|
522
|
+
}
|
523
|
+
};
|
524
|
+
__decorate([
|
525
|
+
property({ reflect: true }),
|
526
|
+
required
|
527
|
+
], Checkbox.prototype, "label", null);
|
528
|
+
__decorate([
|
529
|
+
property({ type: Boolean })
|
530
|
+
], Checkbox.prototype, "checked", null);
|
531
|
+
__decorate([
|
532
|
+
property({ attribute: 'private-internally-inert', type: Boolean })
|
533
|
+
], Checkbox.prototype, "privateInternallyInert", void 0);
|
534
|
+
__decorate([
|
535
|
+
property({ reflect: true, type: Boolean })
|
536
|
+
], Checkbox.prototype, "disabled", null);
|
537
|
+
__decorate([
|
538
|
+
property({ attribute: 'hide-label', type: Boolean })
|
539
|
+
], Checkbox.prototype, "hideLabel", void 0);
|
540
|
+
__decorate([
|
541
|
+
property({ type: Boolean })
|
542
|
+
], Checkbox.prototype, "indeterminate", void 0);
|
543
|
+
__decorate([
|
544
|
+
property({ reflect: true, useDefault: true })
|
545
|
+
], Checkbox.prototype, "orientation", void 0);
|
546
|
+
__decorate([
|
547
|
+
property({ reflect: true, useDefault: true })
|
548
|
+
], Checkbox.prototype, "name", void 0);
|
549
|
+
__decorate([
|
550
|
+
property({
|
551
|
+
attribute: 'private-label-tooltip-offset',
|
552
|
+
reflect: true,
|
553
|
+
useDefault: true,
|
554
|
+
type: Number,
|
555
|
+
})
|
556
|
+
], Checkbox.prototype, "privateLabelTooltipOffset", void 0);
|
557
|
+
__decorate([
|
558
|
+
property({
|
559
|
+
attribute: 'private-show-label-tooltip',
|
560
|
+
reflect: true,
|
561
|
+
type: Boolean,
|
562
|
+
})
|
563
|
+
], Checkbox.prototype, "privateShowLabelTooltip", void 0);
|
564
|
+
__decorate([
|
565
|
+
property({
|
566
|
+
attribute: 'private-disable-label-tooltip',
|
567
|
+
reflect: true,
|
568
|
+
type: Boolean,
|
569
|
+
})
|
570
|
+
], Checkbox.prototype, "privateDisableLabelTooltip", void 0);
|
571
|
+
__decorate([
|
572
|
+
property()
|
573
|
+
], Checkbox.prototype, "privateSplit", void 0);
|
574
|
+
__decorate([
|
575
|
+
property({ attribute: 'private-variant' })
|
576
|
+
], Checkbox.prototype, "privateVariant", void 0);
|
577
|
+
__decorate([
|
578
|
+
property({ reflect: true, type: Boolean })
|
579
|
+
], Checkbox.prototype, "required", void 0);
|
580
|
+
__decorate([
|
581
|
+
property({ reflect: true })
|
582
|
+
], Checkbox.prototype, "summary", void 0);
|
583
|
+
__decorate([
|
584
|
+
property({ reflect: true })
|
585
|
+
], Checkbox.prototype, "tooltip", void 0);
|
586
|
+
__decorate([
|
587
|
+
property({ reflect: true })
|
588
|
+
], Checkbox.prototype, "value", null);
|
589
|
+
__decorate([
|
590
|
+
property({ type: Boolean })
|
591
|
+
], Checkbox.prototype, "privateIsReportValidityOrSubmit", void 0);
|
592
|
+
__decorate([
|
593
|
+
property({ reflect: true })
|
594
|
+
], Checkbox.prototype, "version", void 0);
|
595
|
+
__decorate([
|
596
|
+
state()
|
597
|
+
], Checkbox.prototype, "isBlurring", void 0);
|
598
|
+
__decorate([
|
599
|
+
state()
|
600
|
+
], Checkbox.prototype, "isCheckingValidity", void 0);
|
601
|
+
__decorate([
|
602
|
+
state()
|
603
|
+
], Checkbox.prototype, "isLabelOverflow", void 0);
|
604
|
+
__decorate([
|
605
|
+
state()
|
606
|
+
], Checkbox.prototype, "validityMessage", void 0);
|
607
|
+
Checkbox = __decorate([
|
608
|
+
customElement('glide-core-checkbox'),
|
609
|
+
final
|
610
|
+
], Checkbox);
|
611
|
+
export default Checkbox;
|
612
|
+
const icons = {
|
613
|
+
indeterminate: html `
|
131
614
|
<svg
|
132
615
|
aria-hidden="true"
|
133
|
-
style=${styleMap({
|
616
|
+
style=${styleMap({
|
617
|
+
height: '0.875rem',
|
618
|
+
width: '0.875rem',
|
619
|
+
})}
|
134
620
|
viewBox="0 0 14 14"
|
135
621
|
fill="none"
|
136
622
|
class="indeterminate-icon"
|
@@ -141,4 +627,5 @@ var __decorate=this&&this.__decorate||function(e,t,i,s){var a,r=arguments.length
|
|
141
627
|
fill="currentColor"
|
142
628
|
/>
|
143
629
|
</svg>
|
144
|
-
|
630
|
+
`,
|
631
|
+
};
|
package/dist/checkbox.styles.js
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
import{css}from
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
import { css } from 'lit';
|
2
|
+
import focusOutline from './styles/focus-outline.js';
|
3
|
+
export default [
|
4
|
+
css `
|
5
|
+
${focusOutline('.input:focus-visible ~ .checkbox')}
|
6
|
+
${focusOutline('.input:focus ~ .checkbox.error')}
|
7
|
+
`,
|
8
|
+
css `
|
5
9
|
.label-and-input-and-checkbox {
|
6
10
|
align-items: center;
|
7
11
|
column-gap: var(--glide-core-spacing-base-xs);
|
@@ -208,4 +212,5 @@ import{css}from"lit";import focusOutline from"./styles/focus-outline.js";export
|
|
208
212
|
.validity-message {
|
209
213
|
display: block;
|
210
214
|
}
|
211
|
-
|
215
|
+
`,
|
216
|
+
];
|