-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experiment: add LitElement version of vaadin-date-picker (#6276)
- Loading branch information
1 parent
5e0e6dc
commit da96769
Showing
30 changed files
with
247 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2016 - 2023 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
*/ | ||
import '@vaadin/input-container/src/vaadin-input-container.js'; | ||
import './vaadin-date-picker-overlay.js'; | ||
import './vaadin-lit-date-picker-overlay-content.js'; | ||
import { html, LitElement } from 'lit'; | ||
import { ifDefined } from 'lit/directives/if-defined.js'; | ||
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js'; | ||
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js'; | ||
import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js'; | ||
import { InputControlMixin } from '@vaadin/field-base/src/input-control-mixin.js'; | ||
import { InputController } from '@vaadin/field-base/src/input-controller.js'; | ||
import { LabelledInputController } from '@vaadin/field-base/src/labelled-input-controller.js'; | ||
import { inputFieldShared } from '@vaadin/field-base/src/styles/input-field-shared-styles.js'; | ||
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js'; | ||
import { DatePickerMixin } from './vaadin-date-picker-mixin.js'; | ||
import { datePickerStyles } from './vaadin-date-picker-styles.js'; | ||
|
||
/** | ||
* LitElement based version of `<vaadin-date-picker>` web component. | ||
* | ||
* ## Disclaimer | ||
* | ||
* This component is an experiment not intended for publishing to npm. | ||
* There is no ETA regarding specific Vaadin version where it'll land. | ||
* Feel free to try this code in your apps as per Apache 2.0 license. | ||
*/ | ||
class DatePicker extends DatePickerMixin(InputControlMixin(ThemableMixin(ElementMixin(PolylitMixin(LitElement))))) { | ||
static get is() { | ||
return 'vaadin-date-picker'; | ||
} | ||
|
||
static get styles() { | ||
return [inputFieldShared, datePickerStyles]; | ||
} | ||
|
||
static get properties() { | ||
return { | ||
/** @private */ | ||
_positionTarget: { | ||
type: Object, | ||
sync: true, | ||
}, | ||
}; | ||
} | ||
|
||
/** | ||
* Used by `InputControlMixin` as a reference to the clear button element. | ||
* @protected | ||
* @return {!HTMLElement} | ||
*/ | ||
get clearElement() { | ||
return this.$.clearButton; | ||
} | ||
|
||
/** @protected */ | ||
render() { | ||
return html` | ||
<div class="vaadin-date-picker-container"> | ||
<div part="label"> | ||
<slot name="label"></slot> | ||
<span part="required-indicator" aria-hidden="true" @click="${this.focus}"></span> | ||
</div> | ||
<vaadin-input-container | ||
part="input-field" | ||
.readonly="${this.readonly}" | ||
.disabled="${this.disabled}" | ||
.invalid="${this.invalid}" | ||
theme="${ifDefined(this._theme)}" | ||
> | ||
<slot name="prefix" slot="prefix"></slot> | ||
<slot name="input"></slot> | ||
<div id="clearButton" part="clear-button" slot="suffix" aria-hidden="true"></div> | ||
<div part="toggle-button" slot="suffix" aria-hidden="true" @click="${this._toggle}"></div> | ||
</vaadin-input-container> | ||
<div part="helper-text"> | ||
<slot name="helper"></slot> | ||
</div> | ||
<div part="error-message"> | ||
<slot name="error-message"></slot> | ||
</div> | ||
</div> | ||
<vaadin-date-picker-overlay | ||
id="overlay" | ||
?fullscreen="${this._fullscreen}" | ||
theme="${ifDefined(this._theme)}" | ||
.opened="${this.opened}" | ||
@opened-changed="${this._onOpenedChanged}" | ||
@vaadin-overlay-escape-press="${this._onOverlayEscapePress}" | ||
@vaadin-overlay-open="${this._onOverlayOpened}" | ||
@vaadin-overlay-close="${this._onVaadinOverlayClose}" | ||
@vaadin-overlay-closing="${this._onOverlayClosed}" | ||
restore-focus-on-close | ||
no-vertical-overlap | ||
.restoreFocusNode="${this.inputElement}" | ||
.positionTarget="${this._positionTarget}" | ||
></vaadin-date-picker-overlay> | ||
<slot name="tooltip"></slot> | ||
`; | ||
} | ||
|
||
/** @protected */ | ||
firstUpdated() { | ||
super.firstUpdated(); | ||
|
||
this.addController( | ||
new InputController(this, (input) => { | ||
this._setInputElement(input); | ||
this._setFocusElement(input); | ||
this.stateTarget = input; | ||
this.ariaTarget = input; | ||
}), | ||
); | ||
this.addController(new LabelledInputController(this.inputElement, this._labelController)); | ||
|
||
this._tooltipController = new TooltipController(this); | ||
this.addController(this._tooltipController); | ||
this._tooltipController.setPosition('top'); | ||
this._tooltipController.setShouldShow((target) => !target.opened); | ||
|
||
this._positionTarget = this.shadowRoot.querySelector('[part="input-field"]'); | ||
|
||
const toggleButton = this.shadowRoot.querySelector('[part="toggle-button"]'); | ||
toggleButton.addEventListener('mousedown', (e) => e.preventDefault()); | ||
} | ||
|
||
/** @private */ | ||
_onOpenedChanged(event) { | ||
this.opened = event.detail.value; | ||
} | ||
|
||
/** @private */ | ||
_onVaadinOverlayClose(e) { | ||
if (e.detail.sourceEvent && e.detail.sourceEvent.composedPath().includes(this)) { | ||
e.preventDefault(); | ||
} | ||
} | ||
|
||
/** @private */ | ||
_toggle(e) { | ||
e.stopPropagation(); | ||
if (this.$.overlay.opened) { | ||
this.close(); | ||
} else { | ||
this.open(); | ||
} | ||
} | ||
} | ||
|
||
customElements.define(DatePicker.is, DatePicker); | ||
|
||
export { DatePicker }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import '../src/vaadin-lit-date-picker.js'; | ||
import './basic.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import '../src/vaadin-date-picker.js'; | ||
import './basic.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import '../src/vaadin-lit-date-picker.js'; | ||
import './dropdown.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import '../src/vaadin-date-picker.js'; | ||
import './dropdown.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './not-animated-styles.js'; | ||
import '../src/vaadin-lit-date-picker.js'; | ||
import './events.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './not-animated-styles.js'; | ||
import '../src/vaadin-date-picker.js'; | ||
import './events.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './not-animated-styles.js'; | ||
import '../src/vaadin-lit-date-picker.js'; | ||
import './fullscreen.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './not-animated-styles.js'; | ||
import '../src/vaadin-date-picker.js'; | ||
import './fullscreen.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './not-animated-styles.js'; | ||
import '../src/vaadin-lit-date-picker.js'; | ||
import './keyboard-input.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './not-animated-styles.js'; | ||
import '../src/vaadin-date-picker.js'; | ||
import './keyboard-input.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './not-animated-styles.js'; | ||
import '../src/vaadin-lit-date-picker.js'; | ||
import './keyboard-navigation.common.js'; |
3 changes: 3 additions & 0 deletions
3
packages/date-picker/test/keyboard-navigation-polymer.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './not-animated-styles.js'; | ||
import '../src/vaadin-date-picker.js'; | ||
import './keyboard-navigation.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './not-animated-styles.js'; | ||
import '../src/vaadin-lit-date-picker.js'; | ||
import './theme-propagation.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './not-animated-styles.js'; | ||
import '../src/vaadin-date-picker.js'; | ||
import './theme-propagation.common.js'; |
Oops, something went wrong.