tyrell-components 1.0.0-RC15 → 1.0.0-RC17
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 +44 -52
- package/css/tyrell-colors-static.css +14 -0
- package/css/tyrell-theme.css +13 -7
- package/css/tyrell.css +15 -22
- package/dist/tyrell-colors-static.css +1 -1
- package/dist/tyrell-theme.css +1 -1
- package/dist/tyrell.css +1 -1
- package/dist/tyrell.js +1 -1
- package/lib/base/ty-component.d.ts +37 -15
- package/lib/base/ty-component.js +90 -26
- package/lib/components/button.d.ts +14 -0
- package/lib/components/button.js +61 -7
- package/lib/components/calendar-month.d.ts +7 -1
- package/lib/components/calendar-month.js +38 -30
- package/lib/components/calendar-navigation.d.ts +11 -0
- package/lib/components/calendar-navigation.js +68 -44
- package/lib/components/calendar.d.ts +52 -3
- package/lib/components/calendar.js +274 -61
- package/lib/components/checkbox.d.ts +8 -1
- package/lib/components/checkbox.js +29 -8
- package/lib/components/copy.d.ts +2 -0
- package/lib/components/copy.js +24 -33
- package/lib/components/date-picker.d.ts +68 -34
- package/lib/components/date-picker.js +386 -389
- package/lib/components/file-upload.d.ts +7 -0
- package/lib/components/file-upload.js +36 -4
- package/lib/components/input.d.ts +73 -3
- package/lib/components/input.js +159 -24
- package/lib/components/modal.d.ts +4 -8
- package/lib/components/modal.js +103 -33
- package/lib/components/option.js +7 -5
- package/lib/components/popup.js +117 -14
- package/lib/components/radio.d.ts +24 -0
- package/lib/components/radio.js +55 -32
- package/lib/components/resize-observer.js +2 -0
- package/lib/components/scroll-container.d.ts +3 -2
- package/lib/components/scroll-container.js +7 -8
- package/lib/components/select.d.ts +68 -11
- package/lib/components/select.js +196 -44
- package/lib/components/selected-tags.d.ts +7 -1
- package/lib/components/selected-tags.js +10 -1
- package/lib/components/switch.d.ts +9 -1
- package/lib/components/switch.js +29 -8
- package/lib/components/tab.d.ts +49 -1
- package/lib/components/tab.js +151 -10
- package/lib/components/tabs.d.ts +14 -2
- package/lib/components/tabs.js +185 -136
- package/lib/components/tag.d.ts +4 -7
- package/lib/components/tag.js +6 -7
- package/lib/components/textarea.d.ts +51 -5
- package/lib/components/textarea.js +95 -30
- package/lib/components/tooltip.d.ts +4 -3
- package/lib/components/tooltip.js +34 -24
- package/lib/components/wizard.d.ts +5 -4
- package/lib/components/wizard.js +120 -156
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -0
- package/lib/styles/button.js +21 -19
- package/lib/styles/calendar-month.d.ts +3 -0
- package/lib/styles/calendar-month.js +43 -27
- package/lib/styles/calendar-navigation.d.ts +1 -1
- package/lib/styles/calendar-navigation.js +55 -26
- package/lib/styles/calendar.d.ts +3 -2
- package/lib/styles/calendar.js +77 -0
- package/lib/styles/checkbox.js +31 -13
- package/lib/styles/copy.js +5 -1
- package/lib/styles/date-picker.js +68 -26
- package/lib/styles/file-upload.d.ts +1 -1
- package/lib/styles/file-upload.js +3 -3
- package/lib/styles/icon.d.ts +1 -1
- package/lib/styles/icon.js +2 -2
- package/lib/styles/input.js +6 -10
- package/lib/styles/option.d.ts +1 -1
- package/lib/styles/option.js +7 -3
- package/lib/styles/popup.d.ts +1 -1
- package/lib/styles/popup.js +10 -5
- package/lib/styles/radio.js +18 -6
- package/lib/styles/scroll-container.d.ts +1 -1
- package/lib/styles/scroll-container.js +1 -1
- package/lib/styles/select-base.js +24 -3
- package/lib/styles/select.d.ts +1 -1
- package/lib/styles/select.js +10 -0
- package/lib/styles/step.d.ts +1 -1
- package/lib/styles/step.js +1 -9
- package/lib/styles/switch.js +14 -6
- package/lib/styles/tab.d.ts +1 -1
- package/lib/styles/tab.js +67 -3
- package/lib/styles/tabs.d.ts +1 -1
- package/lib/styles/tabs.js +7 -3
- package/lib/styles/tag.js +3 -3
- package/lib/styles/textarea.d.ts +1 -1
- package/lib/styles/textarea.js +7 -0
- package/lib/styles/wizard.d.ts +9 -5
- package/lib/styles/wizard.js +211 -99
- package/lib/types/common.d.ts +2 -2
- package/lib/utils/calendar-utils.d.ts +49 -0
- package/lib/utils/calendar-utils.js +63 -6
- package/lib/utils/property-manager.d.ts +7 -1
- package/lib/utils/property-manager.js +16 -4
- package/lib/utils/scroll-lock.d.ts +10 -4
- package/lib/utils/scroll-lock.js +102 -2
- package/lib/utils/upgrade-properties.d.ts +21 -0
- package/lib/utils/upgrade-properties.js +47 -0
- package/lib/utils/validity.d.ts +122 -0
- package/lib/utils/validity.js +289 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +27 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ensureStyles } from '../utils/styles.js';
|
|
2
2
|
import { calendarNavigationStyles } from '../styles/calendar-navigation.js';
|
|
3
|
-
import { getMonthName,
|
|
3
|
+
import { getMonthName, parseDateDay } from '../utils/calendar-utils.js';
|
|
4
4
|
import { getEffectiveLocale, observeLocaleChanges } from '../utils/locale.js';
|
|
5
5
|
import { TyComponent } from '../base/ty-component.js';
|
|
6
6
|
const CHEVRON_LEFT_SVG = `<?xml version='1.0' encoding='UTF-8'?>
|
|
@@ -13,29 +13,8 @@ const CHEVRON_RIGHT_SVG = `<?xml version='1.0' encoding='UTF-8'?>
|
|
|
13
13
|
<path fill='none' d='M0 0h24v24H0V0z'/>
|
|
14
14
|
<path d='M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z'/>
|
|
15
15
|
</svg>`;
|
|
16
|
-
const
|
|
17
|
-
<
|
|
18
|
-
<g>
|
|
19
|
-
<rect width='24' height='24' fill='none'/>
|
|
20
|
-
</g>
|
|
21
|
-
<g>
|
|
22
|
-
<g>
|
|
23
|
-
<polygon points='17.59,18 19,16.59 14.42,12 19,7.41 17.59,6 11.59,12'/>
|
|
24
|
-
<polygon points='11,18 12.41,16.59 7.83,12 12.41,7.41 11,6 5,12'/>
|
|
25
|
-
</g>
|
|
26
|
-
</g>
|
|
27
|
-
</svg>`;
|
|
28
|
-
const CHEVRONS_RIGHT_SVG = `<?xml version='1.0' encoding='UTF-8'?>
|
|
29
|
-
<svg width='24' viewBox='0 0 24 24' height='24' enable-background='new 0 0 24 24' xmlns='http://www.w3.org/2000/svg' stroke-width='0' stroke='currentColor' fill='currentColor'>
|
|
30
|
-
<g>
|
|
31
|
-
<rect width='24' height='24' fill='none'/>
|
|
32
|
-
</g>
|
|
33
|
-
<g>
|
|
34
|
-
<g>
|
|
35
|
-
<polygon points='6.41,6 5,7.41 9.58,12 5,16.59 6.41,18 12.41,12'/>
|
|
36
|
-
<polygon points='13,6 11.59,7.41 16.17,12 11.59,16.59 13,18 19,12'/>
|
|
37
|
-
</g>
|
|
38
|
-
</g>
|
|
16
|
+
const CARET_DOWN_SVG = `<svg width='24' viewBox='0 0 24 24' height='24' xmlns='http://www.w3.org/2000/svg' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'>
|
|
17
|
+
<path d='m6 9 6 6 6-6'/>
|
|
39
18
|
</svg>`;
|
|
40
19
|
export class TyCalendarNavigation extends TyComponent {
|
|
41
20
|
constructor() {
|
|
@@ -52,6 +31,7 @@ onConnect() {
|
|
|
52
31
|
this._state.displayMonth = this.displayMonth;
|
|
53
32
|
this._state.displayYear = this.displayYear;
|
|
54
33
|
this._localeObserver = observeLocaleChanges(this, () => {
|
|
34
|
+
if (!this.getProperty('locale'))
|
|
55
35
|
this.render();
|
|
56
36
|
});
|
|
57
37
|
this.render();
|
|
@@ -74,6 +54,7 @@ break;
|
|
|
74
54
|
case 'locale':
|
|
75
55
|
case 'size':
|
|
76
56
|
case 'width':
|
|
57
|
+
case 'view':
|
|
77
58
|
break;
|
|
78
59
|
}
|
|
79
60
|
}
|
|
@@ -108,6 +89,12 @@ return this.getProperty('width');
|
|
|
108
89
|
set width(value) {
|
|
109
90
|
this.setProperty('width', value);
|
|
110
91
|
}
|
|
92
|
+
get view() {
|
|
93
|
+
return this.getProperty('view');
|
|
94
|
+
}
|
|
95
|
+
set view(value) {
|
|
96
|
+
this.setProperty('view', value);
|
|
97
|
+
}
|
|
111
98
|
get min() {
|
|
112
99
|
return this.getProperty('min');
|
|
113
100
|
}
|
|
@@ -136,8 +123,8 @@ static monthIndex(year, month) {
|
|
|
136
123
|
return year * 12 + (month - 1);
|
|
137
124
|
}
|
|
138
125
|
boundIndices() {
|
|
139
|
-
const min =
|
|
140
|
-
const max =
|
|
126
|
+
const min = parseDateDay(this.min);
|
|
127
|
+
const max = parseDateDay(this.max);
|
|
141
128
|
return {
|
|
142
129
|
minIdx: min ? TyCalendarNavigation.monthIndex(min.year, min.month) : null,
|
|
143
130
|
maxIdx: max ? TyCalendarNavigation.monthIndex(max.year, max.month) : null,
|
|
@@ -164,8 +151,10 @@ return this.clampIndex(current + deltaMonths) === current;
|
|
|
164
151
|
}
|
|
165
152
|
createButton(className, title, svg, onClick, disabled = false) {
|
|
166
153
|
const button = document.createElement('button');
|
|
154
|
+
button.type = 'button';
|
|
167
155
|
button.className = className;
|
|
168
156
|
button.title = title;
|
|
157
|
+
button.setAttribute('aria-label', title);
|
|
169
158
|
button.innerHTML = svg;
|
|
170
159
|
button.disabled = disabled;
|
|
171
160
|
button.addEventListener('click', onClick);
|
|
@@ -185,28 +174,56 @@ this.style.setProperty('--nav-width', width);
|
|
|
185
174
|
else {
|
|
186
175
|
this.style.removeProperty('--nav-width');
|
|
187
176
|
}
|
|
177
|
+
const months = this.view === 'months';
|
|
188
178
|
const monthName = getMonthName(this._state.displayMonth, this.locale, 'long');
|
|
179
|
+
const had = root.activeElement;
|
|
180
|
+
const place = !had ? null
|
|
181
|
+
: had.classList.contains('nav-title') ? 'title'
|
|
182
|
+
: had.className.includes('-prev') ? 'prev'
|
|
183
|
+
: had.className.includes('-next') ? 'next'
|
|
184
|
+
: null;
|
|
189
185
|
root.innerHTML = '';
|
|
190
186
|
const header = document.createElement('div');
|
|
191
187
|
header.className = 'calendar-navigation-header';
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
188
|
+
const title = document.createElement('button');
|
|
189
|
+
title.type = 'button';
|
|
190
|
+
title.className = 'nav-title';
|
|
191
|
+
title.setAttribute('aria-expanded', String(months));
|
|
192
|
+
title.setAttribute('aria-label', months ? 'Back to days' : 'Choose month and year');
|
|
193
|
+
if (!months) {
|
|
194
|
+
const month = document.createElement('span');
|
|
195
|
+
month.className = 'nav-title-month';
|
|
196
|
+
month.textContent = monthName;
|
|
197
|
+
title.appendChild(month);
|
|
198
|
+
}
|
|
199
|
+
const year = document.createElement('span');
|
|
200
|
+
year.className = months ? 'nav-title-month' : 'nav-title-year';
|
|
201
|
+
year.textContent = String(this._state.displayYear);
|
|
202
|
+
title.appendChild(year);
|
|
203
|
+
const caret = document.createElement('span');
|
|
204
|
+
caret.className = 'nav-caret';
|
|
205
|
+
caret.innerHTML = CARET_DOWN_SVG;
|
|
206
|
+
title.appendChild(caret);
|
|
207
|
+
title.addEventListener('click', () => {
|
|
208
|
+
this.dispatchEvent(new CustomEvent('view-toggle', {
|
|
209
|
+
detail: { view: months ? 'days' : 'months' },
|
|
210
|
+
}));
|
|
211
|
+
});
|
|
212
|
+
const step = months ? 12 : 1;
|
|
213
|
+
const unit = months ? 'year' : 'month';
|
|
214
|
+
const arrows = document.createElement('div');
|
|
215
|
+
arrows.className = 'nav-group nav-arrows';
|
|
216
|
+
const prev = this.createButton(`nav-btn nav-${unit}-prev`, `Previous ${unit}`, CHEVRON_LEFT_SVG, () => this.navigateBy(-step), this.isNavDisabled(-step));
|
|
217
|
+
const next = this.createButton(`nav-btn nav-${unit}-next`, `Next ${unit}`, CHEVRON_RIGHT_SVG, () => this.navigateBy(step), this.isNavDisabled(step));
|
|
218
|
+
arrows.appendChild(prev);
|
|
219
|
+
arrows.appendChild(next);
|
|
220
|
+
header.appendChild(title);
|
|
221
|
+
header.appendChild(arrows);
|
|
209
222
|
root.appendChild(header);
|
|
223
|
+
if (place) {
|
|
224
|
+
const successor = place === 'prev' ? prev : place === 'next' ? next : title;
|
|
225
|
+
(successor.disabled ? title : successor).focus({ preventScroll: true });
|
|
226
|
+
}
|
|
210
227
|
}
|
|
211
228
|
}
|
|
212
229
|
TyCalendarNavigation.properties = {
|
|
@@ -247,7 +264,7 @@ return num;
|
|
|
247
264
|
locale: {
|
|
248
265
|
type: 'string',
|
|
249
266
|
visual: true,
|
|
250
|
-
default: '
|
|
267
|
+
default: ''
|
|
251
268
|
},
|
|
252
269
|
size: {
|
|
253
270
|
type: 'string',
|
|
@@ -267,6 +284,13 @@ type: 'string',
|
|
|
267
284
|
visual: true,
|
|
268
285
|
default: ''
|
|
269
286
|
},
|
|
287
|
+
view: {
|
|
288
|
+
type: 'string',
|
|
289
|
+
visual: true,
|
|
290
|
+
default: 'days',
|
|
291
|
+
validate: (v) => v === 'days' || v === 'months',
|
|
292
|
+
coerce: (v) => (v === 'months' ? 'months' : 'days')
|
|
293
|
+
},
|
|
270
294
|
min: {
|
|
271
295
|
type: 'string',
|
|
272
296
|
visual: true,
|
|
@@ -43,8 +43,15 @@ export declare class TyCalendar extends HTMLElement {
|
|
|
43
43
|
private _flavor;
|
|
44
44
|
private _navigation?;
|
|
45
45
|
private _monthDisplay?;
|
|
46
|
+
private _container?;
|
|
47
|
+
private _view;
|
|
48
|
+
private _monthGrid?;
|
|
49
|
+
private _dayGridHeight;
|
|
46
50
|
private _internals?;
|
|
51
|
+
private _validity?;
|
|
47
52
|
private _initialValue;
|
|
53
|
+
private _valueSets;
|
|
54
|
+
private _pressing;
|
|
48
55
|
private _localeObserver?;
|
|
49
56
|
static formAssociated: boolean;
|
|
50
57
|
static get observedAttributes(): string[];
|
|
@@ -58,6 +65,8 @@ export declare class TyCalendar extends HTMLElement {
|
|
|
58
65
|
set max(value: string | undefined);
|
|
59
66
|
get flavor(): string;
|
|
60
67
|
set flavor(value: string);
|
|
68
|
+
get required(): boolean;
|
|
69
|
+
set required(value: boolean);
|
|
61
70
|
get year(): number | undefined;
|
|
62
71
|
set year(value: number | undefined);
|
|
63
72
|
get month(): number | undefined;
|
|
@@ -79,7 +88,12 @@ export declare class TyCalendar extends HTMLElement {
|
|
|
79
88
|
get customCSS(): CSSStyleSheet | undefined;
|
|
80
89
|
set customCSS(sheet: CSSStyleSheet | undefined);
|
|
81
90
|
get value(): string;
|
|
82
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Reads what ty-date-picker reads: 'YYYY-MM-DD', 'YYYY-MM-DDTHH:mm[:ss]'
|
|
93
|
+
* (that day), an ISO instant with Z/offset or epoch ms / a Date (its local
|
|
94
|
+
* day). The value stays 'YYYY-MM-DD'; anything else is no value.
|
|
95
|
+
*/
|
|
96
|
+
set value(isoDate: string | number | Date | null | undefined);
|
|
83
97
|
/**
|
|
84
98
|
* Initialize state from HTML attributes on first load
|
|
85
99
|
*/
|
|
@@ -89,11 +103,25 @@ export declare class TyCalendar extends HTMLElement {
|
|
|
89
103
|
private syncChildComponents;
|
|
90
104
|
private updateFormValue;
|
|
91
105
|
/**
|
|
92
|
-
*
|
|
93
|
-
* UI can't
|
|
106
|
+
* required with no selection => valueMissing; a selection outside
|
|
107
|
+
* [min, max] => rangeUnderflow/rangeOverflow (UI can't pick one, days are
|
|
108
|
+
* disabled, but programmatic values can). With a native date input's
|
|
109
|
+
* message. The grid's tab stop is the anchor, so a submit focuses it and
|
|
110
|
+
* the browser shows its bubble there; the cells are rebuilt on every grid
|
|
111
|
+
* render, so each one runs this again.
|
|
94
112
|
*/
|
|
95
113
|
private updateValidity;
|
|
114
|
+
get form(): HTMLFormElement | null;
|
|
115
|
+
get validity(): ValidityState | undefined;
|
|
116
|
+
get validationMessage(): string;
|
|
117
|
+
get willValidate(): boolean;
|
|
118
|
+
checkValidity(): boolean;
|
|
119
|
+
reportValidity(): boolean;
|
|
120
|
+
setCustomValidity(message: string): void;
|
|
96
121
|
private handleNavigationChange;
|
|
122
|
+
/** Show a month (and emit navigate). Shared by the arrows, the month grid
|
|
123
|
+
and Page Up / Page Down. */
|
|
124
|
+
private goTo;
|
|
97
125
|
private handleDayClick;
|
|
98
126
|
/**
|
|
99
127
|
* Force re-render of the calendar
|
|
@@ -103,4 +131,25 @@ export declare class TyCalendar extends HTMLElement {
|
|
|
103
131
|
private createNavigation;
|
|
104
132
|
private createMonthDisplay;
|
|
105
133
|
private render;
|
|
134
|
+
private setView;
|
|
135
|
+
/** Put the day grid or a freshly built month grid under the navigation. */
|
|
136
|
+
private showBody;
|
|
137
|
+
private static monthIndex;
|
|
138
|
+
/** min/max as month indices (null when unset) */
|
|
139
|
+
private boundIndices;
|
|
140
|
+
private buildMonthGrid;
|
|
141
|
+
private pickMonth;
|
|
142
|
+
private handleKeydown;
|
|
143
|
+
private focusNavTitle;
|
|
144
|
+
/**
|
|
145
|
+
* The grid's tab stop: the focused day, or month in the month view. When
|
|
146
|
+
* every day shown is disabled (a value outside min/max) there is none: then
|
|
147
|
+
* the selected day, or the first one; disabled cells still take focus.
|
|
148
|
+
* Disabled month cells don't (buttons): with every month of the year
|
|
149
|
+
* disabled, the navigation title (back to the days) stands in.
|
|
150
|
+
*/
|
|
151
|
+
private gridCell;
|
|
152
|
+
/** Focus the grid's tab stop (see gridCell). */
|
|
153
|
+
focus(options?: FocusOptions): void;
|
|
154
|
+
private focusDayGrid;
|
|
106
155
|
}
|