@vaadin/date-time-picker 22.0.0-beta1 → 22.0.1

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
@@ -1,54 +1,52 @@
1
- # <vaadin-date-time-picker>
1
+ # @vaadin/date-time-picker
2
2
 
3
- [<vaadin-date-time-picker>](https://vaadin.com/components/vaadin-date-time-picker) is a Web Component providing a date and time selection field which includes a scrollable month calendar view, part of the [Vaadin components](https://vaadin.com/components).
3
+ An input field web component for selecting both a date and a time.
4
4
 
5
- [Live Demo ↗](https://vaadin.com/components/vaadin-date-time-picker/html-examples)
6
- |
7
- [API documentation ↗](https://vaadin.com/components/vaadin-date-time-picker/html-api)
5
+ [Documentation + Live Demo ↗](https://vaadin.com/docs/latest/ds/components/date-time-picker)
8
6
 
9
7
  [![npm version](https://badgen.net/npm/v/@vaadin/date-time-picker)](https://www.npmjs.com/package/@vaadin/date-time-picker)
10
- [![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/vaadinvaadin-date-time-picker)
11
8
  [![Discord](https://img.shields.io/discord/732335336448852018?label=discord)](https://discord.gg/PHmkCKC)
12
9
 
13
10
  ```html
14
11
  <vaadin-date-time-picker></vaadin-date-time-picker>
15
12
  ```
16
13
 
17
- [<img src="https://raw.githubusercontent.com/vaadin/vaadin-date-time-picker/master/screenshot.png" width="200" alt="Screenshot of vaadin-date-time-picker">](https://vaadin.com/components/vaadin-date-time-picker)
18
-
19
14
  ## Installation
20
15
 
21
- Install `vaadin-date-time-picker`:
16
+ Install the component:
22
17
 
23
18
  ```sh
24
- npm i @vaadin/date-time-picker --save
19
+ npm i @vaadin/date-time-picker
25
20
  ```
26
21
 
27
- Once installed, import it in your application:
22
+ Once installed, import the component in your application:
28
23
 
29
24
  ```js
30
- import '@vaadin/date-time-picker/vaadin-date-time-picker.js';
25
+ import '@vaadin/date-time-picker';
31
26
  ```
32
27
 
33
- ## Getting started
34
-
35
- Vaadin components use the Lumo theme by default.
36
-
37
- To use the Material theme, import the correspondent file from the `theme/material` folder.
28
+ ## Themes
38
29
 
39
- ## Entry points
30
+ Vaadin components come with two built-in [themes](https://vaadin.com/docs/latest/ds/customization/using-themes), Lumo and Material.
31
+ The [main entrypoint](https://github.com/vaadin/web-components/blob/master/packages/date-time-picker/vaadin-date-time-picker.js) of the package uses the Lumo theme.
40
32
 
41
- - The component with the Lumo theme:
33
+ To use the Material theme, import the component from the `theme/material` folder:
42
34
 
43
- `theme/lumo/vaadin-date-time-picker.js`
35
+ ```js
36
+ import '@vaadin/date-time-picker/theme/material/vaadin-date-time-picker.js';
37
+ ```
44
38
 
45
- - The component with the Material theme:
39
+ You can also import the Lumo version of the component explicitly:
46
40
 
47
- `theme/material/vaadin-date-time-picker.js`
41
+ ```js
42
+ import '@vaadin/date-time-picker/theme/lumo/vaadin-date-time-picker.js';
43
+ ```
48
44
 
49
- - Alias for `theme/lumo/vaadin-date-time-picker.js`:
45
+ Finally, you can import the un-themed component from the `src` folder to get a minimal starting point:
50
46
 
51
- `vaadin-date-time-picker.js`
47
+ ```js
48
+ import '@vaadin/date-time-picker/src/vaadin-date-time-picker.js';
49
+ ```
52
50
 
53
51
  ## Contributing
54
52
 
@@ -58,4 +56,5 @@ Read the [contributing guide](https://vaadin.com/docs/latest/guide/contributing/
58
56
 
59
57
  Apache License 2.0
60
58
 
61
- Vaadin collects development time usage statistics to improve this product. For details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.
59
+ Vaadin collects usage statistics at development time to improve this product.
60
+ For details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/date-time-picker",
3
- "version": "22.0.0-beta1",
3
+ "version": "22.0.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -33,19 +33,19 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@polymer/polymer": "^3.0.0",
36
- "@vaadin/component-base": "22.0.0-beta1",
37
- "@vaadin/custom-field": "22.0.0-beta1",
38
- "@vaadin/date-picker": "22.0.0-beta1",
39
- "@vaadin/field-base": "22.0.0-beta1",
40
- "@vaadin/time-picker": "22.0.0-beta1",
41
- "@vaadin/vaadin-lumo-styles": "22.0.0-beta1",
42
- "@vaadin/vaadin-material-styles": "22.0.0-beta1",
43
- "@vaadin/vaadin-themable-mixin": "22.0.0-beta1"
36
+ "@vaadin/component-base": "^22.0.1",
37
+ "@vaadin/custom-field": "^22.0.1",
38
+ "@vaadin/date-picker": "^22.0.1",
39
+ "@vaadin/field-base": "^22.0.1",
40
+ "@vaadin/time-picker": "^22.0.1",
41
+ "@vaadin/vaadin-lumo-styles": "^22.0.1",
42
+ "@vaadin/vaadin-material-styles": "^22.0.1",
43
+ "@vaadin/vaadin-themable-mixin": "^22.0.1"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@esm-bundle/chai": "^4.3.4",
47
- "@vaadin/testing-helpers": "^0.3.0",
47
+ "@vaadin/testing-helpers": "^0.3.2",
48
48
  "sinon": "^9.2.1"
49
49
  },
50
- "gitHead": "4cf8a9d0504994200c610e44b3676114fef49c1e"
50
+ "gitHead": "2b0a2bff0369d6020f7cc33ad35506aa2d1f6f68"
51
51
  }
@@ -3,11 +3,11 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
7
6
  import { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js';
7
+ import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
8
8
  import { SlotMixin } from '@vaadin/component-base/src/slot-mixin.js';
9
- import { FieldMixin } from '@vaadin/field-base/src/field-mixin.js';
10
9
  import { DatePickerI18n } from '@vaadin/date-picker/src/vaadin-date-picker.js';
10
+ import { FieldMixin } from '@vaadin/field-base/src/field-mixin.js';
11
11
  import { TimePickerI18n } from '@vaadin/time-picker/src/vaadin-time-picker.js';
12
12
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
13
13
 
@@ -3,17 +3,17 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
7
- import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
6
+ import './vaadin-date-time-picker-date-picker.js';
7
+ import './vaadin-date-time-picker-time-picker.js';
8
+ import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
9
+ import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
8
10
  import { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js';
11
+ import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
9
12
  import { SlotMixin } from '@vaadin/component-base/src/slot-mixin.js';
13
+ import { dateEquals } from '@vaadin/date-picker/src/vaadin-date-picker-helper.js';
10
14
  import { FieldMixin } from '@vaadin/field-base/src/field-mixin.js';
11
15
  import { inputFieldShared } from '@vaadin/field-base/src/styles/input-field-shared-styles.js';
12
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
13
- import { registerStyles } from '@vaadin/vaadin-themable-mixin/register-styles.js';
14
- import { dateEquals } from '@vaadin/date-picker/src/vaadin-date-picker-helper.js';
15
- import './vaadin-date-time-picker-date-picker.js';
16
- import './vaadin-date-time-picker-time-picker.js';
16
+ import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
17
17
 
18
18
  registerStyles('vaadin-date-time-picker', inputFieldShared, { moduleId: 'vaadin-date-time-picker' });
19
19
 
@@ -328,6 +328,24 @@ class DateTimePicker extends FieldMixin(SlotMixin(DisabledMixin(ThemableMixin(El
328
328
  i18n: {
329
329
  type: Object,
330
330
  value: () => Object.assign({}, datePickerI18nDefaults, timePickerI18nDefaults)
331
+ },
332
+
333
+ /**
334
+ * The current slotted date picker.
335
+ * @private
336
+ */
337
+ __datePicker: {
338
+ type: HTMLElement,
339
+ observer: '__datePickerChanged'
340
+ },
341
+
342
+ /**
343
+ * The current slotted time picker.
344
+ * @private
345
+ */
346
+ __timePicker: {
347
+ type: HTMLElement,
348
+ observer: '__timePickerChanged'
331
349
  }
332
350
  };
333
351
  }
@@ -379,6 +397,10 @@ class DateTimePicker extends FieldMixin(SlotMixin(DisabledMixin(ThemableMixin(El
379
397
 
380
398
  this.__changeEventHandler = this.__changeEventHandler.bind(this);
381
399
  this.__valueChangedEventHandler = this.__valueChangedEventHandler.bind(this);
400
+
401
+ this._observer = new FlattenedNodesObserver(this, (info) => {
402
+ this.__onDomChange(info.addedNodes);
403
+ });
382
404
  }
383
405
 
384
406
  /** @protected */
@@ -391,11 +413,8 @@ class DateTimePicker extends FieldMixin(SlotMixin(DisabledMixin(ThemableMixin(El
391
413
  }
392
414
  });
393
415
 
394
- this.__datePickerChanged();
395
- this.__timePickerChanged();
396
-
397
- this.$.dateSlot.addEventListener('slotchange', this.__datePickerChanged.bind(this));
398
- this.$.timeSlot.addEventListener('slotchange', this.__timePickerChanged.bind(this));
416
+ this.__datePicker = this._getDirectSlotChild('date-picker');
417
+ this.__timePicker = this._getDirectSlotChild('time-picker');
399
418
 
400
419
  if (this.autofocus && !this.disabled) {
401
420
  window.requestAnimationFrame(() => this.focus());
@@ -406,14 +425,6 @@ class DateTimePicker extends FieldMixin(SlotMixin(DisabledMixin(ThemableMixin(El
406
425
  this.ariaTarget = this;
407
426
  }
408
427
 
409
- /**
410
- * Attribute used by `FieldMixin` to set accessible name.
411
- * @protected
412
- */
413
- get _ariaAttr() {
414
- return 'aria-labelledby';
415
- }
416
-
417
428
  /** @private */
418
429
  __filterElements(node) {
419
430
  return node.nodeType === Node.ELEMENT_NODE;
@@ -458,87 +469,98 @@ class DateTimePicker extends FieldMixin(SlotMixin(DisabledMixin(ThemableMixin(El
458
469
  }
459
470
 
460
471
  /** @private */
461
- __datePickerChanged() {
462
- const datePicker = this._getDirectSlotChild('date-picker');
463
- if (this.__datePicker === datePicker || !datePicker) {
472
+ __onDomChange(addedNodes) {
473
+ addedNodes
474
+ .filter((node) => node.nodeType === Node.ELEMENT_NODE)
475
+ .forEach((node) => {
476
+ const slotAttributeValue = node.getAttribute('slot');
477
+
478
+ if (slotAttributeValue === 'date-picker') {
479
+ this.__datePicker = node;
480
+ } else if (slotAttributeValue === 'time-picker') {
481
+ this.__timePicker = node;
482
+ }
483
+ });
484
+ }
485
+
486
+ /** @private */
487
+ __datePickerChanged(newDatePicker, existingDatePicker) {
488
+ if (!newDatePicker) {
464
489
  return;
465
490
  }
466
- if (this.__datePicker) {
491
+ if (existingDatePicker) {
467
492
  // Remove an existing date picker
468
- this.__removeInputListeners(this.__datePicker);
469
- this.__datePicker.remove();
493
+ this.__removeInputListeners(existingDatePicker);
494
+ existingDatePicker.remove();
470
495
  }
471
496
 
472
- this.__addInputListeners(datePicker);
473
- this.__datePicker = datePicker;
497
+ this.__addInputListeners(newDatePicker);
474
498
 
475
- if (datePicker.__defaultPicker) {
499
+ if (newDatePicker.__defaultPicker) {
476
500
  // Synchronize properties to default date picker
477
- datePicker.placeholder = this.datePlaceholder;
478
- datePicker.invalid = this.invalid;
479
- datePicker.initialPosition = this.initialPosition;
480
- datePicker.showWeekNumbers = this.showWeekNumbers;
481
- this.__syncI18n(datePicker, this, datePickerI18nProps);
501
+ newDatePicker.placeholder = this.datePlaceholder;
502
+ newDatePicker.invalid = this.invalid;
503
+ newDatePicker.initialPosition = this.initialPosition;
504
+ newDatePicker.showWeekNumbers = this.showWeekNumbers;
505
+ this.__syncI18n(newDatePicker, this, datePickerI18nProps);
482
506
  } else {
483
507
  // Synchronize properties from slotted date picker
484
- this.datePlaceholder = datePicker.placeholder;
485
- this.initialPosition = datePicker.initialPosition;
486
- this.showWeekNumbers = datePicker.showWeekNumbers;
487
- this.__syncI18n(this, datePicker, datePickerI18nProps);
508
+ this.datePlaceholder = newDatePicker.placeholder;
509
+ this.initialPosition = newDatePicker.initialPosition;
510
+ this.showWeekNumbers = newDatePicker.showWeekNumbers;
511
+ this.__syncI18n(this, newDatePicker, datePickerI18nProps);
488
512
  }
489
513
 
490
514
  // min and max are always synchronized from date time picker (host) to inner fields because time picker
491
515
  // min and max need to be dynamically set depending on currently selected date instead of simple propagation
492
- datePicker.min = this.__formatDateISO(this.__minDateTime, this.__defaultDateMinMaxValue);
493
- datePicker.max = this.__formatDateISO(this.__maxDateTime, this.__defaultDateMinMaxValue);
494
- datePicker.required = this.required;
495
- datePicker.disabled = this.disabled;
496
- datePicker.readonly = this.readonly;
497
- datePicker.autoOpenDisabled = this.autoOpenDisabled;
516
+ newDatePicker.min = this.__formatDateISO(this.__minDateTime, this.__defaultDateMinMaxValue);
517
+ newDatePicker.max = this.__formatDateISO(this.__maxDateTime, this.__defaultDateMinMaxValue);
518
+ newDatePicker.required = this.required;
519
+ newDatePicker.disabled = this.disabled;
520
+ newDatePicker.readonly = this.readonly;
521
+ newDatePicker.autoOpenDisabled = this.autoOpenDisabled;
498
522
 
499
523
  // Disable default internal validation for the component
500
- datePicker.validate = () => {};
501
- datePicker._validateInput = () => {};
524
+ newDatePicker.validate = () => {};
525
+ newDatePicker._validateInput = () => {};
502
526
  }
503
527
 
504
528
  /** @private */
505
- __timePickerChanged() {
506
- const timePicker = this._getDirectSlotChild('time-picker');
507
- if (this.__timePicker === timePicker || !timePicker) {
529
+ __timePickerChanged(newTimePicker, existingTimePicker) {
530
+ if (!newTimePicker) {
508
531
  return;
509
532
  }
510
- if (this.__timePicker) {
533
+ if (existingTimePicker) {
511
534
  // Remove an existing time picker
512
- this.__removeInputListeners(this.__timePicker);
513
- this.__timePicker.remove();
535
+ this.__removeInputListeners(existingTimePicker);
536
+ existingTimePicker.remove();
514
537
  }
515
538
 
516
- this.__addInputListeners(timePicker);
517
- this.__timePicker = timePicker;
539
+ this.__addInputListeners(newTimePicker);
518
540
 
519
- if (timePicker.__defaultPicker) {
541
+ if (newTimePicker.__defaultPicker) {
520
542
  // Synchronize properties to default time picker
521
- timePicker.placeholder = this.timePlaceholder;
522
- timePicker.step = this.step;
523
- timePicker.invalid = this.invalid;
524
- this.__syncI18n(timePicker, this, timePickerI18nProps);
543
+ newTimePicker.placeholder = this.timePlaceholder;
544
+ newTimePicker.step = this.step;
545
+ newTimePicker.invalid = this.invalid;
546
+ this.__syncI18n(newTimePicker, this, timePickerI18nProps);
525
547
  } else {
526
548
  // Synchronize properties from slotted time picker
527
- this.timePlaceholder = timePicker.placeholder;
528
- this.step = timePicker.step;
529
- this.__syncI18n(this, timePicker, timePickerI18nProps);
549
+ this.timePlaceholder = newTimePicker.placeholder;
550
+ this.step = newTimePicker.step;
551
+ this.__syncI18n(this, newTimePicker, timePickerI18nProps);
530
552
  }
531
553
 
532
554
  // min and max are always synchronized from parent to slotted because time picker min and max
533
555
  // need to be dynamically set depending on currently selected date instead of simple propagation
534
556
  this.__updateTimePickerMinMax();
535
- timePicker.required = this.required;
536
- timePicker.disabled = this.disabled;
537
- timePicker.readonly = this.readonly;
538
- timePicker.autoOpenDisabled = this.autoOpenDisabled;
557
+ newTimePicker.required = this.required;
558
+ newTimePicker.disabled = this.disabled;
559
+ newTimePicker.readonly = this.readonly;
560
+ newTimePicker.autoOpenDisabled = this.autoOpenDisabled;
539
561
 
540
562
  // Disable default internal validation for the component
541
- timePicker.validate = () => {};
563
+ newTimePicker.validate = () => {};
542
564
  }
543
565
 
544
566
  /** @private */
@@ -570,12 +592,10 @@ class DateTimePicker extends FieldMixin(SlotMixin(DisabledMixin(ThemableMixin(El
570
592
 
571
593
  /** @private */
572
594
  __i18nChanged(changeRecord) {
573
- this.__datePickerChanged();
574
595
  if (this.__datePicker) {
575
596
  this.__datePicker.set(changeRecord.path, changeRecord.value);
576
597
  }
577
598
 
578
- this.__timePickerChanged();
579
599
  if (this.__timePicker) {
580
600
  this.__timePicker.set(changeRecord.path, changeRecord.value);
581
601
  }
@@ -1,9 +1,9 @@
1
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
- import { helper } from '@vaadin/vaadin-lumo-styles/mixins/helper.js';
3
- import { requiredField } from '@vaadin/vaadin-lumo-styles/mixins/required-field.js';
4
- import { customField } from '@vaadin/custom-field/theme/lumo/vaadin-custom-field-styles.js';
5
1
  import '@vaadin/date-picker/theme/lumo/vaadin-date-picker.js';
6
2
  import '@vaadin/time-picker/theme/lumo/vaadin-time-picker.js';
3
+ import { customField } from '@vaadin/custom-field/theme/lumo/vaadin-custom-field-styles.js';
4
+ import { helper } from '@vaadin/vaadin-lumo-styles/mixins/helper.js';
5
+ import { requiredField } from '@vaadin/vaadin-lumo-styles/mixins/required-field.js';
6
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
7
7
 
8
8
  registerStyles('vaadin-date-time-picker', [requiredField, helper, customField], {
9
9
  moduleId: 'lumo-date-time-picker'
@@ -1,9 +1,9 @@
1
- import { registerStyles } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
- import { helper } from '@vaadin/vaadin-material-styles/mixins/helper.js';
3
- import { requiredField } from '@vaadin/vaadin-material-styles/mixins/required-field.js';
4
- import { customField } from '@vaadin/custom-field/theme/material/vaadin-custom-field-styles.js';
5
1
  import '@vaadin/date-picker/theme/material/vaadin-date-picker.js';
6
2
  import '@vaadin/time-picker/theme/material/vaadin-time-picker.js';
3
+ import { customField } from '@vaadin/custom-field/theme/material/vaadin-custom-field-styles.js';
4
+ import { helper } from '@vaadin/vaadin-material-styles/mixins/helper.js';
5
+ import { requiredField } from '@vaadin/vaadin-material-styles/mixins/required-field.js';
6
+ import { registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
7
7
 
8
8
  registerStyles('vaadin-date-time-picker', [requiredField, helper, customField], {
9
9
  moduleId: 'material-date-time-picker'