tyrell-components 1.0.0-TC58 → 1.0.0-TC60
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/README.md +1 -1
- package/css/tyrell-colors-static.css +14 -0
- package/css/tyrell-theme.css +6 -5
- package/css/tyrell.css +8 -6
- package/dist/tyrell-colors-static.css +1 -1
- package/dist/tyrell-theme.css +1 -1
- package/dist/tyrell.js +1 -1
- package/lib/base/ty-component.d.ts +13 -12
- package/lib/base/ty-component.js +56 -21
- package/lib/components/button.d.ts +10 -0
- package/lib/components/button.js +22 -1
- package/lib/components/calendar-month.d.ts +7 -1
- package/lib/components/calendar-month.js +32 -18
- package/lib/components/calendar-navigation.js +19 -6
- package/lib/components/calendar.d.ts +25 -5
- package/lib/components/calendar.js +87 -37
- package/lib/components/checkbox.d.ts +5 -0
- package/lib/components/checkbox.js +18 -5
- package/lib/components/copy.d.ts +2 -0
- package/lib/components/copy.js +15 -31
- package/lib/components/date-picker.d.ts +7 -26
- package/lib/components/date-picker.js +14 -84
- package/lib/components/file-upload.js +6 -2
- package/lib/components/input.d.ts +0 -9
- package/lib/components/input.js +18 -40
- package/lib/components/modal.js +59 -18
- package/lib/components/option.d.ts +19 -0
- package/lib/components/option.js +38 -26
- package/lib/components/popup.js +56 -5
- package/lib/components/radio.d.ts +6 -0
- package/lib/components/radio.js +12 -28
- package/lib/components/select.d.ts +132 -194
- package/lib/components/select.js +436 -836
- package/lib/components/selected-tags.d.ts +8 -4
- package/lib/components/selected-tags.js +26 -8
- package/lib/components/switch.d.ts +4 -0
- package/lib/components/switch.js +18 -5
- package/lib/components/tabs.js +1 -1
- package/lib/components/textarea.d.ts +1 -0
- package/lib/components/textarea.js +21 -8
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/styles/button.js +1 -0
- package/lib/styles/calendar-month.js +1 -1
- package/lib/styles/calendar.js +3 -0
- package/lib/styles/checkbox.js +11 -5
- package/lib/styles/date-picker.js +5 -10
- package/lib/styles/input.js +5 -9
- package/lib/styles/option.d.ts +1 -1
- package/lib/styles/option.js +6 -7
- package/lib/styles/popup.d.ts +1 -1
- package/lib/styles/popup.js +2 -0
- package/lib/styles/radio.js +10 -4
- package/lib/styles/select-base.js +6 -70
- package/lib/styles/select.d.ts +1 -1
- package/lib/styles/select.js +13 -2
- package/lib/styles/switch.js +10 -5
- package/lib/styles/tag.js +2 -1
- package/lib/types/common.d.ts +3 -1
- package/lib/utils/calendar-utils.d.ts +49 -0
- package/lib/utils/calendar-utils.js +63 -6
- package/lib/utils/property-manager.d.ts +0 -5
- package/lib/utils/property-manager.js +0 -11
- package/lib/utils/scroll-lock.d.ts +10 -4
- package/lib/utils/scroll-lock.js +102 -2
- package/lib/utils/validity.d.ts +27 -1
- package/lib/utils/validity.js +68 -16
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/dist/tyrell.js.map +0 -1
- package/lib/utils/error-flavor.d.ts +0 -8
- package/lib/utils/error-flavor.js +0 -1
|
@@ -3,7 +3,7 @@ import { liftProperties, upgradeProperties } from '../utils/upgrade-properties.j
|
|
|
3
3
|
import { calendarStyles } from '../styles/calendar.js';
|
|
4
4
|
import './calendar-month.js';
|
|
5
5
|
import './calendar-navigation.js';
|
|
6
|
-
import {
|
|
6
|
+
import { parseDateDay, formatISODay, toISODay, getMonthName, localMidnight, utcMidnight } from '../utils/calendar-utils.js';
|
|
7
7
|
import { getEffectiveLocale, observeLocaleChanges } from '../utils/locale.js';
|
|
8
8
|
import { ValidityController, nativeMessage } from '../utils/validity.js';
|
|
9
9
|
function getCurrentDate() {
|
|
@@ -32,14 +32,12 @@ const day = parseInt(dayStr, 10);
|
|
|
32
32
|
const daysInMonth = new Date(year, month, 0).getDate();
|
|
33
33
|
return day >= 1 && day <= daysInMonth ? day : null;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
const dayStr = day.toString().padStart(2, '0');
|
|
38
|
-
return `${year}-${monthStr}-${dayStr}`;
|
|
35
|
+
function formatYear(year) {
|
|
36
|
+
return year.toString().padStart(4, '0');
|
|
39
37
|
}
|
|
40
38
|
export class TyCalendar extends HTMLElement {
|
|
41
39
|
static get observedAttributes() {
|
|
42
|
-
return ['value', 'year', 'month', 'day', 'hide-navigation', 'stateless', 'locale', 'name', 'size', 'width', 'min', 'max', 'flavor'];
|
|
40
|
+
return ['value', 'year', 'month', 'day', 'hide-navigation', 'stateless', 'locale', 'name', 'size', 'width', 'min', 'max', 'flavor', 'required'];
|
|
43
41
|
}
|
|
44
42
|
constructor() {
|
|
45
43
|
super();
|
|
@@ -50,13 +48,15 @@ this._flavor = 'primary';
|
|
|
50
48
|
this._view = 'days';
|
|
51
49
|
this._dayGridHeight = 0;
|
|
52
50
|
this._initialValue = '';
|
|
51
|
+
this._initialized = false;
|
|
53
52
|
this._valueSets = 0;
|
|
53
|
+
this._pressing = false;
|
|
54
54
|
const current = getCurrentDate();
|
|
55
55
|
this._state = {
|
|
56
56
|
displayYear: current.year,
|
|
57
57
|
displayMonth: current.month,
|
|
58
58
|
};
|
|
59
|
-
this.attachShadow({ mode: 'open' });
|
|
59
|
+
this.attachShadow({ mode: 'open', delegatesFocus: true });
|
|
60
60
|
liftProperties(this);
|
|
61
61
|
if ('attachInternals' in this) {
|
|
62
62
|
this._internals = this.attachInternals();
|
|
@@ -64,7 +64,10 @@ this._validity = new ValidityController(this, this._internals);
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
connectedCallback() {
|
|
67
|
+
if (!this._initialized) {
|
|
67
68
|
this.initializeFromAttributes();
|
|
69
|
+
this._initialized = true;
|
|
70
|
+
}
|
|
68
71
|
upgradeProperties(this);
|
|
69
72
|
this.render();
|
|
70
73
|
this.updateFormValue();
|
|
@@ -132,6 +135,9 @@ this[name === 'min' ? '_min' : '_max'] = newValue || undefined;
|
|
|
132
135
|
this.syncChildComponents();
|
|
133
136
|
this.updateValidity();
|
|
134
137
|
break;
|
|
138
|
+
case 'required':
|
|
139
|
+
this.updateValidity();
|
|
140
|
+
break;
|
|
135
141
|
case 'flavor':
|
|
136
142
|
this._flavor = newValue || 'primary';
|
|
137
143
|
this.syncChildComponents();
|
|
@@ -165,6 +171,12 @@ this.setAttribute('flavor', value);
|
|
|
165
171
|
else
|
|
166
172
|
this.removeAttribute('flavor');
|
|
167
173
|
}
|
|
174
|
+
get required() {
|
|
175
|
+
return this.hasAttribute('required');
|
|
176
|
+
}
|
|
177
|
+
set required(value) {
|
|
178
|
+
this.toggleAttribute('required', !!value);
|
|
179
|
+
}
|
|
168
180
|
get year() {
|
|
169
181
|
return this._state.selectedYear;
|
|
170
182
|
}
|
|
@@ -172,12 +184,12 @@ set year(value) {
|
|
|
172
184
|
if (value !== undefined) {
|
|
173
185
|
if (this._stateless) {
|
|
174
186
|
this._state.displayYear = value;
|
|
175
|
-
this.setAttribute('year', value
|
|
187
|
+
this.setAttribute('year', formatYear(value));
|
|
176
188
|
}
|
|
177
189
|
else {
|
|
178
190
|
this._state.selectedYear = value;
|
|
179
191
|
this._state.displayYear = value;
|
|
180
|
-
this.setAttribute('year', value
|
|
192
|
+
this.setAttribute('year', formatYear(value));
|
|
181
193
|
}
|
|
182
194
|
}
|
|
183
195
|
else {
|
|
@@ -306,14 +318,14 @@ this.syncChildComponents();
|
|
|
306
318
|
get value() {
|
|
307
319
|
const { selectedYear, selectedMonth, selectedDay } = this._state;
|
|
308
320
|
if (selectedYear && selectedMonth && selectedDay) {
|
|
309
|
-
return
|
|
321
|
+
return formatISODay(selectedYear, selectedMonth, selectedDay);
|
|
310
322
|
}
|
|
311
323
|
return '';
|
|
312
324
|
}
|
|
313
325
|
set value(isoDate) {
|
|
314
326
|
const set = ++this._valueSets;
|
|
315
327
|
const superseded = () => set !== this._valueSets;
|
|
316
|
-
if (
|
|
328
|
+
if (isoDate === null || isoDate === undefined || isoDate === '') {
|
|
317
329
|
delete this._state.selectedYear;
|
|
318
330
|
delete this._state.selectedMonth;
|
|
319
331
|
delete this._state.selectedDay;
|
|
@@ -328,18 +340,16 @@ this.removeAttribute('day');
|
|
|
328
340
|
}
|
|
329
341
|
}
|
|
330
342
|
else {
|
|
331
|
-
const
|
|
332
|
-
if (
|
|
333
|
-
const year =
|
|
334
|
-
const month = parseInt(match[2], 10);
|
|
335
|
-
const day = parseInt(match[3], 10);
|
|
343
|
+
const parsed = parseDateDay(isoDate);
|
|
344
|
+
if (parsed) {
|
|
345
|
+
const { year, month, day } = parsed;
|
|
336
346
|
this._state.selectedYear = year;
|
|
337
347
|
this._state.selectedMonth = month;
|
|
338
348
|
this._state.selectedDay = day;
|
|
339
349
|
this._state.displayYear = year;
|
|
340
350
|
this._state.displayMonth = month;
|
|
341
351
|
if (!this._stateless) {
|
|
342
|
-
this.setAttribute('year', year
|
|
352
|
+
this.setAttribute('year', formatYear(year));
|
|
343
353
|
if (superseded())
|
|
344
354
|
return;
|
|
345
355
|
this.setAttribute('month', month.toString());
|
|
@@ -455,13 +465,13 @@ this._monthDisplay.customCSS = this._customCSS;
|
|
|
455
465
|
}
|
|
456
466
|
const { selectedYear, selectedMonth, selectedDay } = this._state;
|
|
457
467
|
if (selectedYear && selectedMonth && selectedDay) {
|
|
458
|
-
|
|
459
|
-
this._monthDisplay.value = date.getTime();
|
|
468
|
+
this._monthDisplay.value = localMidnight(selectedYear, selectedMonth, selectedDay).getTime();
|
|
460
469
|
}
|
|
461
470
|
else {
|
|
462
471
|
this._monthDisplay.value = null;
|
|
463
472
|
}
|
|
464
473
|
}
|
|
474
|
+
this.updateValidity();
|
|
465
475
|
}
|
|
466
476
|
updateFormValue() {
|
|
467
477
|
if (this._stateless)
|
|
@@ -471,7 +481,7 @@ return;
|
|
|
471
481
|
const elementName = this.getAttribute('name');
|
|
472
482
|
const { selectedYear, selectedMonth, selectedDay } = this._state;
|
|
473
483
|
if (elementName && selectedYear && selectedMonth && selectedDay) {
|
|
474
|
-
const isoDate =
|
|
484
|
+
const isoDate = formatISODay(selectedYear, selectedMonth, selectedDay);
|
|
475
485
|
this._internals.setFormValue(isoDate);
|
|
476
486
|
}
|
|
477
487
|
else {
|
|
@@ -482,22 +492,27 @@ this.updateValidity();
|
|
|
482
492
|
updateValidity() {
|
|
483
493
|
if (!this._internals)
|
|
484
494
|
return;
|
|
495
|
+
const anchor = this.gridCell() ?? undefined;
|
|
485
496
|
const { selectedYear, selectedMonth, selectedDay } = this._state;
|
|
486
497
|
if (selectedYear && selectedMonth && selectedDay) {
|
|
487
|
-
const sel =
|
|
488
|
-
const min = this._min ?
|
|
489
|
-
const max = this._max ?
|
|
490
|
-
const message = () => nativeMessage('input', { type: 'date', min: this._min, max: this._max },
|
|
491
|
-
if (min && sel <
|
|
492
|
-
this._validity.set({ rangeUnderflow: true }, message());
|
|
498
|
+
const sel = utcMidnight(selectedYear, selectedMonth, selectedDay);
|
|
499
|
+
const min = this._min ? parseDateDay(this._min) : null;
|
|
500
|
+
const max = this._max ? parseDateDay(this._max) : null;
|
|
501
|
+
const message = () => nativeMessage('input', { type: 'date', min: toISODay(this._min) ?? undefined, max: toISODay(this._max) ?? undefined }, formatISODay(selectedYear, selectedMonth, selectedDay));
|
|
502
|
+
if (min && sel < utcMidnight(min.year, min.month, min.day)) {
|
|
503
|
+
this._validity.set({ rangeUnderflow: true }, message(), anchor);
|
|
493
504
|
return;
|
|
494
505
|
}
|
|
495
|
-
if (max && sel >
|
|
496
|
-
this._validity.set({ rangeOverflow: true }, message());
|
|
506
|
+
if (max && sel > utcMidnight(max.year, max.month, max.day)) {
|
|
507
|
+
this._validity.set({ rangeOverflow: true }, message(), anchor);
|
|
497
508
|
return;
|
|
498
509
|
}
|
|
499
510
|
}
|
|
500
|
-
this.
|
|
511
|
+
else if (this.required) {
|
|
512
|
+
this._validity.set({ valueMissing: true }, nativeMessage('input', { type: 'date', required: true }), anchor);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
this._validity.set({}, undefined, anchor);
|
|
501
516
|
}
|
|
502
517
|
get form() { return this._internals?.form ?? null; }
|
|
503
518
|
get validity() { return this._internals?.validity; }
|
|
@@ -547,7 +562,7 @@ this._state.selectedMonth = month;
|
|
|
547
562
|
this._state.selectedDay = day;
|
|
548
563
|
this._state.displayYear = year;
|
|
549
564
|
this._state.displayMonth = month;
|
|
550
|
-
this.setAttribute('year', year
|
|
565
|
+
this.setAttribute('year', formatYear(year));
|
|
551
566
|
this.setAttribute('month', month.toString());
|
|
552
567
|
this.setAttribute('day', day.toString());
|
|
553
568
|
this.updateFormValue();
|
|
@@ -572,6 +587,7 @@ this.syncChildComponents();
|
|
|
572
587
|
if (this._monthDisplay && typeof this._monthDisplay.refresh === 'function') {
|
|
573
588
|
this._monthDisplay.refresh();
|
|
574
589
|
}
|
|
590
|
+
this.updateValidity();
|
|
575
591
|
}
|
|
576
592
|
createNavigation() {
|
|
577
593
|
const nav = document.createElement('ty-calendar-navigation');
|
|
@@ -607,8 +623,7 @@ month.width = this._width;
|
|
|
607
623
|
}
|
|
608
624
|
const { selectedYear, selectedMonth, selectedDay } = this._state;
|
|
609
625
|
if (selectedYear && selectedMonth && selectedDay) {
|
|
610
|
-
|
|
611
|
-
month.value = date.getTime();
|
|
626
|
+
month.value = localMidnight(selectedYear, selectedMonth, selectedDay).getTime();
|
|
612
627
|
}
|
|
613
628
|
if (this._dayContentFn) {
|
|
614
629
|
month.dayContentFn = this._dayContentFn;
|
|
@@ -617,6 +632,7 @@ if (this._customCSS) {
|
|
|
617
632
|
month.customCSS = this._customCSS;
|
|
618
633
|
}
|
|
619
634
|
month.addEventListener('day-click', (e) => this.handleDayClick(e));
|
|
635
|
+
month.shadowRoot?.addEventListener('focusin', () => this.updateValidity());
|
|
620
636
|
this._monthDisplay = month;
|
|
621
637
|
return month;
|
|
622
638
|
}
|
|
@@ -629,7 +645,23 @@ root.innerHTML = '';
|
|
|
629
645
|
this._monthGrid = undefined;
|
|
630
646
|
const container = document.createElement('div');
|
|
631
647
|
container.className = 'calendar-container';
|
|
648
|
+
container.tabIndex = -1;
|
|
649
|
+
const press = () => {
|
|
650
|
+
this._pressing = true;
|
|
651
|
+
setTimeout(() => { this._pressing = false; });
|
|
652
|
+
};
|
|
653
|
+
container.addEventListener('pointerdown', press);
|
|
654
|
+
container.addEventListener('mousedown', press);
|
|
655
|
+
container.addEventListener('focus', () => {
|
|
656
|
+
if (this._pressing)
|
|
657
|
+
return;
|
|
658
|
+
queueMicrotask(() => {
|
|
659
|
+
if (this.shadowRoot?.activeElement === container)
|
|
660
|
+
this.gridCell()?.focus();
|
|
661
|
+
});
|
|
662
|
+
});
|
|
632
663
|
container.addEventListener('keydown', (e) => this.handleKeydown(e));
|
|
664
|
+
container.addEventListener('focusin', () => this.updateValidity());
|
|
633
665
|
this._container = container;
|
|
634
666
|
if (!this._hideNavigation) {
|
|
635
667
|
const nav = this.createNavigation();
|
|
@@ -640,6 +672,7 @@ container.appendChild(month);
|
|
|
640
672
|
root.appendChild(container);
|
|
641
673
|
if (this._view === 'months')
|
|
642
674
|
this.showBody();
|
|
675
|
+
this.updateValidity();
|
|
643
676
|
}
|
|
644
677
|
setView(view) {
|
|
645
678
|
if (view === this._view)
|
|
@@ -651,6 +684,7 @@ this._view = view;
|
|
|
651
684
|
if (this._navigation)
|
|
652
685
|
this._navigation.view = view;
|
|
653
686
|
this.showBody();
|
|
687
|
+
this.updateValidity();
|
|
654
688
|
}
|
|
655
689
|
showBody() {
|
|
656
690
|
const container = this._container;
|
|
@@ -676,8 +710,8 @@ static monthIndex(year, month) {
|
|
|
676
710
|
return year * 12 + (month - 1);
|
|
677
711
|
}
|
|
678
712
|
boundIndices() {
|
|
679
|
-
const min = this._min ?
|
|
680
|
-
const max = this._max ?
|
|
713
|
+
const min = this._min ? parseDateDay(this._min) : null;
|
|
714
|
+
const max = this._max ? parseDateDay(this._max) : null;
|
|
681
715
|
return {
|
|
682
716
|
minIdx: min ? TyCalendar.monthIndex(min.year, min.month) : null,
|
|
683
717
|
maxIdx: max ? TyCalendar.monthIndex(max.year, max.month) : null,
|
|
@@ -742,6 +776,11 @@ this.goTo(month, this._state.displayYear);
|
|
|
742
776
|
this.focusDayGrid();
|
|
743
777
|
}
|
|
744
778
|
handleKeydown(e) {
|
|
779
|
+
if (e.target === this._container && e.key.startsWith('Arrow')) {
|
|
780
|
+
e.preventDefault();
|
|
781
|
+
this.gridCell()?.focus();
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
745
784
|
if (e.key === 'Escape' && this._view === 'months') {
|
|
746
785
|
e.preventDefault();
|
|
747
786
|
e.stopPropagation();
|
|
@@ -777,10 +816,21 @@ requestAnimationFrame(() => {
|
|
|
777
816
|
this._navigation?.shadowRoot?.querySelector('.nav-title')?.focus();
|
|
778
817
|
});
|
|
779
818
|
}
|
|
819
|
+
gridCell() {
|
|
820
|
+
if (this._view === 'months') {
|
|
821
|
+
return this._monthGrid?.querySelector('.month-cell[tabindex="0"]:not(:disabled)')
|
|
822
|
+
?? this._monthGrid?.querySelector('.month-cell:not(:disabled)')
|
|
823
|
+
?? this._navigation?.shadowRoot?.querySelector('.nav-title')
|
|
824
|
+
?? null;
|
|
825
|
+
}
|
|
826
|
+
const root = this._monthDisplay?.shadowRoot;
|
|
827
|
+
return root?.querySelector('.calendar-day-cell[tabindex="0"]')
|
|
828
|
+
?? root?.querySelector('.calendar-day-cell.selected')
|
|
829
|
+
?? root?.querySelector('.calendar-day-cell')
|
|
830
|
+
?? null;
|
|
831
|
+
}
|
|
780
832
|
focus(options) {
|
|
781
|
-
const cell = this.
|
|
782
|
-
? this._monthGrid?.querySelector('.month-cell[tabindex="0"]')
|
|
783
|
-
: this._monthDisplay?.shadowRoot?.querySelector('.calendar-day-cell[tabindex="0"]');
|
|
833
|
+
const cell = this.gridCell();
|
|
784
834
|
if (cell)
|
|
785
835
|
cell.focus(options);
|
|
786
836
|
else
|
|
@@ -32,6 +32,8 @@ export interface TyCheckboxElement extends HTMLElement {
|
|
|
32
32
|
*/
|
|
33
33
|
export declare class TyCheckbox extends TyComponent<CheckboxState> implements TyCheckboxElement {
|
|
34
34
|
static formAssociated: boolean;
|
|
35
|
+
protected static delegatesFocus: boolean;
|
|
36
|
+
protected static labelClicks: boolean;
|
|
35
37
|
protected static properties: {
|
|
36
38
|
checked: {
|
|
37
39
|
type: "boolean";
|
|
@@ -98,6 +100,9 @@ export declare class TyCheckbox extends TyComponent<CheckboxState> implements Ty
|
|
|
98
100
|
protected getFormValue(): FormDataEntryValue | null;
|
|
99
101
|
private buildClassList;
|
|
100
102
|
private handleCheckboxClick;
|
|
103
|
+
/** The ring is for keyboard use: keys show it, a click hides it — also a
|
|
104
|
+
* <label>'s, which in Chromium focuses the box as :focus-visible. */
|
|
105
|
+
private showFocusRing;
|
|
101
106
|
private handleCheckboxKeydown;
|
|
102
107
|
private removeEventListeners;
|
|
103
108
|
/**
|
|
@@ -21,6 +21,9 @@ ensureStyles(shadow, { css: checkboxStyles, id: "ty-checkbox" });
|
|
|
21
21
|
onConnect() {
|
|
22
22
|
this.setupEventListeners();
|
|
23
23
|
this._syncCustomFlavor();
|
|
24
|
+
const el = this.shadowRoot.querySelector(".checkbox-container");
|
|
25
|
+
if (el && this.shadowRoot.activeElement !== el)
|
|
26
|
+
el.classList.remove("focused");
|
|
24
27
|
}
|
|
25
28
|
_syncCustomFlavor() {
|
|
26
29
|
this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.flavor, ({ base }) => checkboxCustomFlavorCss(base));
|
|
@@ -47,8 +50,7 @@ return classes.join(" ");
|
|
|
47
50
|
handleCheckboxClick(e) {
|
|
48
51
|
if (this.disabled)
|
|
49
52
|
return;
|
|
50
|
-
|
|
51
|
-
return;
|
|
53
|
+
this.showFocusRing(e instanceof KeyboardEvent);
|
|
52
54
|
const newValue = this.indeterminate ? true : !this.checked;
|
|
53
55
|
if (this.indeterminate)
|
|
54
56
|
this.indeterminate = false;
|
|
@@ -72,6 +74,9 @@ composed: true,
|
|
|
72
74
|
}));
|
|
73
75
|
}, 0);
|
|
74
76
|
}
|
|
77
|
+
showFocusRing(on) {
|
|
78
|
+
this.shadowRoot?.querySelector(".checkbox-container")?.classList.toggle("focused", on);
|
|
79
|
+
}
|
|
75
80
|
handleCheckboxKeydown(e) {
|
|
76
81
|
if (this.disabled)
|
|
77
82
|
return;
|
|
@@ -124,7 +129,7 @@ this._keydownHandler = (e) => {
|
|
|
124
129
|
this.handleCheckboxKeydown(e);
|
|
125
130
|
};
|
|
126
131
|
this._focusHandler = () => {
|
|
127
|
-
checkboxEl.classList.
|
|
132
|
+
checkboxEl.classList.toggle("focused", checkboxEl.matches(":focus-visible"));
|
|
128
133
|
};
|
|
129
134
|
this._blurHandler = () => {
|
|
130
135
|
checkboxEl.classList.remove("focused");
|
|
@@ -143,7 +148,8 @@ const ariaChecked = this.indeterminate ? "mixed" : String(this.checked);
|
|
|
143
148
|
if (!checkboxEl) {
|
|
144
149
|
checkboxEl = document.createElement("div");
|
|
145
150
|
checkboxEl.className = "checkbox-container " + classes;
|
|
146
|
-
|
|
151
|
+
if (!this.disabled)
|
|
152
|
+
checkboxEl.tabIndex = 0;
|
|
147
153
|
checkboxEl.setAttribute("role", "checkbox");
|
|
148
154
|
checkboxEl.setAttribute("aria-checked", ariaChecked);
|
|
149
155
|
checkboxEl.setAttribute("aria-disabled", String(this.disabled));
|
|
@@ -154,8 +160,13 @@ checkboxEl.appendChild(checkboxIcon);
|
|
|
154
160
|
shadow.appendChild(checkboxEl);
|
|
155
161
|
}
|
|
156
162
|
else {
|
|
163
|
+
const focused = checkboxEl.classList.contains("focused") && shadow.activeElement === checkboxEl;
|
|
157
164
|
checkboxEl.className = "checkbox-container " + classes;
|
|
158
|
-
checkboxEl.
|
|
165
|
+
checkboxEl.classList.toggle("focused", focused && !this.disabled);
|
|
166
|
+
if (this.disabled)
|
|
167
|
+
checkboxEl.removeAttribute("tabindex");
|
|
168
|
+
else
|
|
169
|
+
checkboxEl.tabIndex = 0;
|
|
159
170
|
checkboxEl.setAttribute("aria-checked", ariaChecked);
|
|
160
171
|
checkboxEl.setAttribute("aria-disabled", String(this.disabled));
|
|
161
172
|
checkboxEl.setAttribute("aria-required", String(this.required));
|
|
@@ -239,6 +250,8 @@ return this._internals.form;
|
|
|
239
250
|
}
|
|
240
251
|
}
|
|
241
252
|
TyCheckbox.formAssociated = true;
|
|
253
|
+
TyCheckbox.delegatesFocus = true;
|
|
254
|
+
TyCheckbox.labelClicks = true;
|
|
242
255
|
TyCheckbox.properties = {
|
|
243
256
|
checked: {
|
|
244
257
|
type: "boolean",
|
package/lib/components/copy.d.ts
CHANGED
|
@@ -109,6 +109,8 @@ export declare class TyCopy extends TyComponent<CopyState> implements TyCopyElem
|
|
|
109
109
|
* Uses state flag so render() can show the correct icon
|
|
110
110
|
*/
|
|
111
111
|
private showCopySuccess;
|
|
112
|
+
/** Feedback over: the copy icon again. */
|
|
113
|
+
private resetCopyButton;
|
|
112
114
|
/**
|
|
113
115
|
* Show copy error animation
|
|
114
116
|
* Swaps copy icon → red X icon → copy icon
|
package/lib/components/copy.js
CHANGED
|
@@ -32,7 +32,7 @@ this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFla
|
|
|
32
32
|
onDisconnect() {
|
|
33
33
|
if (this._copyTimeout !== null) {
|
|
34
34
|
clearTimeout(this._copyTimeout);
|
|
35
|
-
this.
|
|
35
|
+
this.resetCopyButton();
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
onPropertiesChanged(changes) {
|
|
@@ -61,15 +61,15 @@ composed: true
|
|
|
61
61
|
}));
|
|
62
62
|
}
|
|
63
63
|
catch (err) {
|
|
64
|
-
|
|
64
|
+
const focused = this.shadowRoot.activeElement;
|
|
65
65
|
const textarea = document.createElement('textarea');
|
|
66
|
+
try {
|
|
66
67
|
textarea.value = value;
|
|
67
68
|
textarea.style.position = 'fixed';
|
|
68
69
|
textarea.style.opacity = '0';
|
|
69
70
|
document.body.appendChild(textarea);
|
|
70
71
|
textarea.select();
|
|
71
72
|
document.execCommand('copy');
|
|
72
|
-
document.body.removeChild(textarea);
|
|
73
73
|
this.dispatchEvent(new CustomEvent('copy-success', {
|
|
74
74
|
detail: { value },
|
|
75
75
|
bubbles: true,
|
|
@@ -86,6 +86,10 @@ composed: true
|
|
|
86
86
|
this.showCopyError();
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
|
+
finally {
|
|
90
|
+
textarea.remove();
|
|
91
|
+
focused?.focus();
|
|
92
|
+
}
|
|
89
93
|
}
|
|
90
94
|
this.showCopySuccess();
|
|
91
95
|
}
|
|
@@ -100,16 +104,17 @@ copyButton.classList.add('success');
|
|
|
100
104
|
copyButton.innerHTML = CHECK_ICON_SVG;
|
|
101
105
|
copyButton.setAttribute('aria-label', 'Copied!');
|
|
102
106
|
}
|
|
103
|
-
this._copyTimeout = window.setTimeout(() =>
|
|
107
|
+
this._copyTimeout = window.setTimeout(() => this.resetCopyButton(), 2000);
|
|
108
|
+
}
|
|
109
|
+
resetCopyButton() {
|
|
104
110
|
this._showingSuccess = false;
|
|
105
111
|
const btn = this.shadowRoot.querySelector('.copy-button');
|
|
106
112
|
if (btn) {
|
|
107
|
-
btn.classList.remove('success');
|
|
113
|
+
btn.classList.remove('success', 'error');
|
|
108
114
|
btn.innerHTML = COPY_ICON_SVG;
|
|
109
115
|
btn.setAttribute('aria-label', 'Copy to clipboard');
|
|
110
116
|
}
|
|
111
117
|
this._copyTimeout = null;
|
|
112
|
-
}, 2000);
|
|
113
118
|
}
|
|
114
119
|
showCopyError() {
|
|
115
120
|
if (this._copyTimeout !== null) {
|
|
@@ -122,34 +127,13 @@ copyButton.classList.add('error');
|
|
|
122
127
|
copyButton.innerHTML = ERROR_ICON_SVG;
|
|
123
128
|
copyButton.setAttribute('aria-label', 'Copy failed');
|
|
124
129
|
}
|
|
125
|
-
this._copyTimeout = window.setTimeout(() =>
|
|
126
|
-
const btn = this.shadowRoot.querySelector('.copy-button');
|
|
127
|
-
if (btn) {
|
|
128
|
-
btn.classList.remove('error');
|
|
129
|
-
btn.innerHTML = COPY_ICON_SVG;
|
|
130
|
-
btn.setAttribute('aria-label', 'Copy to clipboard');
|
|
131
|
-
}
|
|
132
|
-
this._copyTimeout = null;
|
|
133
|
-
}, 2000);
|
|
130
|
+
this._copyTimeout = window.setTimeout(() => this.resetCopyButton(), 2000);
|
|
134
131
|
}
|
|
135
132
|
setupEventListeners() {
|
|
136
|
-
const
|
|
137
|
-
const inputWrapper = shadow.querySelector('.input-wrapper');
|
|
138
|
-
const copyButton = shadow.querySelector('.copy-button');
|
|
133
|
+
const inputWrapper = this.shadowRoot.querySelector('.input-wrapper');
|
|
139
134
|
if (inputWrapper && !this.disabled) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (e.target === copyButton || e.target.closest('.copy-button')) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
this.copyToClipboard();
|
|
146
|
-
});
|
|
147
|
-
wrapperEl.style.cursor = 'pointer';
|
|
148
|
-
}
|
|
149
|
-
if (copyButton) {
|
|
150
|
-
copyButton.addEventListener('click', () => {
|
|
151
|
-
this.copyToClipboard();
|
|
152
|
-
});
|
|
135
|
+
inputWrapper.addEventListener('click', () => this.copyToClipboard());
|
|
136
|
+
inputWrapper.style.cursor = 'pointer';
|
|
153
137
|
}
|
|
154
138
|
}
|
|
155
139
|
render() {
|
|
@@ -8,22 +8,11 @@ import { type Placement } from '../utils/positioning.js';
|
|
|
8
8
|
import { TyComponent } from '../base/ty-component.js';
|
|
9
9
|
import type { Flavor } from '../types/common.js';
|
|
10
10
|
import type { PropertyChange } from '../utils/property-manager.js';
|
|
11
|
-
|
|
12
|
-
* Date components (internal representation in local timezone)
|
|
13
|
-
*/
|
|
14
|
-
interface DateComponents {
|
|
15
|
-
year?: number;
|
|
16
|
-
month?: number;
|
|
17
|
-
day?: number;
|
|
18
|
-
hour?: number;
|
|
19
|
-
minute?: number;
|
|
20
|
-
second?: number;
|
|
21
|
-
epoch?: number;
|
|
22
|
-
}
|
|
11
|
+
import { type DateTimeParts } from '../utils/calendar-utils.js';
|
|
23
12
|
/**
|
|
24
13
|
* Internal date picker state
|
|
25
14
|
*/
|
|
26
|
-
interface DatePickerState extends
|
|
15
|
+
interface DatePickerState extends DateTimeParts {
|
|
27
16
|
withTime: boolean;
|
|
28
17
|
open: boolean;
|
|
29
18
|
}
|
|
@@ -193,14 +182,6 @@ export declare class TyDatePicker extends TyComponent<DatePickerState> {
|
|
|
193
182
|
* Compares before setting to prevent circular triggers
|
|
194
183
|
*/
|
|
195
184
|
private syncFormValue;
|
|
196
|
-
/**
|
|
197
|
-
* `error` turns an unflavored field ('default'/'neutral') danger, like
|
|
198
|
-
* ty-input; clearing it puts back exactly the flavor attribute the author
|
|
199
|
-
* had, or none, kept meanwhile in ERROR_FLAVOR. Runs once connected: while
|
|
200
|
-
* the element upgrades, `error` may come before the `flavor` written next
|
|
201
|
-
* to it.
|
|
202
|
-
*/
|
|
203
|
-
private syncErrorFlavor;
|
|
204
185
|
/**
|
|
205
186
|
* Handle time changes from the footer's hour/minute fields
|
|
206
187
|
*/
|
|
@@ -214,7 +195,6 @@ export declare class TyDatePicker extends TyComponent<DatePickerState> {
|
|
|
214
195
|
set placement(v: Placement | '');
|
|
215
196
|
get flavor(): DatePickerFlavor;
|
|
216
197
|
set flavor(v: DatePickerFlavor);
|
|
217
|
-
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
218
198
|
get label(): string;
|
|
219
199
|
set label(v: string);
|
|
220
200
|
get placeholder(): string;
|
|
@@ -248,7 +228,7 @@ export declare class TyDatePicker extends TyComponent<DatePickerState> {
|
|
|
248
228
|
*/
|
|
249
229
|
get value(): string | null;
|
|
250
230
|
/**
|
|
251
|
-
* Set value: any format
|
|
231
|
+
* Set value: any format parseDateTime() reads, a Date, epoch milliseconds,
|
|
252
232
|
* or null. It's normalized to the submitted form.
|
|
253
233
|
*
|
|
254
234
|
* When set to null/undefined/empty string, the attribute is removed.
|
|
@@ -268,9 +248,10 @@ export declare class TyDatePicker extends TyComponent<DatePickerState> {
|
|
|
268
248
|
private renderTimeSection;
|
|
269
249
|
private renderCalendarDropdown;
|
|
270
250
|
/**
|
|
271
|
-
* Match the popup calendar to the stub's
|
|
272
|
-
*
|
|
273
|
-
* state, not a real flavor: the
|
|
251
|
+
* Match the popup calendar to the stub's look: danger while an error
|
|
252
|
+
* shows, as on the stub (styles: errorLook), else the user's flavor.
|
|
253
|
+
* 'default' is the stub's own unstyled state, not a real flavor: the
|
|
254
|
+
* calendar stays on its own default.
|
|
274
255
|
*/
|
|
275
256
|
private calendarFlavor;
|
|
276
257
|
/**
|