-
Notifications
You must be signed in to change notification settings - Fork 83
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 based version of vaadin-tooltip (#6536)
- Loading branch information
1 parent
1d4eb25
commit 3aebd45
Showing
18 changed files
with
349 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2022 - 2023 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
*/ | ||
import { html, LitElement } from 'lit'; | ||
import { defineCustomElement } from '@vaadin/component-base/src/define.js'; | ||
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js'; | ||
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js'; | ||
import { overlayStyles } from '@vaadin/overlay/src/vaadin-overlay-styles.js'; | ||
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js'; | ||
import { TooltipOverlayMixin } from './vaadin-tooltip-overlay-mixin.js'; | ||
import { tooltipOverlayStyles } from './vaadin-tooltip-overlay-styles.js'; | ||
|
||
/** | ||
* An element used internally by `<vaadin-tooltip>`. Not intended to be used separately. | ||
* | ||
* @customElement | ||
* @extends HTMLElement | ||
* @mixes DirMixin | ||
* @mixes ThemableMixin | ||
* @mixes TooltipOverlayMixin | ||
* @private | ||
*/ | ||
class TooltipOverlay extends TooltipOverlayMixin(DirMixin(ThemableMixin(PolylitMixin(LitElement)))) { | ||
static get is() { | ||
return 'vaadin-tooltip-overlay'; | ||
} | ||
|
||
static get styles() { | ||
return [overlayStyles, tooltipOverlayStyles]; | ||
} | ||
|
||
/** @protected */ | ||
render() { | ||
return html` | ||
<div id="backdrop" part="backdrop" hidden></div> | ||
<div part="overlay" id="overlay"> | ||
<div part="content" id="content"><slot></slot></div> | ||
</div> | ||
`; | ||
} | ||
} | ||
|
||
defineCustomElement(TooltipOverlay); |
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,6 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2022 - 2023 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
*/ | ||
export * from './vaadin-tooltip.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,78 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2022 - 2023 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
*/ | ||
import './vaadin-lit-tooltip-overlay.js'; | ||
import { css, html, LitElement } from 'lit'; | ||
import { ifDefined } from 'lit/directives/if-defined.js'; | ||
import { defineCustomElement } from '@vaadin/component-base/src/define.js'; | ||
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js'; | ||
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js'; | ||
import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js'; | ||
import { TooltipMixin } from './vaadin-tooltip-mixin.js'; | ||
|
||
/** | ||
* LitElement based version of `<vaadin-tooltip>` 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. | ||
* | ||
* @customElement | ||
* @extends HTMLElement | ||
* @mixes ElementMixin | ||
* @mixes ThemePropertyMixin | ||
* @mixes TooltipMixin | ||
*/ | ||
class Tooltip extends TooltipMixin(ThemePropertyMixin(ElementMixin(PolylitMixin(LitElement)))) { | ||
static get is() { | ||
return 'vaadin-tooltip'; | ||
} | ||
|
||
static get styles() { | ||
return css` | ||
:host { | ||
display: none; | ||
} | ||
`; | ||
} | ||
|
||
/** @protected */ | ||
render() { | ||
const effectivePosition = this.__effectivePosition; | ||
|
||
return html` | ||
<vaadin-tooltip-overlay | ||
.renderer="${this._renderer}" | ||
.owner="${this}" | ||
theme="${ifDefined(this._theme)}" | ||
.opened="${this._isConnected && (this.manual ? this.opened : this._autoOpened)}" | ||
.positionTarget="${this.target}" | ||
.position="${effectivePosition}" | ||
?no-horizontal-overlap="${this.__computeNoHorizontalOverlap(effectivePosition)}" | ||
?no-vertical-overlap="${this.__computeNoVerticalOverlap(effectivePosition)}" | ||
.horizontalAlign="${this.__computeHorizontalAlign(effectivePosition)}" | ||
.verticalAlign="${this.__computeVerticalAlign(effectivePosition)}" | ||
@mouseenter="${this.__onOverlayMouseEnter}" | ||
@mouseleave="${this.__onOverlayMouseLeave}" | ||
modeless | ||
></vaadin-tooltip-overlay> | ||
<slot name="sr-label"></slot> | ||
`; | ||
} | ||
|
||
/** @protected */ | ||
ready() { | ||
super.ready(); | ||
|
||
this._overlayElement = this.shadowRoot.querySelector('vaadin-tooltip-overlay'); | ||
} | ||
} | ||
|
||
defineCustomElement(Tooltip); | ||
|
||
export { Tooltip }; |
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,11 @@ | ||
import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js'; | ||
|
||
registerStyles( | ||
'vaadin-tooltip-overlay', | ||
css` | ||
[part='overlay'] { | ||
width: 50px; | ||
border: 1px solid blue; | ||
} | ||
`, | ||
); |
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-tooltip.js'; | ||
import './tooltip.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-lit-tooltip.js'; | ||
import './tooltip-offset.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-tooltip.js'; | ||
import './tooltip-offset.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-tooltip.js'; | ||
import './tooltip.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,4 @@ | ||
import './not-animated-styles.js'; | ||
import './position-styles.js'; | ||
import '../src/vaadin-lit-tooltip.js'; | ||
import './tooltip-position.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,4 @@ | ||
import './not-animated-styles.js'; | ||
import './position-styles.js'; | ||
import '../src/vaadin-tooltip.js'; | ||
import './tooltip-position.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-tooltip.js'; | ||
import './tooltip-timers.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-tooltip.js'; | ||
import './tooltip-timers.common.js'; |
Oops, something went wrong.