@vaadin/date-picker 24.2.0-dev.f254716fe → 24.3.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.
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { css } from 'lit';
7
+
8
+ export const datePickerOverlayStyles = css`
9
+ [part='overlay'] {
10
+ display: flex;
11
+ flex: auto;
12
+ }
13
+
14
+ [part~='content'] {
15
+ flex: auto;
16
+ }
17
+
18
+ @media (forced-colors: active) {
19
+ [part='overlay'] {
20
+ outline: 3px solid;
21
+ }
22
+ }
23
+ `;
@@ -4,28 +4,13 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
+ import { defineCustomElement } from '@vaadin/component-base/src/define.js';
7
8
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
8
9
  import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js';
9
10
  import { PositionMixin } from '@vaadin/overlay/src/vaadin-overlay-position-mixin.js';
10
11
  import { overlayStyles } from '@vaadin/overlay/src/vaadin-overlay-styles.js';
11
- import { css, registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
12
-
13
- const datePickerOverlayStyles = css`
14
- [part='overlay'] {
15
- display: flex;
16
- flex: auto;
17
- }
18
-
19
- [part~='content'] {
20
- flex: auto;
21
- }
22
-
23
- @media (forced-colors: active) {
24
- [part='overlay'] {
25
- outline: 3px solid;
26
- }
27
- }
28
- `;
12
+ import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
13
+ import { datePickerOverlayStyles } from './vaadin-date-picker-overlay-styles.js';
29
14
 
30
15
  registerStyles('vaadin-date-picker-overlay', [overlayStyles, datePickerOverlayStyles], {
31
16
  moduleId: 'vaadin-date-picker-overlay-styles',
@@ -34,7 +19,12 @@ registerStyles('vaadin-date-picker-overlay', [overlayStyles, datePickerOverlaySt
34
19
  /**
35
20
  * An element used internally by `<vaadin-date-picker>`. Not intended to be used separately.
36
21
  *
37
- * @extends Overlay
22
+ * @customElement
23
+ * @extends HTMLElement
24
+ * @mixes PositionMixin
25
+ * @mixes OverlayMixin
26
+ * @mixes DirMixin
27
+ * @mixes ThemableMixin
38
28
  * @private
39
29
  */
40
30
  class DatePickerOverlay extends PositionMixin(OverlayMixin(DirMixin(ThemableMixin(PolymerElement)))) {
@@ -54,4 +44,4 @@ class DatePickerOverlay extends PositionMixin(OverlayMixin(DirMixin(ThemableMixi
54
44
  }
55
45
  }
56
46
 
57
- customElements.define(DatePickerOverlay.is, DatePickerOverlay);
47
+ defineCustomElement(DatePickerOverlay);
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { css } from 'lit';
7
+
8
+ export const datePickerStyles = css`
9
+ :host([opened]) {
10
+ pointer-events: auto;
11
+ }
12
+
13
+ :host([dir='rtl']) [part='input-field'] {
14
+ direction: ltr;
15
+ }
16
+
17
+ :host([dir='rtl']) [part='input-field'] ::slotted(input)::placeholder {
18
+ direction: rtl;
19
+ text-align: left;
20
+ }
21
+ `;
@@ -3,10 +3,11 @@
3
3
  * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { html } from '@polymer/polymer/lib/utils/html-tag.js';
6
+ import { defineCustomElement } from '@vaadin/component-base/src/define.js';
7
7
  import { InfiniteScroller } from './vaadin-infinite-scroller.js';
8
8
 
9
- const stylesTemplate = html`
9
+ const stylesTemplate = document.createElement('template');
10
+ stylesTemplate.innerHTML = `
10
11
  <style>
11
12
  :host {
12
13
  --vaadin-infinite-scroller-item-height: 80px;
@@ -42,13 +43,11 @@ const stylesTemplate = html`
42
43
  </style>
43
44
  `;
44
45
 
45
- let memoizedTemplate;
46
-
47
46
  /**
48
47
  * An element used internally by `<vaadin-date-picker>`. Not intended to be used separately.
49
48
  *
49
+ * @customElement
50
50
  * @extends InfiniteScroller
51
- * @mixes ThemableMixin
52
51
  * @private
53
52
  */
54
53
  class DatePickerYearScroller extends InfiniteScroller {
@@ -56,22 +55,11 @@ class DatePickerYearScroller extends InfiniteScroller {
56
55
  return 'vaadin-date-picker-year-scroller';
57
56
  }
58
57
 
59
- static get template() {
60
- if (!memoizedTemplate) {
61
- memoizedTemplate = super.template.cloneNode(true);
62
- memoizedTemplate.content.appendChild(stylesTemplate.content.cloneNode(true));
63
- }
64
-
65
- return memoizedTemplate;
66
- }
58
+ constructor() {
59
+ super();
67
60
 
68
- static get properties() {
69
- return {
70
- bufferSize: {
71
- type: Number,
72
- value: 12,
73
- },
74
- };
61
+ this.bufferSize = 12;
62
+ this.shadowRoot.appendChild(stylesTemplate.content.cloneNode(true));
75
63
  }
76
64
 
77
65
  /**
@@ -101,4 +89,4 @@ class DatePickerYearScroller extends InfiniteScroller {
101
89
  }
102
90
  }
103
91
 
104
- customElements.define(DatePickerYearScroller.is, DatePickerYearScroller);
92
+ defineCustomElement(DatePickerYearScroller);
@@ -4,11 +4,13 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
+ import { defineCustomElement } from '@vaadin/component-base/src/define.js';
7
8
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
8
9
 
9
10
  /**
10
11
  * An element used internally by `<vaadin-date-picker>`. Not intended to be used separately.
11
12
  *
13
+ * @customElement
12
14
  * @extends HTMLElement
13
15
  * @mixes ThemableMixin
14
16
  * @private
@@ -54,4 +56,4 @@ export class DatePickerYear extends ThemableMixin(PolymerElement) {
54
56
  }
55
57
  }
56
58
 
57
- customElements.define(DatePickerYear.is, DatePickerYear);
59
+ defineCustomElement(DatePickerYear);
@@ -7,6 +7,7 @@ import '@vaadin/input-container/src/vaadin-input-container.js';
7
7
  import './vaadin-date-picker-overlay.js';
8
8
  import './vaadin-date-picker-overlay-content.js';
9
9
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
10
+ import { defineCustomElement } from '@vaadin/component-base/src/define.js';
10
11
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
11
12
  import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js';
12
13
  import { InputControlMixin } from '@vaadin/field-base/src/input-control-mixin.js';
@@ -15,8 +16,9 @@ import { LabelledInputController } from '@vaadin/field-base/src/labelled-input-c
15
16
  import { inputFieldShared } from '@vaadin/field-base/src/styles/input-field-shared-styles.js';
16
17
  import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
17
18
  import { DatePickerMixin } from './vaadin-date-picker-mixin.js';
19
+ import { datePickerStyles } from './vaadin-date-picker-styles.js';
18
20
 
19
- registerStyles('vaadin-date-picker', inputFieldShared, { moduleId: 'vaadin-date-picker-styles' });
21
+ registerStyles('vaadin-date-picker', [inputFieldShared, datePickerStyles], { moduleId: 'vaadin-date-picker-styles' });
20
22
 
21
23
  /**
22
24
  * `<vaadin-date-picker>` is an input field that allows to enter a date by typing or by selecting from a calendar overlay.
@@ -122,6 +124,7 @@ registerStyles('vaadin-date-picker', inputFieldShared, { moduleId: 'vaadin-date-
122
124
  * @fires {CustomEvent} value-changed - Fired when the `value` property changes.
123
125
  * @fires {CustomEvent} validated - Fired whenever the field is validated.
124
126
  *
127
+ * @customElement
125
128
  * @extends HTMLElement
126
129
  * @mixes ElementMixin
127
130
  * @mixes ThemableMixin
@@ -135,21 +138,6 @@ class DatePicker extends DatePickerMixin(InputControlMixin(ThemableMixin(Element
135
138
 
136
139
  static get template() {
137
140
  return html`
138
- <style>
139
- :host([opened]) {
140
- pointer-events: auto;
141
- }
142
-
143
- :host([dir='rtl']) [part='input-field'] {
144
- direction: ltr;
145
- }
146
-
147
- :host([dir='rtl']) [part='input-field'] ::slotted(input)::placeholder {
148
- direction: rtl;
149
- text-align: left;
150
- }
151
- </style>
152
-
153
141
  <div class="vaadin-date-picker-container">
154
142
  <div part="label">
155
143
  <slot name="label"></slot>
@@ -220,6 +208,7 @@ class DatePicker extends DatePickerMixin(InputControlMixin(ThemableMixin(Element
220
208
  this._tooltipController = new TooltipController(this);
221
209
  this.addController(this._tooltipController);
222
210
  this._tooltipController.setPosition('top');
211
+ this._tooltipController.setAriaTarget(this.inputElement);
223
212
  this._tooltipController.setShouldShow((target) => !target.opened);
224
213
 
225
214
  const toggleButton = this.shadowRoot.querySelector('[part="toggle-button"]');
@@ -255,6 +244,6 @@ class DatePicker extends DatePickerMixin(InputControlMixin(ThemableMixin(Element
255
244
  }
256
245
  }
257
246
 
258
- customElements.define(DatePicker.is, DatePicker);
247
+ defineCustomElement(DatePicker);
259
248
 
260
249
  export { DatePicker };
@@ -3,119 +3,118 @@
3
3
  * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { afterNextRender } from '@polymer/polymer/lib/utils/render-status.js';
7
- import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
8
6
  import { timeOut } from '@vaadin/component-base/src/async.js';
9
7
  import { isFirefox } from '@vaadin/component-base/src/browser-utils.js';
10
8
  import { Debouncer } from '@vaadin/component-base/src/debounce.js';
11
9
  import { generateUniqueId } from '@vaadin/component-base/src/unique-id-utils.js';
12
10
 
13
- /**
14
- * @extends HTMLElement
15
- * @private
16
- */
17
- export class InfiniteScroller extends PolymerElement {
18
- static get template() {
19
- return html`
20
- <style>
21
- :host {
22
- display: block;
23
- overflow: hidden;
24
- height: 500px;
25
- }
26
-
27
- #scroller {
28
- position: relative;
29
- height: 100%;
30
- overflow: auto;
31
- outline: none;
32
- margin-right: -40px;
33
- -webkit-overflow-scrolling: touch;
34
- overflow-x: hidden;
35
- }
11
+ const template = document.createElement('template');
12
+ template.innerHTML = `
13
+ <style>
14
+ :host {
15
+ display: block;
16
+ overflow: hidden;
17
+ height: 500px;
18
+ }
36
19
 
37
- #scroller.notouchscroll {
38
- -webkit-overflow-scrolling: auto;
39
- }
20
+ #scroller {
21
+ position: relative;
22
+ height: 100%;
23
+ overflow: auto;
24
+ outline: none;
25
+ margin-right: -40px;
26
+ -webkit-overflow-scrolling: touch;
27
+ overflow-x: hidden;
28
+ }
40
29
 
41
- #scroller::-webkit-scrollbar {
42
- display: none;
43
- }
30
+ #scroller.notouchscroll {
31
+ -webkit-overflow-scrolling: auto;
32
+ }
44
33
 
45
- .buffer {
46
- position: absolute;
47
- width: var(--vaadin-infinite-scroller-buffer-width, 100%);
48
- box-sizing: border-box;
49
- padding-right: 40px;
50
- top: var(--vaadin-infinite-scroller-buffer-offset, 0);
51
- animation: fadein 0.2s;
52
- }
34
+ #scroller::-webkit-scrollbar {
35
+ display: none;
36
+ }
53
37
 
54
- @keyframes fadein {
55
- from {
56
- opacity: 0;
57
- }
58
- to {
59
- opacity: 1;
60
- }
61
- }
62
- </style>
63
-
64
- <div id="scroller" on-scroll="_scroll">
65
- <div class="buffer"></div>
66
- <div class="buffer"></div>
67
- <div id="fullHeight"></div>
68
- </div>
69
- `;
70
- }
38
+ .buffer {
39
+ position: absolute;
40
+ width: var(--vaadin-infinite-scroller-buffer-width, 100%);
41
+ box-sizing: border-box;
42
+ padding-right: 40px;
43
+ top: var(--vaadin-infinite-scroller-buffer-offset, 0);
44
+ animation: fadein 0.2s;
45
+ }
71
46
 
72
- static get properties() {
73
- return {
74
- /**
75
- * Count of individual items in each buffer.
76
- * The scroller has 2 buffers altogether so bufferSize of 20
77
- * will result in 40 buffered DOM items in total.
78
- * Changing after initialization not supported.
79
- */
80
- bufferSize: {
81
- type: Number,
82
- value: 20,
83
- },
84
-
85
- /**
86
- * The amount of initial scroll top. Needed in order for the
87
- * user to be able to scroll backwards.
88
- * @private
89
- */
90
- _initialScroll: {
91
- value: 500000,
92
- },
93
-
94
- /**
95
- * The index/position mapped at _initialScroll point.
96
- * @private
97
- */
98
- _initialIndex: {
99
- value: 0,
100
- },
47
+ @keyframes fadein {
48
+ from {
49
+ opacity: 0;
50
+ }
51
+ to {
52
+ opacity: 1;
53
+ }
54
+ }
55
+ </style>
101
56
 
102
- /** @private */
103
- _buffers: Array,
57
+ <div id="scroller">
58
+ <div class="buffer"></div>
59
+ <div class="buffer"></div>
60
+ <div id="fullHeight"></div>
61
+ </div>
62
+ `;
104
63
 
105
- /** @private */
106
- _preventScrollEvent: Boolean,
107
-
108
- /** @private */
109
- _mayHaveMomentum: Boolean,
64
+ /**
65
+ * @extends HTMLElement
66
+ * @private
67
+ */
68
+ export class InfiniteScroller extends HTMLElement {
69
+ constructor() {
70
+ super();
71
+
72
+ const root = this.attachShadow({ mode: 'open' });
73
+ root.appendChild(template.content.cloneNode(true));
74
+
75
+ /**
76
+ * Count of individual items in each buffer.
77
+ * The scroller has 2 buffers altogether so bufferSize of 20
78
+ * will result in 40 buffered DOM items in total.
79
+ * Changing after initialization not supported.
80
+ * @type {number}
81
+ */
82
+ this.bufferSize = 20;
83
+
84
+ /**
85
+ * The amount of initial scroll top. Needed in order for the
86
+ * user to be able to scroll backwards.
87
+ * @type {number}
88
+ * @private
89
+ */
90
+ this._initialScroll = 500000;
91
+
92
+ /**
93
+ * The index/position mapped at _initialScroll point.
94
+ * @type {number}
95
+ * @private
96
+ */
97
+ this._initialIndex = 0;
98
+
99
+ /**
100
+ * @type {boolean}
101
+ * @private
102
+ */
103
+ this._activated = false;
104
+ }
110
105
 
111
- /** @private */
112
- _initialized: Boolean,
106
+ /**
107
+ * @return {boolean}
108
+ */
109
+ get active() {
110
+ return this._activated;
111
+ }
113
112
 
114
- active: {
115
- type: Boolean,
116
- observer: '_activated',
117
- },
118
- };
113
+ set active(active) {
114
+ if (active && !this._activated) {
115
+ this._createPool();
116
+ this._activated = true;
117
+ }
119
118
  }
120
119
 
121
120
  /**
@@ -184,17 +183,27 @@ export class InfiniteScroller extends PolymerElement {
184
183
  }
185
184
 
186
185
  /** @protected */
187
- ready() {
188
- super.ready();
186
+ connectedCallback() {
187
+ if (!this._ready) {
188
+ this._ready = true;
189
+
190
+ this.$ = {};
191
+ this.shadowRoot.querySelectorAll('[id]').forEach((node) => {
192
+ this.$[node.id] = node;
193
+ });
189
194
 
190
- this._buffers = [...this.shadowRoot.querySelectorAll('.buffer')];
195
+ this.$.scroller.addEventListener('scroll', () => this._scroll());
191
196
 
192
- this.$.fullHeight.style.height = `${this._initialScroll * 2}px`;
197
+ /** @private */
198
+ this._buffers = [...this.shadowRoot.querySelectorAll('.buffer')];
199
+
200
+ this.$.fullHeight.style.height = `${this._initialScroll * 2}px`;
193
201
 
194
- // Firefox interprets elements with overflow:auto as focusable
195
- // https://bugzilla.mozilla.org/show_bug.cgi?id=1069739
196
- if (isFirefox) {
197
- this.$.scroller.tabIndex = -1;
202
+ // Firefox interprets elements with overflow:auto as focusable
203
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1069739
204
+ if (isFirefox) {
205
+ this.$.scroller.tabIndex = -1;
206
+ }
198
207
  }
199
208
  }
200
209
 
@@ -228,14 +237,6 @@ export class InfiniteScroller extends PolymerElement {
228
237
  // To be implemented.
229
238
  }
230
239
 
231
- /** @private */
232
- _activated(active) {
233
- if (active && !this._initialized) {
234
- this._createPool();
235
- this._initialized = true;
236
- }
237
- }
238
-
239
240
  /** @private */
240
241
  _finishInit() {
241
242
  if (!this._initDone) {
@@ -347,7 +348,7 @@ export class InfiniteScroller extends PolymerElement {
347
348
  }
348
349
  });
349
350
 
350
- afterNextRender(this, () => {
351
+ requestAnimationFrame(() => {
351
352
  this._finishInit();
352
353
  });
353
354
  }
@@ -364,7 +365,7 @@ export class InfiniteScroller extends PolymerElement {
364
365
  itemWrapper.appendChild(itemWrapper.instance);
365
366
 
366
367
  Object.keys(tmpInstance).forEach((prop) => {
367
- itemWrapper.instance.set(prop, tmpInstance[prop]);
368
+ itemWrapper.instance[prop] = tmpInstance[prop];
368
369
  });
369
370
  }
370
371