diff --git a/packages/tooltip/package.json b/packages/tooltip/package.json index 9b7c3770c..891b67556 100644 --- a/packages/tooltip/package.json +++ b/packages/tooltip/package.json @@ -33,6 +33,7 @@ ], "dependencies": { "@lion/core": "^0.1.9", + "@lion/popup": "^0.1.23", "@lion/overlays": "^0.2.7" }, "devDependencies": { diff --git a/packages/tooltip/src/LionTooltip.js b/packages/tooltip/src/LionTooltip.js index b2a30e8d4..47681f6eb 100644 --- a/packages/tooltip/src/LionTooltip.js +++ b/packages/tooltip/src/LionTooltip.js @@ -1,31 +1,23 @@ -import { UpdatingElement } from '@lion/core'; +import { LionPopup } from '@lion/popup'; import { overlays, LocalOverlayController } from '@lion/overlays'; -export class LionTooltip extends UpdatingElement { - static get properties() { - return { - position: { - type: String, - }, - }; - } - +export class LionTooltip extends LionPopup { connectedCallback() { super.connectedCallback(); - this.contenNode = this.querySelector('[slot="content"]'); + this.contentNode = this.querySelector('[slot="content"]'); this.invokerNode = this.querySelector('[slot="invoker"]'); - this._tooltip = overlays.add( + this._controller = overlays.add( new LocalOverlayController({ hidesOnEsc: true, hidesOnOutsideClick: true, - placement: this.position, - contentNode: this.contenNode, + placementConfig: this.placementConfig, + contentNode: this.contentNode, invokerNode: this.invokerNode, }), ); - this._show = () => this._tooltip.show(); - this._hide = () => this._tooltip.hide(); + this._show = () => this._controller.show(); + this._hide = () => this._controller.hide(); this.invokerNode.addEventListener('mouseenter', this._show); this.invokerNode.addEventListener('mouseleave', this._hide); diff --git a/packages/tooltip/stories/index.stories.js b/packages/tooltip/stories/index.stories.js index b0226a7ea..ceb896325 100644 --- a/packages/tooltip/stories/index.stories.js +++ b/packages/tooltip/stories/index.stories.js @@ -1,4 +1,4 @@ -import { storiesOf, html } from '@open-wc/demoing-storybook'; +import { storiesOf, html, withKnobs, object, text } from '@open-wc/demoing-storybook'; import { css } from '@lion/core'; import '@lion/icon/lion-icon.js'; @@ -15,7 +15,7 @@ const tooltipDemoStyle = css` padding: 8px; } - .demo-box_positions { + .demo-box_placements { display: flex; flex-direction: column; width: 173px; @@ -40,6 +40,8 @@ const tooltipDemoStyle = css` background-color: black; border-radius: 4px; padding: 8px; + /* To display on top of elements with no z-index that are appear later in the DOM */ + z-index: 1; } @media (max-width: 480px) { @@ -50,6 +52,7 @@ const tooltipDemoStyle = css` `; storiesOf('Local Overlay System|Tooltip', module) + .addDecorator(withKnobs) .add( 'Button tooltip', () => html` @@ -57,36 +60,73 @@ storiesOf('Local Overlay System|Tooltip', module) ${tooltipDemoStyle}
- -
hey there
+ +
Hello there!
Tooltip
`, ) .add( - 'positions', + 'placements', () => html` -
- -
Its top position
+
+ +
Its top placement
Top
- -
Its right position
+ +
Its right placement
Right
- -
Its bottom position
+ +
Its bottom placement
Bottom
- -
Its left position
+ +
Its left placement
Left
`, + ) + .add( + 'Override placement configuration', + () => html` + +

Use the Storybook Knobs to dynamically change the placement configuration!

+
+ +
${text('Content text', 'Hello, World!')}
+ ${text('Invoker text', 'Click me!')} +
+
+ `, ); diff --git a/packages/tooltip/test/lion-tooltip.test.js b/packages/tooltip/test/lion-tooltip.test.js index 198b7ed80..1965abd23 100644 --- a/packages/tooltip/test/lion-tooltip.test.js +++ b/packages/tooltip/test/lion-tooltip.test.js @@ -25,6 +25,7 @@ describe('lion-tooltip', () => { const eventMouseEnter = new Event('mouseenter'); invoker.dispatchEvent(eventMouseEnter); await el.updateComplete; + await aTimeout(); expect(el.querySelector('[slot="content"]').style.display).to.be.equal('inline-block'); const eventMouseLeave = new Event('mouseleave'); invoker.dispatchEvent(eventMouseLeave);