@vaadin/date-picker 23.3.0-alpha5 → 24.0.0-alpha2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/date-picker",
3
- "version": "23.3.0-alpha5",
3
+ "version": "24.0.0-alpha2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,14 +36,14 @@
36
36
  "dependencies": {
37
37
  "@open-wc/dedupe-mixin": "^1.3.0",
38
38
  "@polymer/polymer": "^3.2.0",
39
- "@vaadin/button": "23.3.0-alpha5",
40
- "@vaadin/component-base": "23.3.0-alpha5",
41
- "@vaadin/field-base": "23.3.0-alpha5",
42
- "@vaadin/input-container": "23.3.0-alpha5",
43
- "@vaadin/overlay": "23.3.0-alpha5",
44
- "@vaadin/vaadin-lumo-styles": "23.3.0-alpha5",
45
- "@vaadin/vaadin-material-styles": "23.3.0-alpha5",
46
- "@vaadin/vaadin-themable-mixin": "23.3.0-alpha5"
39
+ "@vaadin/button": "24.0.0-alpha2",
40
+ "@vaadin/component-base": "24.0.0-alpha2",
41
+ "@vaadin/field-base": "24.0.0-alpha2",
42
+ "@vaadin/input-container": "24.0.0-alpha2",
43
+ "@vaadin/overlay": "24.0.0-alpha2",
44
+ "@vaadin/vaadin-lumo-styles": "24.0.0-alpha2",
45
+ "@vaadin/vaadin-material-styles": "24.0.0-alpha2",
46
+ "@vaadin/vaadin-themable-mixin": "24.0.0-alpha2"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@esm-bundle/chai": "^4.3.4",
@@ -54,5 +54,5 @@
54
54
  "web-types.json",
55
55
  "web-types.lit.json"
56
56
  ],
57
- "gitHead": "0b6fdcf444683e97e3efb433d603e1274d5bcd66"
57
+ "gitHead": "0c16c01a6807e629a84f5a982793afecc1a7ced0"
58
58
  }
@@ -42,6 +42,13 @@ export { extractDateParts };
42
42
  */
43
43
  declare function extractDateParts(date: Date): { day: number; month: number; year: number };
44
44
 
45
+ /**
46
+ * Get difference in months between today and given months value.
47
+ */
48
+ declare function dateAfterXMonths(months: number): number;
49
+
50
+ export { dateAfterXMonths };
51
+
45
52
  /**
46
53
  * Calculate the year of the date based on the provided reference date
47
54
  * Gets a two-digit year and returns a full year.
@@ -104,6 +104,20 @@ export function extractDateParts(date) {
104
104
  };
105
105
  }
106
106
 
107
+ /**
108
+ * Get difference in months between today and given months value.
109
+ *
110
+ * @param {number} months
111
+ * @return {number}
112
+ */
113
+ export function dateAfterXMonths(months) {
114
+ const today = new Date();
115
+ const result = new Date(today);
116
+ result.setDate(1);
117
+ result.setMonth(parseInt(months) + today.getMonth());
118
+ return result;
119
+ }
120
+
107
121
  /**
108
122
  * Calculate the year of the date based on the provided reference date.
109
123
  * Gets a two-digit year and returns a full year.
@@ -66,12 +66,6 @@ export interface DatePickerLightEventMap extends HTMLElementEventMap, DatePicker
66
66
  *
67
67
  * ### Styling
68
68
  *
69
- * The following shadow DOM parts are available for styling:
70
- *
71
- * Part name | Description | Theme for Element
72
- * ----------------|----------------|----------------
73
- * `overlay-content` | The overlay element | vaadin-date-picker-light
74
- *
75
69
  * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
76
70
  *
77
71
  * In addition to `<vaadin-date-picker-light>` itself, the following
@@ -28,12 +28,6 @@ import { DatePickerMixin } from './vaadin-date-picker-mixin.js';
28
28
  *
29
29
  * ### Styling
30
30
  *
31
- * The following shadow DOM parts are available for styling:
32
- *
33
- * Part name | Description | Theme for Element
34
- * ----------------|----------------|----------------
35
- * `overlay-content` | The overlay element | vaadin-date-picker-light
36
- *
37
31
  * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
38
32
  *
39
33
  * In addition to `<vaadin-date-picker-light>` itself, the following
@@ -73,29 +67,13 @@ class DatePickerLight extends ThemableMixin(DatePickerMixin(ValidateMixin(Polyme
73
67
  id="overlay"
74
68
  fullscreen$="[[_fullscreen]]"
75
69
  opened="{{opened}}"
70
+ on-vaadin-overlay-escape-press="_onOverlayEscapePress"
76
71
  on-vaadin-overlay-open="_onOverlayOpened"
77
72
  on-vaadin-overlay-closing="_onOverlayClosed"
78
73
  restore-focus-on-close
79
74
  restore-focus-node="[[inputElement]]"
80
- theme$="[[__getOverlayTheme(_theme, _overlayInitialized)]]"
81
- >
82
- <template>
83
- <vaadin-date-picker-overlay-content
84
- id="overlay-content"
85
- i18n="[[i18n]]"
86
- fullscreen$="[[_fullscreen]]"
87
- label="[[label]]"
88
- selected-date="[[_selectedDate]]"
89
- focused-date="{{_focusedDate}}"
90
- show-week-numbers="[[showWeekNumbers]]"
91
- min-date="[[_minDate]]"
92
- max-date="[[_maxDate]]"
93
- part="overlay-content"
94
- theme$="[[__getOverlayTheme(_theme, _overlayInitialized)]]"
95
- >
96
- </vaadin-date-picker-overlay-content>
97
- </template>
98
- </vaadin-date-picker-overlay>
75
+ theme$="[[_theme]]"
76
+ ></vaadin-date-picker-overlay>
99
77
  `;
100
78
  }
101
79
 
@@ -115,29 +93,13 @@ class DatePickerLight extends ThemableMixin(DatePickerMixin(ValidateMixin(Polyme
115
93
  type: String,
116
94
  value: 'value',
117
95
  },
118
-
119
- /**
120
- * @type {boolean}
121
- * @protected
122
- */
123
- _overlayInitialized: {
124
- type: Boolean,
125
- value: true,
126
- },
127
96
  };
128
97
  }
129
98
 
130
- /** @protected */
131
- ready() {
132
- super.ready();
133
-
134
- this._initOverlay();
135
- }
136
-
137
99
  /** @protected */
138
100
  connectedCallback() {
139
101
  super.connectedCallback();
140
- const cssSelector = 'vaadin-text-field,iron-input,paper-input,.paper-input-input,.input';
102
+ const cssSelector = 'vaadin-text-field,.input';
141
103
  this._setInputElement(this.querySelector(cssSelector));
142
104
  this._setFocusElement(this.inputElement);
143
105
  }
@@ -22,8 +22,6 @@ export interface DatePickerI18n {
22
22
  weekdays: string[];
23
23
  weekdaysShort: string[];
24
24
  firstDayOfWeek: number;
25
- week: string;
26
- calendar: string;
27
25
  today: string;
28
26
  cancel: string;
29
27
  referenceDate: string;
@@ -122,13 +120,6 @@ export declare class DatePickerMixinClass {
122
120
  * // (0 = Sunday, 1 = Monday, etc.).
123
121
  * firstDayOfWeek: 0,
124
122
  *
125
- * // Used in screen reader announcements along with week
126
- * // numbers, if they are displayed.
127
- * week: 'Week',
128
- *
129
- * // Translation of the Calendar icon button title.
130
- * calendar: 'Calendar',
131
- *
132
123
  * // Translation of the Today shortcut button text.
133
124
  * today: 'Today',
134
125
  *
@@ -91,6 +91,7 @@ export const DatePickerMixin = (subclass) =>
91
91
  */
92
92
  showWeekNumbers: {
93
93
  type: Boolean,
94
+ value: false,
94
95
  },
95
96
 
96
97
  /**
@@ -152,13 +153,6 @@ export const DatePickerMixin = (subclass) =>
152
153
  * // (0 = Sunday, 1 = Monday, etc.).
153
154
  * firstDayOfWeek: 0,
154
155
  *
155
- * // Used in screen reader announcements along with week
156
- * // numbers, if they are displayed.
157
- * week: 'Week',
158
- *
159
- * // Translation of the Calendar icon button title.
160
- * calendar: 'Calendar',
161
- *
162
156
  * // Translation of the Today shortcut button text.
163
157
  * today: 'Today',
164
158
  *
@@ -224,8 +218,6 @@ export const DatePickerMixin = (subclass) =>
224
218
  weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
225
219
  weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
226
220
  firstDayOfWeek: 0,
227
- week: 'Week',
228
- calendar: 'Calendar',
229
221
  today: 'Today',
230
222
  cancel: 'Cancel',
231
223
  referenceDate: '',
@@ -327,8 +319,8 @@ export const DatePickerMixin = (subclass) =>
327
319
  /** @private */
328
320
  _focusOverlayOnOpen: Boolean,
329
321
 
330
- /** @protected */
331
- _overlayInitialized: Boolean,
322
+ /** @private */
323
+ _overlayContent: Object,
332
324
  };
333
325
  }
334
326
 
@@ -336,6 +328,9 @@ export const DatePickerMixin = (subclass) =>
336
328
  return [
337
329
  '_selectedDateChanged(_selectedDate, i18n.formatDate)',
338
330
  '_focusedDateChanged(_focusedDate, i18n.formatDate)',
331
+ '__updateOverlayContent(_overlayContent, i18n, label, _minDate, _maxDate, _focusedDate, _selectedDate, showWeekNumbers)',
332
+ '__updateOverlayContentTheme(_overlayContent, _theme)',
333
+ '__updateOverlayContentFullScreen(_overlayContent, _fullscreen)',
339
334
  ];
340
335
  }
341
336
 
@@ -380,6 +375,7 @@ export const DatePickerMixin = (subclass) =>
380
375
 
381
376
  this._boundOnClick = this._onClick.bind(this);
382
377
  this._boundOnScroll = this._onScroll.bind(this);
378
+ this._boundOverlayRenderer = this._overlayRenderer.bind(this);
383
379
  }
384
380
 
385
381
  /**
@@ -430,6 +426,11 @@ export const DatePickerMixin = (subclass) =>
430
426
  );
431
427
 
432
428
  this.addController(new VirtualKeyboardController(this));
429
+
430
+ this.$.overlay.renderer = this._boundOverlayRenderer;
431
+
432
+ this.addEventListener('mousedown', () => this.__bringToFront());
433
+ this.addEventListener('touchstart', () => this.__bringToFront());
433
434
  }
434
435
 
435
436
  /** @protected */
@@ -471,33 +472,29 @@ export const DatePickerMixin = (subclass) =>
471
472
  * Closes the dropdown.
472
473
  */
473
474
  close() {
474
- if (this._overlayInitialized || this.autoOpenDisabled) {
475
- this.$.overlay.close();
476
- }
475
+ this.$.overlay.close();
477
476
  }
478
477
 
479
- /** @protected */
480
- _initOverlay() {
481
- this.$.overlay.removeAttribute('disable-upgrade');
482
- this._overlayInitialized = true;
478
+ /** @private */
479
+ _overlayRenderer(root) {
480
+ if (root.firstChild) {
481
+ return;
482
+ }
483
483
 
484
- this.$.overlay.addEventListener('opened-changed', (e) => {
485
- this.opened = e.detail.value;
486
- });
484
+ // Create and store document content element
485
+ const content = document.createElement('vaadin-date-picker-overlay-content');
486
+ root.appendChild(content);
487
487
 
488
- this.$.overlay.addEventListener('vaadin-overlay-escape-press', () => {
489
- this._focusedDate = this._selectedDate;
490
- this._close();
491
- });
488
+ this._overlayContent = content;
492
489
 
493
- this._overlayContent.addEventListener('close', () => {
490
+ content.addEventListener('close', () => {
494
491
  this._close();
495
492
  });
496
493
 
497
- this._overlayContent.addEventListener('focus-input', this._focusAndSelect.bind(this));
494
+ content.addEventListener('focus-input', this._focusAndSelect.bind(this));
498
495
 
499
496
  // User confirmed selected date by clicking the calendar.
500
- this._overlayContent.addEventListener('date-tap', (e) => {
497
+ content.addEventListener('date-tap', (e) => {
501
498
  this.__userConfirmedDate = true;
502
499
 
503
500
  this._selectDate(e.detail.date);
@@ -506,7 +503,7 @@ export const DatePickerMixin = (subclass) =>
506
503
  });
507
504
 
508
505
  // User confirmed selected date by pressing Enter or Today.
509
- this._overlayContent.addEventListener('date-selected', (e) => {
506
+ content.addEventListener('date-selected', (e) => {
510
507
  this.__userConfirmedDate = true;
511
508
 
512
509
  this._selectDate(e.detail.date);
@@ -514,14 +511,16 @@ export const DatePickerMixin = (subclass) =>
514
511
 
515
512
  // Set focus-ring attribute when moving focus to the overlay
516
513
  // by pressing Tab or arrow key, after opening it on click.
517
- this._overlayContent.addEventListener('focusin', () => {
514
+ content.addEventListener('focusin', () => {
518
515
  if (this._keyboardActive) {
519
516
  this._setFocused(true);
520
517
  }
521
518
  });
522
519
 
523
- this.addEventListener('mousedown', () => this.__bringToFront());
524
- this.addEventListener('touchstart', () => this.__bringToFront());
520
+ // Two-way data binding for `focusedDate` property
521
+ content.addEventListener('focused-date-changed', (e) => {
522
+ this._focusedDate = e.detail.value;
523
+ });
525
524
  }
526
525
 
527
526
  /**
@@ -680,12 +679,6 @@ export const DatePickerMixin = (subclass) =>
680
679
 
681
680
  /** @protected */
682
681
  _openedChanged(opened) {
683
- if (opened && !this._overlayInitialized) {
684
- this._initOverlay();
685
- }
686
- if (this._overlayInitialized) {
687
- this.$.overlay.opened = opened;
688
- }
689
682
  if (this.inputElement) {
690
683
  this.inputElement.setAttribute('aria-expanded', opened);
691
684
  }
@@ -721,13 +714,6 @@ export const DatePickerMixin = (subclass) =>
721
714
  }
722
715
  }
723
716
 
724
- /** @private */
725
- __getOverlayTheme(theme, overlayInitialized) {
726
- if (overlayInitialized) {
727
- return theme;
728
- }
729
- }
730
-
731
717
  /**
732
718
  * Override the value observer from `InputMixin` to implement custom
733
719
  * handling of the `value` property. The date-picker doesn't forward
@@ -766,6 +752,46 @@ export const DatePickerMixin = (subclass) =>
766
752
  this._toggleHasValue(this._hasValue);
767
753
  }
768
754
 
755
+ /** @private */
756
+ // eslint-disable-next-line max-params
757
+ __updateOverlayContent(overlayContent, i18n, label, minDate, maxDate, focusedDate, selectedDate, showWeekNumbers) {
758
+ if (overlayContent) {
759
+ overlayContent.setProperties({
760
+ i18n,
761
+ label,
762
+ minDate,
763
+ maxDate,
764
+ focusedDate,
765
+ selectedDate,
766
+ showWeekNumbers,
767
+ });
768
+ }
769
+ }
770
+
771
+ /** @private */
772
+ __updateOverlayContentTheme(overlayContent, theme) {
773
+ if (overlayContent) {
774
+ if (theme) {
775
+ overlayContent.setAttribute('theme', theme);
776
+ } else {
777
+ overlayContent.removeAttribute('theme');
778
+ }
779
+ }
780
+ }
781
+
782
+ /** @private */
783
+ __updateOverlayContentFullScreen(overlayContent, fullscreen) {
784
+ if (overlayContent) {
785
+ overlayContent.toggleAttribute('fullscreen', fullscreen);
786
+ }
787
+ }
788
+
789
+ /** @protected */
790
+ _onOverlayEscapePress() {
791
+ this._focusedDate = this._selectedDate;
792
+ this._close();
793
+ }
794
+
769
795
  /** @protected */
770
796
  _onOverlayOpened() {
771
797
  const parsedInitialPosition = parseDate(this.initialPosition);
@@ -1000,7 +1026,7 @@ export const DatePickerMixin = (subclass) =>
1000
1026
  const parsedDate = this._getParsedDate();
1001
1027
  const isValidDate = this._isValidDate(parsedDate);
1002
1028
  if (this.opened) {
1003
- if (this._overlayInitialized && this._overlayContent.focusedDate && isValidDate) {
1029
+ if (this._overlayContent && this._overlayContent.focusedDate && isValidDate) {
1004
1030
  this._selectDate(this._overlayContent.focusedDate);
1005
1031
  }
1006
1032
  this.close();
@@ -1088,11 +1114,6 @@ export const DatePickerMixin = (subclass) =>
1088
1114
  }
1089
1115
  }
1090
1116
 
1091
- /** @private */
1092
- get _overlayContent() {
1093
- return this.$.overlay.content.querySelector('#overlay-content');
1094
- }
1095
-
1096
1117
  /** @private */
1097
1118
  __computeMinOrMaxDate(dateString) {
1098
1119
  return parseDate(dateString);
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { html } from '@polymer/polymer/lib/utils/html-tag.js';
7
+ import { dateAfterXMonths } from './vaadin-date-picker-helper.js';
8
+ import { InfiniteScroller } from './vaadin-infinite-scroller.js';
9
+
10
+ const stylesTemplate = html`
11
+ <style>
12
+ :host {
13
+ --vaadin-infinite-scroller-item-height: 270px;
14
+ position: absolute;
15
+ top: 0;
16
+ left: 0;
17
+ right: 0;
18
+ bottom: 0;
19
+ height: 100%;
20
+ }
21
+ </style>
22
+ `;
23
+
24
+ let memoizedTemplate;
25
+
26
+ /**
27
+ * An element used internally by `<vaadin-date-picker>`. Not intended to be used separately.
28
+ *
29
+ * @extends InfiniteScroller
30
+ * @private
31
+ */
32
+ class DatePickerMonthScroller extends InfiniteScroller {
33
+ static get is() {
34
+ return 'vaadin-date-picker-month-scroller';
35
+ }
36
+
37
+ static get template() {
38
+ if (!memoizedTemplate) {
39
+ memoizedTemplate = super.template.cloneNode(true);
40
+ memoizedTemplate.content.appendChild(stylesTemplate.content.cloneNode(true));
41
+ }
42
+
43
+ return memoizedTemplate;
44
+ }
45
+
46
+ static get properties() {
47
+ return {
48
+ bufferSize: {
49
+ type: Number,
50
+ value: 3,
51
+ },
52
+ };
53
+ }
54
+
55
+ /**
56
+ * @protected
57
+ * @override
58
+ */
59
+ _createElement() {
60
+ return document.createElement('vaadin-month-calendar');
61
+ }
62
+
63
+ /**
64
+ * @param {HTMLElement} element
65
+ * @param {number} index
66
+ * @protected
67
+ * @override
68
+ */
69
+ _updateElement(element, index) {
70
+ element.month = dateAfterXMonths(index);
71
+ }
72
+ }
73
+
74
+ customElements.define(DatePickerMonthScroller.is, DatePickerMonthScroller);