@vaadin/date-picker 24.8.4 → 25.0.0-alpha10

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 (63) hide show
  1. package/README.md +0 -23
  2. package/package.json +15 -15
  3. package/src/styles/vaadin-date-picker-base-styles.d.ts +8 -0
  4. package/src/styles/vaadin-date-picker-base-styles.js +30 -0
  5. package/src/styles/vaadin-date-picker-core-styles.d.ts +8 -0
  6. package/src/styles/vaadin-date-picker-overlay-base-styles.js +48 -0
  7. package/src/styles/vaadin-date-picker-overlay-content-base-styles.js +107 -0
  8. package/src/styles/vaadin-date-picker-overlay-content-core-styles.js +54 -0
  9. package/src/styles/vaadin-date-picker-year-base-styles.js +26 -0
  10. package/src/styles/vaadin-date-picker-year-core-styles.js +13 -0
  11. package/src/styles/vaadin-month-calendar-base-styles.js +140 -0
  12. package/src/vaadin-date-picker-helper.d.ts +5 -0
  13. package/src/vaadin-date-picker-mixin.js +34 -45
  14. package/src/vaadin-date-picker-month-scroller.js +2 -6
  15. package/src/vaadin-date-picker-overlay-content-mixin.js +5 -135
  16. package/src/vaadin-date-picker-overlay-content.js +28 -31
  17. package/src/vaadin-date-picker-overlay.js +27 -11
  18. package/src/vaadin-date-picker-year-scroller.js +3 -4
  19. package/src/vaadin-date-picker-year.js +39 -11
  20. package/src/vaadin-date-picker.d.ts +11 -14
  21. package/src/vaadin-date-picker.js +73 -54
  22. package/src/vaadin-infinite-scroller.js +1 -22
  23. package/src/vaadin-month-calendar.js +69 -47
  24. package/theme/lumo/vaadin-date-picker-overlay-content-styles.js +19 -46
  25. package/theme/lumo/vaadin-date-picker-overlay-styles.js +0 -1
  26. package/web-types.json +2 -369
  27. package/web-types.lit.json +2 -156
  28. package/src/vaadin-date-picker-light.d.ts +0 -112
  29. package/src/vaadin-date-picker-light.js +0 -136
  30. package/src/vaadin-date-picker-overlay-content-styles.js +0 -68
  31. package/src/vaadin-date-picker-year-mixin.js +0 -35
  32. package/src/vaadin-lit-date-picker-overlay-content.js +0 -70
  33. package/src/vaadin-lit-date-picker-overlay.js +0 -46
  34. package/src/vaadin-lit-date-picker-year.js +0 -41
  35. package/src/vaadin-lit-date-picker.js +0 -172
  36. package/src/vaadin-lit-month-calendar.js +0 -98
  37. package/theme/lumo/vaadin-date-picker-light.d.ts +0 -4
  38. package/theme/lumo/vaadin-date-picker-light.js +0 -4
  39. package/theme/lumo/vaadin-lit-date-picker.d.ts +0 -5
  40. package/theme/lumo/vaadin-lit-date-picker.js +0 -5
  41. package/theme/material/vaadin-date-picker-light.d.ts +0 -4
  42. package/theme/material/vaadin-date-picker-light.js +0 -4
  43. package/theme/material/vaadin-date-picker-overlay-content-styles.d.ts +0 -6
  44. package/theme/material/vaadin-date-picker-overlay-content-styles.js +0 -132
  45. package/theme/material/vaadin-date-picker-overlay-styles.d.ts +0 -1
  46. package/theme/material/vaadin-date-picker-overlay-styles.js +0 -47
  47. package/theme/material/vaadin-date-picker-styles.d.ts +0 -3
  48. package/theme/material/vaadin-date-picker-styles.js +0 -22
  49. package/theme/material/vaadin-date-picker-year-styles.d.ts +0 -1
  50. package/theme/material/vaadin-date-picker-year-styles.js +0 -28
  51. package/theme/material/vaadin-date-picker.d.ts +0 -5
  52. package/theme/material/vaadin-date-picker.js +0 -5
  53. package/theme/material/vaadin-lit-date-picker.d.ts +0 -5
  54. package/theme/material/vaadin-lit-date-picker.js +0 -5
  55. package/theme/material/vaadin-month-calendar-styles.d.ts +0 -2
  56. package/theme/material/vaadin-month-calendar-styles.js +0 -120
  57. package/vaadin-date-picker-light.d.ts +0 -1
  58. package/vaadin-date-picker-light.js +0 -2
  59. package/vaadin-lit-date-picker.d.ts +0 -1
  60. package/vaadin-lit-date-picker.js +0 -2
  61. /package/src/{vaadin-date-picker-styles.js → styles/vaadin-date-picker-core-styles.js} +0 -0
  62. /package/src/{vaadin-date-picker-overlay-styles.js → styles/vaadin-date-picker-overlay-core-styles.js} +0 -0
  63. /package/src/{vaadin-month-calendar-styles.js → styles/vaadin-month-calendar-core-styles.js} +0 -0
@@ -1,112 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { ValidateMixin } from '@vaadin/field-base/src/validate-mixin.js';
7
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
8
- import { DatePickerMixin } from './vaadin-date-picker-mixin.js';
9
- export { DatePickerDate, DatePickerI18n } from './vaadin-date-picker-mixin.js';
10
-
11
- /**
12
- * Fired when the user commits a value change.
13
- */
14
- export type DatePickerLightChangeEvent = Event & {
15
- target: DatePickerLight;
16
- };
17
-
18
- /**
19
- * Fired when the `opened` property changes.
20
- */
21
- export type DatePickerLightOpenedChangedEvent = CustomEvent<{ value: boolean }>;
22
-
23
- /**
24
- * Fired when the `invalid` property changes.
25
- */
26
- export type DatePickerLightInvalidChangedEvent = CustomEvent<{ value: boolean }>;
27
-
28
- /**
29
- * Fired when the `value` property changes.
30
- */
31
- export type DatePickerLightValueChangedEvent = CustomEvent<{ value: string }>;
32
-
33
- /**
34
- * Fired whenever the field is validated.
35
- */
36
- export type DatePickerLightValidatedEvent = CustomEvent<{ valid: boolean }>;
37
-
38
- export interface DatePickerLightCustomEventMap {
39
- 'opened-changed': DatePickerLightOpenedChangedEvent;
40
-
41
- 'invalid-changed': DatePickerLightInvalidChangedEvent;
42
-
43
- 'value-changed': DatePickerLightValueChangedEvent;
44
-
45
- validated: DatePickerLightValidatedEvent;
46
- }
47
-
48
- export interface DatePickerLightEventMap extends HTMLElementEventMap, DatePickerLightCustomEventMap {
49
- change: DatePickerLightChangeEvent;
50
- }
51
-
52
- /**
53
- * `<vaadin-date-picker-light>` is a customizable version of the `<vaadin-date-picker>` providing
54
- * only the scrollable month calendar view and leaving the input field definition to the user.
55
- *
56
- * To create a custom input field, you need to add a child element which has a two-way
57
- * data-bindable property representing the input value. The property name is expected
58
- * to be `bindValue` by default. See the example below for a simplest possible example
59
- * using an `<input>` element.
60
- *
61
- * ```html
62
- * <vaadin-date-picker-light attr-for-value="value">
63
- * <input class="input">
64
- * </vaadin-date-picker-light>
65
- * ```
66
- *
67
- * ### Styling
68
- *
69
- * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
70
- *
71
- * In addition to `<vaadin-date-picker-light>` itself, the following
72
- * internal components are themable:
73
- *
74
- * - `<vaadin-date-picker-overlay>`
75
- * - `<vaadin-date-picker-overlay-content>`
76
- * - `<vaadin-month-calendar>`
77
- *
78
- * Note: the `theme` attribute value set on `<vaadin-date-picker-light>`
79
- * is propagated to the internal themable components listed above.
80
- *
81
- * @fires {Event} change - Fired when the user commits a value change.
82
- * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
83
- * @fires {CustomEvent} value-changed - Fired when the `value` property changes.
84
- * @fires {CustomEvent} validated - Fired whenever the field is validated.
85
- */
86
- declare class DatePickerLight extends ThemableMixin(DatePickerMixin(ValidateMixin(HTMLElement))) {
87
- /**
88
- * Name of the two-way data-bindable property representing the
89
- * value of the custom input field.
90
- */
91
- attrForValue: string;
92
-
93
- addEventListener<K extends keyof DatePickerLightEventMap>(
94
- type: K,
95
- listener: (this: DatePickerLight, ev: DatePickerLightEventMap[K]) => void,
96
- options?: AddEventListenerOptions | boolean,
97
- ): void;
98
-
99
- removeEventListener<K extends keyof DatePickerLightEventMap>(
100
- type: K,
101
- listener: (this: DatePickerLight, ev: DatePickerLightEventMap[K]) => void,
102
- options?: EventListenerOptions | boolean,
103
- ): void;
104
- }
105
-
106
- declare global {
107
- interface HTMLElementTagNameMap {
108
- 'vaadin-date-picker-light': DatePickerLight;
109
- }
110
- }
111
-
112
- export { DatePickerLight };
@@ -1,136 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import './vaadin-date-picker-overlay-content.js';
7
- import './vaadin-date-picker-overlay.js';
8
- import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
9
- import { defineCustomElement } from '@vaadin/component-base/src/define.js';
10
- import { ValidateMixin } from '@vaadin/field-base/src/validate-mixin.js';
11
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
12
- import { DatePickerMixin } from './vaadin-date-picker-mixin.js';
13
-
14
- function dashToCamelCase(dash) {
15
- return dash.replace(/-[a-z]/gu, (m) => m[1].toUpperCase());
16
- }
17
-
18
- /**
19
- * `<vaadin-date-picker-light>` is a customizable version of the `<vaadin-date-picker>` providing
20
- * only the scrollable month calendar view and leaving the input field definition to the user.
21
- *
22
- * To create a custom input field, you need to add a child element which has a two-way
23
- * data-bindable property representing the input value. The property name is expected
24
- * to be `bindValue` by default. See the example below for a simplest possible example
25
- * using an `<input>` element.
26
- *
27
- * ```html
28
- * <vaadin-date-picker-light attr-for-value="value">
29
- * <input class="input">
30
- * </vaadin-date-picker-light>
31
- * ```
32
- *
33
- * ### Styling
34
- *
35
- * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
36
- *
37
- * In addition to `<vaadin-date-picker-light>` itself, the following
38
- * internal components are themable:
39
- *
40
- * - `<vaadin-date-picker-overlay>`
41
- * - `<vaadin-date-picker-overlay-content>`
42
- * - `<vaadin-month-calendar>`
43
- *
44
- * Note: the `theme` attribute value set on `<vaadin-date-picker-light>`
45
- * is propagated to the internal themable components listed above.
46
- *
47
- * @fires {Event} change - Fired when the user commits a value change.
48
- * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
49
- * @fires {CustomEvent} value-changed - Fired when the `value` property changes.
50
- * @fires {CustomEvent} validated - Fired whenever the field is validated.
51
- *
52
- * @customElement
53
- * @extends HTMLElement
54
- * @mixes ThemableMixin
55
- * @mixes DatePickerMixin
56
- */
57
- class DatePickerLight extends ThemableMixin(DatePickerMixin(ValidateMixin(PolymerElement))) {
58
- static get template() {
59
- return html`
60
- <style>
61
- :host {
62
- display: inline-block;
63
- }
64
-
65
- :host([opened]) {
66
- pointer-events: auto;
67
- }
68
- </style>
69
- <slot></slot>
70
-
71
- <vaadin-date-picker-overlay
72
- id="overlay"
73
- fullscreen$="[[_fullscreen]]"
74
- opened="{{opened}}"
75
- on-vaadin-overlay-escape-press="_onOverlayEscapePress"
76
- on-vaadin-overlay-open="_onOverlayOpened"
77
- on-vaadin-overlay-closing="_onOverlayClosed"
78
- restore-focus-on-close
79
- restore-focus-node="[[inputElement]]"
80
- theme$="[[_theme]]"
81
- ></vaadin-date-picker-overlay>
82
- `;
83
- }
84
-
85
- static get is() {
86
- return 'vaadin-date-picker-light';
87
- }
88
-
89
- static get properties() {
90
- return {
91
- /**
92
- * Name of the two-way data-bindable property representing the
93
- * value of the custom input field.
94
- * @attr {string} attr-for-value
95
- * @type {string}
96
- */
97
- attrForValue: {
98
- type: String,
99
- value: 'value',
100
- },
101
- };
102
- }
103
-
104
- /**
105
- * This method from InputMixin is overridden to make
106
- * the input element value property customizable.
107
- *
108
- * @protected
109
- * @override
110
- * @return {string}
111
- */
112
- get _inputElementValueProperty() {
113
- return dashToCamelCase(this.attrForValue);
114
- }
115
-
116
- /** @protected */
117
- connectedCallback() {
118
- super.connectedCallback();
119
- const cssSelector = 'vaadin-text-field,.input';
120
- this._setInputElement(this.querySelector(cssSelector));
121
- this._setFocusElement(this.inputElement);
122
- }
123
-
124
- // Workaround https://github.com/vaadin/web-components/issues/2855
125
- /** @protected */
126
- _openedChanged(opened) {
127
- super._openedChanged(opened);
128
-
129
- this.$.overlay.positionTarget = this.inputElement;
130
- this.$.overlay.noVerticalOverlap = true;
131
- }
132
- }
133
-
134
- defineCustomElement(DatePickerLight);
135
-
136
- export { DatePickerLight };
@@ -1,68 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2016 - 2025 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 overlayContentStyles = css`
9
- :host {
10
- display: flex;
11
- flex-direction: column;
12
- height: 100%;
13
- width: 100%;
14
- outline: none;
15
- }
16
-
17
- [part='overlay-header'] {
18
- display: flex;
19
- flex-shrink: 0;
20
- flex-wrap: nowrap;
21
- align-items: center;
22
- }
23
-
24
- :host(:not([fullscreen])) [part='overlay-header'] {
25
- display: none;
26
- }
27
-
28
- [part='label'] {
29
- flex-grow: 1;
30
- }
31
-
32
- [hidden] {
33
- display: none !important;
34
- }
35
-
36
- [part='years-toggle-button'] {
37
- display: flex;
38
- }
39
-
40
- #scrollers {
41
- display: flex;
42
- height: 100%;
43
- width: 100%;
44
- position: relative;
45
- overflow: hidden;
46
- }
47
-
48
- :host([desktop]) ::slotted([slot='months']) {
49
- right: 50px;
50
- transform: none !important;
51
- }
52
-
53
- :host([desktop]) ::slotted([slot='years']) {
54
- transform: none !important;
55
- }
56
-
57
- :host(.animate) ::slotted([slot='months']),
58
- :host(.animate) ::slotted([slot='years']) {
59
- transition: all 200ms;
60
- }
61
-
62
- [part='toolbar'] {
63
- display: flex;
64
- justify-content: space-between;
65
- z-index: 2;
66
- flex-shrink: 0;
67
- }
68
- `;
@@ -1,35 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
-
7
- /**
8
- * @polymerMixin
9
- */
10
- export const DatePickerYearMixin = (superClass) =>
11
- class DatePickerYearMixin extends superClass {
12
- static get properties() {
13
- return {
14
- year: {
15
- type: String,
16
- sync: true,
17
- },
18
-
19
- selectedDate: {
20
- type: Object,
21
- sync: true,
22
- },
23
- };
24
- }
25
-
26
- static get observers() {
27
- return ['__updateSelected(year, selectedDate)'];
28
- }
29
-
30
- /** @private */
31
- __updateSelected(year, selectedDate) {
32
- this.toggleAttribute('selected', selectedDate && selectedDate.getFullYear() === year);
33
- this.toggleAttribute('current', year === new Date().getFullYear());
34
- }
35
- };
@@ -1,70 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import '@vaadin/button/src/vaadin-lit-button.js';
7
- import './vaadin-date-picker-month-scroller.js';
8
- import './vaadin-date-picker-year-scroller.js';
9
- import './vaadin-lit-date-picker-year.js';
10
- import './vaadin-lit-month-calendar.js';
11
- import { html, LitElement } from 'lit';
12
- import { defineCustomElement } from '@vaadin/component-base/src/define.js';
13
- import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
14
- import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
15
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
16
- import { DatePickerOverlayContentMixin } from './vaadin-date-picker-overlay-content-mixin.js';
17
- import { overlayContentStyles } from './vaadin-date-picker-overlay-content-styles.js';
18
-
19
- /**
20
- * @extends HTMLElement
21
- * @private
22
- */
23
- class DatePickerOverlayContent extends DatePickerOverlayContentMixin(
24
- ThemableMixin(DirMixin(PolylitMixin(LitElement))),
25
- ) {
26
- static get is() {
27
- return 'vaadin-date-picker-overlay-content';
28
- }
29
-
30
- static get styles() {
31
- return overlayContentStyles;
32
- }
33
-
34
- /** @protected */
35
- render() {
36
- return html`
37
- <div part="overlay-header" @touchend="${this._preventDefault}" aria-hidden="true">
38
- <div part="label">${this._formatDisplayed(this.selectedDate, this.i18n, this.label)}</div>
39
- <div part="clear-button" ?hidden="${!this.selectedDate}"></div>
40
- <div part="toggle-button"></div>
41
-
42
- <div part="years-toggle-button" ?hidden="${this._desktopMode}" aria-hidden="true">
43
- ${this._yearAfterXMonths(this._visibleMonthIndex)}
44
- </div>
45
- </div>
46
-
47
- <div id="scrollers">
48
- <slot name="months"></slot>
49
- <slot name="years"></slot>
50
- </div>
51
-
52
- <div @touchend="${this._preventDefault}" role="toolbar" part="toolbar">
53
- <slot name="today-button"></slot>
54
- <slot name="cancel-button"></slot>
55
- </div>
56
- `;
57
- }
58
-
59
- /** @protected */
60
- firstUpdated() {
61
- super.firstUpdated();
62
-
63
- this.setAttribute('role', 'dialog');
64
-
65
- this._addListeners();
66
- this._initControllers();
67
- }
68
- }
69
-
70
- defineCustomElement(DatePickerOverlayContent);
@@ -1,46 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { html, LitElement } from 'lit';
7
- import { defineCustomElement } from '@vaadin/component-base/src/define.js';
8
- import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
9
- import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
10
- import { overlayStyles } from '@vaadin/overlay/src/vaadin-overlay-styles.js';
11
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
12
- import { DatePickerOverlayMixin } from './vaadin-date-picker-overlay-mixin.js';
13
- import { datePickerOverlayStyles } from './vaadin-date-picker-overlay-styles.js';
14
-
15
- /**
16
- * An element used internally by `<vaadin-date-picker>`. Not intended to be used separately.
17
- *
18
- * @extends HTMLElement
19
- * @mixes DatePickerOverlayMixin
20
- * @mixes DirMixin
21
- * @mixes ThemableMixin
22
- * @private
23
- */
24
- class DatePickerOverlay extends DatePickerOverlayMixin(DirMixin(ThemableMixin(PolylitMixin(LitElement)))) {
25
- static get is() {
26
- return 'vaadin-date-picker-overlay';
27
- }
28
-
29
- static get styles() {
30
- return [overlayStyles, datePickerOverlayStyles];
31
- }
32
-
33
- /** @protected */
34
- render() {
35
- return html`
36
- <div id="backdrop" part="backdrop" ?hidden="${!this.withBackdrop}"></div>
37
- <div part="overlay" id="overlay">
38
- <div part="content" id="content">
39
- <slot></slot>
40
- </div>
41
- </div>
42
- `;
43
- }
44
- }
45
-
46
- defineCustomElement(DatePickerOverlay);
@@ -1,41 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { css, html, LitElement } from 'lit';
7
- import { defineCustomElement } from '@vaadin/component-base/src/define.js';
8
- import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
9
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
- import { DatePickerYearMixin } from './vaadin-date-picker-year-mixin.js';
11
-
12
- /**
13
- * @extends HTMLElement
14
- * @mixes ThemableMixin
15
- * @mixes DatePickerYearMixin
16
- * @private
17
- */
18
- export class DatePickerYear extends ThemableMixin(DatePickerYearMixin(PolylitMixin(LitElement))) {
19
- static get is() {
20
- return 'vaadin-date-picker-year';
21
- }
22
-
23
- static get styles() {
24
- return css`
25
- :host {
26
- display: block;
27
- height: 100%;
28
- }
29
- `;
30
- }
31
-
32
- /** @protected */
33
- render() {
34
- return html`
35
- <div part="year-number">${this.year}</div>
36
- <div part="year-separator" aria-hidden="true"></div>
37
- `;
38
- }
39
- }
40
-
41
- defineCustomElement(DatePickerYear);
@@ -1,172 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import '@vaadin/input-container/src/vaadin-lit-input-container.js';
7
- import './vaadin-lit-date-picker-overlay.js';
8
- import './vaadin-lit-date-picker-overlay-content.js';
9
- import { html, LitElement } from 'lit';
10
- import { ifDefined } from 'lit/directives/if-defined.js';
11
- import { defineCustomElement } from '@vaadin/component-base/src/define.js';
12
- import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
13
- import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
14
- import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js';
15
- import { InputControlMixin } from '@vaadin/field-base/src/input-control-mixin.js';
16
- import { InputController } from '@vaadin/field-base/src/input-controller.js';
17
- import { LabelledInputController } from '@vaadin/field-base/src/labelled-input-controller.js';
18
- import { inputFieldShared } from '@vaadin/field-base/src/styles/input-field-shared-styles.js';
19
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
20
- import { DatePickerMixin } from './vaadin-date-picker-mixin.js';
21
- import { datePickerStyles } from './vaadin-date-picker-styles.js';
22
-
23
- /**
24
- * LitElement based version of `<vaadin-date-picker>` web component.
25
- *
26
- * ## Disclaimer
27
- *
28
- * This component is an experiment and not yet a part of Vaadin platform.
29
- * There is no ETA regarding specific Vaadin version where it'll land.
30
- * Feel free to try this code in your apps as per Apache 2.0 license.
31
- */
32
- class DatePicker extends DatePickerMixin(InputControlMixin(ThemableMixin(ElementMixin(PolylitMixin(LitElement))))) {
33
- static get is() {
34
- return 'vaadin-date-picker';
35
- }
36
-
37
- static get styles() {
38
- return [inputFieldShared, datePickerStyles];
39
- }
40
-
41
- static get properties() {
42
- return {
43
- /** @private */
44
- _positionTarget: {
45
- type: Object,
46
- sync: true,
47
- },
48
- };
49
- }
50
-
51
- /**
52
- * Used by `InputControlMixin` as a reference to the clear button element.
53
- * @protected
54
- * @return {!HTMLElement}
55
- */
56
- get clearElement() {
57
- return this.$.clearButton;
58
- }
59
-
60
- /** @protected */
61
- render() {
62
- return html`
63
- <div class="vaadin-date-picker-container">
64
- <div part="label">
65
- <slot name="label"></slot>
66
- <span part="required-indicator" aria-hidden="true" @click="${this.focus}"></span>
67
- </div>
68
-
69
- <vaadin-input-container
70
- part="input-field"
71
- .readonly="${this.readonly}"
72
- .disabled="${this.disabled}"
73
- .invalid="${this.invalid}"
74
- theme="${ifDefined(this._theme)}"
75
- >
76
- <slot name="prefix" slot="prefix"></slot>
77
- <slot name="input"></slot>
78
- <div id="clearButton" part="clear-button" slot="suffix" aria-hidden="true"></div>
79
- <div part="toggle-button" slot="suffix" aria-hidden="true" @click="${this._toggle}"></div>
80
- </vaadin-input-container>
81
-
82
- <div part="helper-text">
83
- <slot name="helper"></slot>
84
- </div>
85
-
86
- <div part="error-message">
87
- <slot name="error-message"></slot>
88
- </div>
89
- </div>
90
-
91
- <vaadin-date-picker-overlay
92
- id="overlay"
93
- ?fullscreen="${this._fullscreen}"
94
- theme="${ifDefined(this._theme)}"
95
- .opened="${this.opened}"
96
- @opened-changed="${this._onOpenedChanged}"
97
- @vaadin-overlay-escape-press="${this._onOverlayEscapePress}"
98
- @vaadin-overlay-open="${this._onOverlayOpened}"
99
- @vaadin-overlay-close="${this._onVaadinOverlayClose}"
100
- @vaadin-overlay-closing="${this._onOverlayClosed}"
101
- restore-focus-on-close
102
- no-vertical-overlap
103
- .restoreFocusNode="${this.inputElement}"
104
- .positionTarget="${this._positionTarget}"
105
- ></vaadin-date-picker-overlay>
106
-
107
- <slot name="tooltip"></slot>
108
- `;
109
- }
110
-
111
- /** @protected */
112
- ready() {
113
- super.ready();
114
-
115
- this.addController(
116
- new InputController(
117
- this,
118
- (input) => {
119
- this._setInputElement(input);
120
- this._setFocusElement(input);
121
- this.stateTarget = input;
122
- this.ariaTarget = input;
123
- },
124
- {
125
- // The "search" word is a trick to prevent Safari from enabling AutoFill,
126
- // which is causing click issues:
127
- // https://github.com/vaadin/web-components/issues/6817#issuecomment-2268229567
128
- uniqueIdPrefix: 'search-input',
129
- },
130
- ),
131
- );
132
- this.addController(new LabelledInputController(this.inputElement, this._labelController));
133
-
134
- this._tooltipController = new TooltipController(this);
135
- this.addController(this._tooltipController);
136
- this._tooltipController.setPosition('top');
137
- this._tooltipController.setAriaTarget(this.inputElement);
138
- this._tooltipController.setShouldShow((target) => !target.opened);
139
-
140
- this._positionTarget = this.shadowRoot.querySelector('[part="input-field"]');
141
-
142
- const toggleButton = this.shadowRoot.querySelector('[part="toggle-button"]');
143
- toggleButton.addEventListener('mousedown', (e) => e.preventDefault());
144
- }
145
-
146
- /** @private */
147
- _onOpenedChanged(event) {
148
- this.opened = event.detail.value;
149
- }
150
-
151
- /** @private */
152
- _onVaadinOverlayClose(e) {
153
- // Prevent closing the overlay on label element click
154
- if (e.detail.sourceEvent && e.detail.sourceEvent.composedPath().includes(this)) {
155
- e.preventDefault();
156
- }
157
- }
158
-
159
- /** @private */
160
- _toggle(e) {
161
- e.stopPropagation();
162
- if (this.$.overlay.opened) {
163
- this.close();
164
- } else {
165
- this.open();
166
- }
167
- }
168
- }
169
-
170
- defineCustomElement(DatePicker);
171
-
172
- export { DatePicker };