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.
Files changed (108) hide show
  1. package/README.md +44 -52
  2. package/css/tyrell-colors-static.css +14 -0
  3. package/css/tyrell-theme.css +13 -7
  4. package/css/tyrell.css +15 -22
  5. package/dist/tyrell-colors-static.css +1 -1
  6. package/dist/tyrell-theme.css +1 -1
  7. package/dist/tyrell.css +1 -1
  8. package/dist/tyrell.js +1 -1
  9. package/lib/base/ty-component.d.ts +37 -15
  10. package/lib/base/ty-component.js +90 -26
  11. package/lib/components/button.d.ts +14 -0
  12. package/lib/components/button.js +61 -7
  13. package/lib/components/calendar-month.d.ts +7 -1
  14. package/lib/components/calendar-month.js +38 -30
  15. package/lib/components/calendar-navigation.d.ts +11 -0
  16. package/lib/components/calendar-navigation.js +68 -44
  17. package/lib/components/calendar.d.ts +52 -3
  18. package/lib/components/calendar.js +274 -61
  19. package/lib/components/checkbox.d.ts +8 -1
  20. package/lib/components/checkbox.js +29 -8
  21. package/lib/components/copy.d.ts +2 -0
  22. package/lib/components/copy.js +24 -33
  23. package/lib/components/date-picker.d.ts +68 -34
  24. package/lib/components/date-picker.js +386 -389
  25. package/lib/components/file-upload.d.ts +7 -0
  26. package/lib/components/file-upload.js +36 -4
  27. package/lib/components/input.d.ts +73 -3
  28. package/lib/components/input.js +159 -24
  29. package/lib/components/modal.d.ts +4 -8
  30. package/lib/components/modal.js +103 -33
  31. package/lib/components/option.js +7 -5
  32. package/lib/components/popup.js +117 -14
  33. package/lib/components/radio.d.ts +24 -0
  34. package/lib/components/radio.js +55 -32
  35. package/lib/components/resize-observer.js +2 -0
  36. package/lib/components/scroll-container.d.ts +3 -2
  37. package/lib/components/scroll-container.js +7 -8
  38. package/lib/components/select.d.ts +68 -11
  39. package/lib/components/select.js +196 -44
  40. package/lib/components/selected-tags.d.ts +7 -1
  41. package/lib/components/selected-tags.js +10 -1
  42. package/lib/components/switch.d.ts +9 -1
  43. package/lib/components/switch.js +29 -8
  44. package/lib/components/tab.d.ts +49 -1
  45. package/lib/components/tab.js +151 -10
  46. package/lib/components/tabs.d.ts +14 -2
  47. package/lib/components/tabs.js +185 -136
  48. package/lib/components/tag.d.ts +4 -7
  49. package/lib/components/tag.js +6 -7
  50. package/lib/components/textarea.d.ts +51 -5
  51. package/lib/components/textarea.js +95 -30
  52. package/lib/components/tooltip.d.ts +4 -3
  53. package/lib/components/tooltip.js +34 -24
  54. package/lib/components/wizard.d.ts +5 -4
  55. package/lib/components/wizard.js +120 -156
  56. package/lib/index.d.ts +2 -1
  57. package/lib/index.js +1 -0
  58. package/lib/styles/button.js +21 -19
  59. package/lib/styles/calendar-month.d.ts +3 -0
  60. package/lib/styles/calendar-month.js +43 -27
  61. package/lib/styles/calendar-navigation.d.ts +1 -1
  62. package/lib/styles/calendar-navigation.js +55 -26
  63. package/lib/styles/calendar.d.ts +3 -2
  64. package/lib/styles/calendar.js +77 -0
  65. package/lib/styles/checkbox.js +31 -13
  66. package/lib/styles/copy.js +5 -1
  67. package/lib/styles/date-picker.js +68 -26
  68. package/lib/styles/file-upload.d.ts +1 -1
  69. package/lib/styles/file-upload.js +3 -3
  70. package/lib/styles/icon.d.ts +1 -1
  71. package/lib/styles/icon.js +2 -2
  72. package/lib/styles/input.js +6 -10
  73. package/lib/styles/option.d.ts +1 -1
  74. package/lib/styles/option.js +7 -3
  75. package/lib/styles/popup.d.ts +1 -1
  76. package/lib/styles/popup.js +10 -5
  77. package/lib/styles/radio.js +18 -6
  78. package/lib/styles/scroll-container.d.ts +1 -1
  79. package/lib/styles/scroll-container.js +1 -1
  80. package/lib/styles/select-base.js +24 -3
  81. package/lib/styles/select.d.ts +1 -1
  82. package/lib/styles/select.js +10 -0
  83. package/lib/styles/step.d.ts +1 -1
  84. package/lib/styles/step.js +1 -9
  85. package/lib/styles/switch.js +14 -6
  86. package/lib/styles/tab.d.ts +1 -1
  87. package/lib/styles/tab.js +67 -3
  88. package/lib/styles/tabs.d.ts +1 -1
  89. package/lib/styles/tabs.js +7 -3
  90. package/lib/styles/tag.js +3 -3
  91. package/lib/styles/textarea.d.ts +1 -1
  92. package/lib/styles/textarea.js +7 -0
  93. package/lib/styles/wizard.d.ts +9 -5
  94. package/lib/styles/wizard.js +211 -99
  95. package/lib/types/common.d.ts +2 -2
  96. package/lib/utils/calendar-utils.d.ts +49 -0
  97. package/lib/utils/calendar-utils.js +63 -6
  98. package/lib/utils/property-manager.d.ts +7 -1
  99. package/lib/utils/property-manager.js +16 -4
  100. package/lib/utils/scroll-lock.d.ts +10 -4
  101. package/lib/utils/scroll-lock.js +102 -2
  102. package/lib/utils/upgrade-properties.d.ts +21 -0
  103. package/lib/utils/upgrade-properties.js +47 -0
  104. package/lib/utils/validity.d.ts +122 -0
  105. package/lib/utils/validity.js +289 -0
  106. package/lib/version.d.ts +1 -1
  107. package/lib/version.js +1 -1
  108. 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, parseISODate } from '../utils/calendar-utils.js';
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 CHEVRONS_LEFT_SVG = `<?xml version='1.0' encoding='UTF-8'?>
17
- <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'>
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 = parseISODate(this.min);
140
- const max = parseISODate(this.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 leftGroup = document.createElement('div');
193
- leftGroup.className = 'nav-group nav-group-left';
194
- leftGroup.appendChild(this.createButton('nav-btn nav-year-prev', 'Previous year', CHEVRONS_LEFT_SVG, () => this.navigateBy(-12), this.isNavDisabled(-12)));
195
- leftGroup.appendChild(this.createButton('nav-btn nav-month-prev', 'Previous month', CHEVRON_LEFT_SVG, () => this.navigateBy(-1), this.isNavDisabled(-1)));
196
- const centerGroup = document.createElement('div');
197
- centerGroup.className = 'nav-group nav-group-center';
198
- const monthYearDisplay = document.createElement('div');
199
- monthYearDisplay.className = 'month-year-display';
200
- monthYearDisplay.textContent = `${monthName} ${this._state.displayYear}`;
201
- centerGroup.appendChild(monthYearDisplay);
202
- const rightGroup = document.createElement('div');
203
- rightGroup.className = 'nav-group nav-group-right';
204
- rightGroup.appendChild(this.createButton('nav-btn nav-month-next', 'Next month', CHEVRON_RIGHT_SVG, () => this.navigateBy(1), this.isNavDisabled(1)));
205
- rightGroup.appendChild(this.createButton('nav-btn nav-year-next', 'Next year', CHEVRONS_RIGHT_SVG, () => this.navigateBy(12), this.isNavDisabled(12)));
206
- header.appendChild(leftGroup);
207
- header.appendChild(centerGroup);
208
- header.appendChild(rightGroup);
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: 'en-US'
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
- set value(isoDate: string);
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
- * Selection outside [min, max] => rangeUnderflow/rangeOverflow.
93
- * UI can't produce this (days are disabled), but programmatic values can.
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
  }