@vaadin/date-picker 24.4.0-dev.223e39f050 → 24.4.0-dev.4b20a0c55.3

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 CHANGED
@@ -5,7 +5,6 @@ A web component that allows to enter a date by typing or by selecting from a cal
5
5
  [Documentation + Live Demo ↗](https://vaadin.com/docs/latest/components/date-picker)
6
6
 
7
7
  [![npm version](https://badgen.net/npm/v/@vaadin/date-picker)](https://www.npmjs.com/package/@vaadin/date-picker)
8
- [![Discord](https://img.shields.io/discord/732335336448852018?label=discord)](https://discord.gg/PHmkCKC)
9
8
 
10
9
  ```html
11
10
  <vaadin-date-picker label="Label" value="2018-12-03" clear-button-visible></vaadin-date-picker>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/date-picker",
3
- "version": "24.4.0-dev.223e39f050",
3
+ "version": "24.4.0-dev.4b20a0c55.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,15 +36,15 @@
36
36
  "dependencies": {
37
37
  "@open-wc/dedupe-mixin": "^1.3.0",
38
38
  "@polymer/polymer": "^3.2.0",
39
- "@vaadin/a11y-base": "24.4.0-dev.223e39f050",
40
- "@vaadin/button": "24.4.0-dev.223e39f050",
41
- "@vaadin/component-base": "24.4.0-dev.223e39f050",
42
- "@vaadin/field-base": "24.4.0-dev.223e39f050",
43
- "@vaadin/input-container": "24.4.0-dev.223e39f050",
44
- "@vaadin/overlay": "24.4.0-dev.223e39f050",
45
- "@vaadin/vaadin-lumo-styles": "24.4.0-dev.223e39f050",
46
- "@vaadin/vaadin-material-styles": "24.4.0-dev.223e39f050",
47
- "@vaadin/vaadin-themable-mixin": "24.4.0-dev.223e39f050",
39
+ "@vaadin/a11y-base": "24.4.0-dev.4b20a0c55.3",
40
+ "@vaadin/button": "24.4.0-dev.4b20a0c55.3",
41
+ "@vaadin/component-base": "24.4.0-dev.4b20a0c55.3",
42
+ "@vaadin/field-base": "24.4.0-dev.4b20a0c55.3",
43
+ "@vaadin/input-container": "24.4.0-dev.4b20a0c55.3",
44
+ "@vaadin/overlay": "24.4.0-dev.4b20a0c55.3",
45
+ "@vaadin/vaadin-lumo-styles": "24.4.0-dev.4b20a0c55.3",
46
+ "@vaadin/vaadin-material-styles": "24.4.0-dev.4b20a0c55.3",
47
+ "@vaadin/vaadin-themable-mixin": "24.4.0-dev.4b20a0c55.3",
48
48
  "lit": "^3.0.0"
49
49
  },
50
50
  "devDependencies": {
@@ -56,5 +56,5 @@
56
56
  "web-types.json",
57
57
  "web-types.lit.json"
58
58
  ],
59
- "gitHead": "5e2e3bfc811c95aed9354235fab93fdbf43eb354"
59
+ "gitHead": "41cf17453d7506fb635c088a0425e20b6e82b89b"
60
60
  }
@@ -17,7 +17,12 @@ declare function dateEquals(date1: Date | null, date2: Date | null): boolean;
17
17
  *
18
18
  * @returns True if the date is in the range
19
19
  */
20
- declare function dateAllowed(date: Date, min: Date | null, max: Date | null): boolean;
20
+ declare function dateAllowed(
21
+ date: Date,
22
+ min: Date | null,
23
+ max: Date | null,
24
+ isDateDisabled: (DatePickerDate) => boolean | null,
25
+ ): boolean;
21
26
 
22
27
  /**
23
28
  * Get closest date from array of dates.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
@@ -53,16 +53,37 @@ export function dateEquals(date1, date2) {
53
53
  );
54
54
  }
55
55
 
56
+ /**
57
+ * Extracts the basic component parts of a date (day, month and year)
58
+ * to the expected format.
59
+ * @param {!Date} date
60
+ * @return {{day: number, month: number, year: number}}
61
+ */
62
+ export function extractDateParts(date) {
63
+ return {
64
+ day: date.getDate(),
65
+ month: date.getMonth(),
66
+ year: date.getFullYear(),
67
+ };
68
+ }
69
+
56
70
  /**
57
71
  * Check if the given date is in the range of allowed dates.
58
72
  *
59
73
  * @param {!Date} date The date to check
60
74
  * @param {Date} min Range start
61
75
  * @param {Date} max Range end
76
+ * @param {function(!DatePickerDate): boolean} isDateDisabled Callback to check if the date is disabled
62
77
  * @return {boolean} True if the date is in the range
63
78
  */
64
- export function dateAllowed(date, min, max) {
65
- return (!min || date >= min) && (!max || date <= max);
79
+ export function dateAllowed(date, min, max, isDateDisabled) {
80
+ let dateIsDisabled = false;
81
+ if (typeof isDateDisabled === 'function' && !!date) {
82
+ const dateToCheck = extractDateParts(date);
83
+ dateIsDisabled = isDateDisabled(dateToCheck);
84
+ }
85
+
86
+ return (!min || date >= min) && (!max || date <= max) && !dateIsDisabled;
66
87
  }
67
88
 
68
89
  /**
@@ -90,20 +111,6 @@ export function getClosestDate(date, dates) {
90
111
  });
91
112
  }
92
113
 
93
- /**
94
- * Extracts the basic component parts of a date (day, month and year)
95
- * to the expected format.
96
- * @param {!Date} date
97
- * @return {{day: number, month: number, year: number}}
98
- */
99
- export function extractDateParts(date) {
100
- return {
101
- day: date.getDate(),
102
- month: date.getMonth(),
103
- year: date.getFullYear(),
104
- };
105
- }
106
-
107
114
  /**
108
115
  * Get difference in months between today and given months value.
109
116
  *
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { ValidateMixin } from '@vaadin/field-base/src/validate-mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import './vaadin-date-picker-overlay-content.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -237,6 +237,13 @@ export declare class DatePickerMixinClass {
237
237
  */
238
238
  max: string | undefined;
239
239
 
240
+ /**
241
+ * A function to be used to determine whether the user can select a given date.
242
+ * Receives a `DatePickerDate` object of the date to be selected and should return a
243
+ * boolean.
244
+ */
245
+ isDateDisabled: (date: DatePickerDate) => boolean;
246
+
240
247
  /**
241
248
  * Opens the dropdown.
242
249
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { hideOthers } from '@vaadin/a11y-base/src/aria-hidden.js';
@@ -302,6 +302,17 @@ export const DatePickerMixin = (subclass) =>
302
302
  sync: true,
303
303
  },
304
304
 
305
+ /**
306
+ * A function to be used to determine whether the user can select a given date.
307
+ * Receives a `DatePickerDate` object of the date to be selected and should return a
308
+ * boolean.
309
+ *
310
+ * @type {function(DatePickerDate): boolean | undefined}
311
+ */
312
+ isDateDisabled: {
313
+ type: Function,
314
+ },
315
+
305
316
  /**
306
317
  * The earliest date that can be selected. All earlier dates will be disabled.
307
318
  * @type {Date | undefined}
@@ -365,7 +376,7 @@ export const DatePickerMixin = (subclass) =>
365
376
  return [
366
377
  '_selectedDateChanged(_selectedDate, i18n)',
367
378
  '_focusedDateChanged(_focusedDate, i18n)',
368
- '__updateOverlayContent(_overlayContent, i18n, label, _minDate, _maxDate, _focusedDate, _selectedDate, showWeekNumbers)',
379
+ '__updateOverlayContent(_overlayContent, i18n, label, _minDate, _maxDate, _focusedDate, _selectedDate, showWeekNumbers, isDateDisabled)',
369
380
  '__updateOverlayContentTheme(_overlayContent, _theme)',
370
381
  '__updateOverlayContentFullScreen(_overlayContent, _fullscreen)',
371
382
  ];
@@ -601,7 +612,8 @@ export const DatePickerMixin = (subclass) =>
601
612
  checkValidity() {
602
613
  const inputValue = this._inputElementValue;
603
614
  const inputValid = !inputValue || (!!this._selectedDate && inputValue === this.__formatDate(this._selectedDate));
604
- const minMaxValid = !this._selectedDate || dateAllowed(this._selectedDate, this._minDate, this._maxDate);
615
+ const isDateValid =
616
+ !this._selectedDate || dateAllowed(this._selectedDate, this._minDate, this._maxDate, this.isDateDisabled);
605
617
 
606
618
  let inputValidity = true;
607
619
  if (this.inputElement) {
@@ -613,7 +625,7 @@ export const DatePickerMixin = (subclass) =>
613
625
  }
614
626
  }
615
627
 
616
- return inputValid && minMaxValid && inputValidity;
628
+ return inputValid && isDateValid && inputValidity;
617
629
  }
618
630
 
619
631
  /**
@@ -852,7 +864,17 @@ export const DatePickerMixin = (subclass) =>
852
864
 
853
865
  /** @private */
854
866
  // eslint-disable-next-line max-params
855
- __updateOverlayContent(overlayContent, i18n, label, minDate, maxDate, focusedDate, selectedDate, showWeekNumbers) {
867
+ __updateOverlayContent(
868
+ overlayContent,
869
+ i18n,
870
+ label,
871
+ minDate,
872
+ maxDate,
873
+ focusedDate,
874
+ selectedDate,
875
+ showWeekNumbers,
876
+ isDateDisabled,
877
+ ) {
856
878
  if (overlayContent) {
857
879
  overlayContent.i18n = i18n;
858
880
  overlayContent.label = label;
@@ -861,6 +883,7 @@ export const DatePickerMixin = (subclass) =>
861
883
  overlayContent.focusedDate = focusedDate;
862
884
  overlayContent.selectedDate = selectedDate;
863
885
  overlayContent.showWeekNumbers = showWeekNumbers;
886
+ overlayContent.isDateDisabled = isDateDisabled;
864
887
  }
865
888
  }
866
889
 
@@ -932,9 +955,11 @@ export const DatePickerMixin = (subclass) =>
932
955
  const initialPosition =
933
956
  this._selectedDate || this._overlayContent.initialPosition || parsedInitialPosition || new Date();
934
957
 
935
- return parsedInitialPosition || dateAllowed(initialPosition, this._minDate, this._maxDate)
958
+ return parsedInitialPosition || dateAllowed(initialPosition, this._minDate, this._maxDate, this.isDateDisabled)
936
959
  ? initialPosition
937
- : getClosestDate(initialPosition, [this._minDate, this._maxDate]);
960
+ : this._minDate || this._maxDate
961
+ ? getClosestDate(initialPosition, [this._minDate, this._maxDate])
962
+ : new Date();
938
963
  }
939
964
 
940
965
  /**
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { flush } from '@polymer/polymer/lib/utils/flush.js';
@@ -10,7 +10,13 @@ import { Debouncer } from '@vaadin/component-base/src/debounce.js';
10
10
  import { addListener, setTouchAction } from '@vaadin/component-base/src/gestures.js';
11
11
  import { MediaQueryController } from '@vaadin/component-base/src/media-query-controller.js';
12
12
  import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
13
- import { dateAfterXMonths, dateEquals, extractDateParts, getClosestDate } from './vaadin-date-picker-helper.js';
13
+ import {
14
+ dateAfterXMonths,
15
+ dateAllowed,
16
+ dateEquals,
17
+ extractDateParts,
18
+ getClosestDate,
19
+ } from './vaadin-date-picker-helper.js';
14
20
 
15
21
  /**
16
22
  * @polymerMixin
@@ -107,6 +113,17 @@ export const DatePickerOverlayContentMixin = (superClass) =>
107
113
  sync: true,
108
114
  },
109
115
 
116
+ /**
117
+ * A function to be used to determine whether the user can select a given date.
118
+ * Receives a `DatePickerDate` object of the date to be selected and should return a
119
+ * boolean.
120
+ *
121
+ * @type {function(DatePickerDate): boolean | undefined}
122
+ */
123
+ isDateDisabled: {
124
+ type: Function,
125
+ },
126
+
110
127
  /**
111
128
  * Input label
112
129
  */
@@ -134,9 +151,9 @@ export const DatePickerOverlayContentMixin = (superClass) =>
134
151
 
135
152
  static get observers() {
136
153
  return [
137
- '__updateCalendars(calendars, i18n, minDate, maxDate, selectedDate, focusedDate, showWeekNumbers, _ignoreTaps, _theme)',
154
+ '__updateCalendars(calendars, i18n, minDate, maxDate, selectedDate, focusedDate, showWeekNumbers, _ignoreTaps, _theme, isDateDisabled)',
138
155
  '__updateCancelButton(_cancelButton, i18n)',
139
- '__updateTodayButton(_todayButton, i18n, minDate, maxDate)',
156
+ '__updateTodayButton(_todayButton, i18n, minDate, maxDate, isDateDisabled)',
140
157
  '__updateYears(years, selectedDate, _theme)',
141
158
  ];
142
159
  }
@@ -303,10 +320,10 @@ export const DatePickerOverlayContentMixin = (superClass) =>
303
320
  }
304
321
 
305
322
  /** @private */
306
- __updateTodayButton(todayButton, i18n, minDate, maxDate) {
323
+ __updateTodayButton(todayButton, i18n, minDate, maxDate, isDateDisabled) {
307
324
  if (todayButton) {
308
325
  todayButton.textContent = i18n && i18n.today;
309
- todayButton.disabled = !this._isTodayAllowed(minDate, maxDate);
326
+ todayButton.disabled = !this._isTodayAllowed(minDate, maxDate, isDateDisabled);
310
327
  }
311
328
  }
312
329
 
@@ -321,12 +338,14 @@ export const DatePickerOverlayContentMixin = (superClass) =>
321
338
  showWeekNumbers,
322
339
  ignoreTaps,
323
340
  theme,
341
+ isDateDisabled,
324
342
  ) {
325
343
  if (calendars && calendars.length) {
326
344
  calendars.forEach((calendar) => {
327
345
  calendar.i18n = i18n;
328
346
  calendar.minDate = minDate;
329
347
  calendar.maxDate = maxDate;
348
+ calendar.isDateDisabled = isDateDisabled;
330
349
  calendar.focusedDate = focusedDate;
331
350
  calendar.selectedDate = selectedDate;
332
351
  calendar.showWeekNumbers = showWeekNumbers;
@@ -361,10 +380,14 @@ export const DatePickerOverlayContentMixin = (superClass) =>
361
380
  * @protected
362
381
  */
363
382
  _selectDate(dateToSelect) {
383
+ if (!this._dateAllowed(dateToSelect)) {
384
+ return false;
385
+ }
364
386
  this.selectedDate = dateToSelect;
365
387
  this.dispatchEvent(
366
388
  new CustomEvent('date-selected', { detail: { date: dateToSelect }, bubbles: true, composed: true }),
367
389
  );
390
+ return true;
368
391
  }
369
392
 
370
393
  /** @private */
@@ -775,9 +798,10 @@ export const DatePickerOverlayContentMixin = (superClass) =>
775
798
  handled = true;
776
799
  break;
777
800
  case 'Enter':
778
- this._selectDate(this.focusedDate);
779
- this._close();
780
- handled = true;
801
+ if (this._selectDate(this.focusedDate)) {
802
+ this._close();
803
+ handled = true;
804
+ }
781
805
  break;
782
806
  case ' ':
783
807
  this.__toggleDate(this.focusedDate);
@@ -931,7 +955,8 @@ export const DatePickerOverlayContentMixin = (superClass) =>
931
955
 
932
956
  /** @private */
933
957
  _focusAllowedDate(dateToFocus, diff, keepMonth) {
934
- if (this._dateAllowed(dateToFocus)) {
958
+ // For this check we do consider the isDateDisabled function because disabled dates are allowed to be focused, just not outside min/max
959
+ if (this._dateAllowed(dateToFocus, undefined, undefined, () => false)) {
935
960
  this.focusDate(dateToFocus, keepMonth);
936
961
  } else if (this._dateAllowed(this.focusedDate)) {
937
962
  // Move to min or max date
@@ -1009,18 +1034,18 @@ export const DatePickerOverlayContentMixin = (superClass) =>
1009
1034
  }
1010
1035
 
1011
1036
  /** @private */
1012
- _dateAllowed(date, min = this.minDate, max = this.maxDate) {
1013
- return (!min || date >= min) && (!max || date <= max);
1037
+ _dateAllowed(date, min = this.minDate, max = this.maxDate, isDateDisabled = this.isDateDisabled) {
1038
+ return dateAllowed(date, min, max, isDateDisabled);
1014
1039
  }
1015
1040
 
1016
1041
  /** @private */
1017
- _isTodayAllowed(min, max) {
1042
+ _isTodayAllowed(min, max, isDateDisabled) {
1018
1043
  const today = new Date();
1019
1044
  const todayMidnight = new Date(0, 0);
1020
1045
  todayMidnight.setFullYear(today.getFullYear());
1021
1046
  todayMidnight.setMonth(today.getMonth());
1022
1047
  todayMidnight.setDate(today.getDate());
1023
- return this._dateAllowed(todayMidnight, min, max);
1048
+ return this._dateAllowed(todayMidnight, min, max, isDateDisabled);
1024
1049
  }
1025
1050
 
1026
1051
  /**
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { css } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import '@vaadin/button/src/vaadin-button.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { css } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
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';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { css } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
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';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import '@vaadin/input-container/src/vaadin-input-container.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { timeOut } from '@vaadin/component-base/src/async.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import '@vaadin/button/src/vaadin-lit-button.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { html, LitElement } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { css, html, LitElement } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import '@vaadin/input-container/src/vaadin-lit-input-container.js';
@@ -25,7 +25,7 @@ import { datePickerStyles } from './vaadin-date-picker-styles.js';
25
25
  *
26
26
  * ## Disclaimer
27
27
  *
28
- * This component is an experiment not intended for publishing to npm.
28
+ * This component is an experiment and not yet a part of Vaadin platform.
29
29
  * There is no ETA regarding specific Vaadin version where it'll land.
30
30
  * Feel free to try this code in your apps as per Apache 2.0 license.
31
31
  */
@@ -61,7 +61,7 @@ class MonthCalendar extends MonthCalendarMixin(ThemableMixin(PolylitMixin(LitEle
61
61
  ${week.map((date) => {
62
62
  const isFocused = dateEquals(date, this.focusedDate);
63
63
  const isSelected = dateEquals(date, this.selectedDate);
64
- const isDisabled = !dateAllowed(date, this.minDate, this.maxDate);
64
+ const isDisabled = !dateAllowed(date, this.minDate, this.maxDate, this.isDateDisabled);
65
65
 
66
66
  const parts = [
67
67
  'date',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { FocusMixin } from '@vaadin/a11y-base/src/focus-mixin.js';
@@ -80,6 +80,17 @@ export const MonthCalendarMixin = (superClass) =>
80
80
  sync: true,
81
81
  },
82
82
 
83
+ /**
84
+ * A function to be used to determine whether the user can select a given date.
85
+ * Receives a `DatePickerDate` object of the date to be selected and should return a
86
+ * boolean.
87
+ * @type {Function | undefined}
88
+ */
89
+ isDateDisabled: {
90
+ type: Function,
91
+ value: () => false,
92
+ },
93
+
83
94
  disabled: {
84
95
  type: Boolean,
85
96
  reflectToAttribute: true,
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { css } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2016 - 2023 Vaadin Ltd.
3
+ * Copyright (c) 2016 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import '@polymer/polymer/lib/elements/dom-repeat.js';
@@ -50,12 +50,12 @@ class MonthCalendar extends MonthCalendarMixin(ThemableMixin(PolymerElement)) {
50
50
  <template is="dom-repeat" items="[[week]]">
51
51
  <td
52
52
  role="gridcell"
53
- part$="[[__getDatePart(item, focusedDate, selectedDate, minDate, maxDate)]]"
53
+ part$="[[__getDatePart(item, focusedDate, selectedDate, minDate, maxDate, isDateDisabled)]]"
54
54
  date="[[item]]"
55
55
  tabindex$="[[__getDayTabindex(item, focusedDate)]]"
56
- disabled$="[[__isDayDisabled(item, minDate, maxDate)]]"
56
+ disabled$="[[__isDayDisabled(item, minDate, maxDate, isDateDisabled)]]"
57
57
  aria-selected$="[[__getDayAriaSelected(item, selectedDate)]]"
58
- aria-disabled$="[[__getDayAriaDisabled(item, minDate, maxDate)]]"
58
+ aria-disabled$="[[__getDayAriaDisabled(item, minDate, maxDate, isDateDisabled)]]"
59
59
  aria-label$="[[__getDayAriaLabel(item)]]"
60
60
  >[[_getDate(item)]]</td
61
61
  >
@@ -76,7 +76,7 @@ class MonthCalendar extends MonthCalendarMixin(ThemableMixin(PolymerElement)) {
76
76
  /** @protected */
77
77
  _days: {
78
78
  type: Array,
79
- computed: '_getDays(month, i18n, minDate, maxDate)',
79
+ computed: '_getDays(month, i18n, minDate, maxDate, isDateDisabled)',
80
80
  },
81
81
 
82
82
  /** @protected */
@@ -107,10 +107,10 @@ class MonthCalendar extends MonthCalendarMixin(ThemableMixin(PolymerElement)) {
107
107
  }
108
108
 
109
109
  /** @private */
110
- __getDatePart(date, focusedDate, selectedDate, minDate, maxDate) {
110
+ __getDatePart(date, focusedDate, selectedDate, minDate, maxDate, isDateDisabled) {
111
111
  const result = ['date'];
112
112
 
113
- if (this.__isDayDisabled(date, minDate, maxDate)) {
113
+ if (this.__isDayDisabled(date, minDate, maxDate, isDateDisabled)) {
114
114
  result.push('disabled');
115
115
  }
116
116
 
@@ -147,17 +147,17 @@ class MonthCalendar extends MonthCalendarMixin(ThemableMixin(PolymerElement)) {
147
147
  }
148
148
 
149
149
  /** @private */
150
- __isDayDisabled(date, minDate, maxDate) {
151
- return !dateAllowed(date, minDate, maxDate);
150
+ __isDayDisabled(date, minDate, maxDate, isDateDisabled) {
151
+ return !dateAllowed(date, minDate, maxDate, isDateDisabled);
152
152
  }
153
153
 
154
154
  /** @private */
155
- __getDayAriaDisabled(date, min, max) {
156
- if (date === undefined || min === undefined || max === undefined) {
155
+ __getDayAriaDisabled(date, min, max, isDateDisabled) {
156
+ if (date === undefined || (min === undefined && max === undefined && isDateDisabled === undefined)) {
157
157
  return;
158
158
  }
159
159
 
160
- if (this.__isDayDisabled(date, min, max)) {
160
+ if (this.__isDayDisabled(date, min, max, isDateDisabled)) {
161
161
  return 'true';
162
162
  }
163
163
  }