Co-authored-by: Thomas Allmer <Thomas.Allmer@ing.com> Co-authored-by: Joren Broekema <Joren.Broekema@ing.com> Co-authored-by: Mikhail Bashkirov <Mikhail.Bashkirov@ing.com> Co-authored-by: Alex Ghiu <Alex.Ghiu@ing.com>
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
import { LionPopup } from '@lion/popup';
|
|
|
|
export class LionTooltip extends LionPopup {
|
|
constructor() {
|
|
super();
|
|
this.mouseActive = false;
|
|
this.keyActive = false;
|
|
}
|
|
|
|
connectedCallback() {
|
|
super.connectedCallback();
|
|
this._overlayContentNode.setAttribute('role', 'tooltip');
|
|
|
|
this.__resetActive = () => {
|
|
this.mouseActive = false;
|
|
this.keyActive = false;
|
|
};
|
|
|
|
this.__showMouse = () => {
|
|
if (!this.keyActive) {
|
|
this.mouseActive = true;
|
|
this._overlayCtrl.show();
|
|
}
|
|
};
|
|
|
|
this.__hideMouse = () => {
|
|
if (!this.keyActive) {
|
|
this._overlayCtrl.hide();
|
|
}
|
|
};
|
|
|
|
this.__showKey = () => {
|
|
if (!this.mouseActive) {
|
|
this.keyActive = true;
|
|
this._overlayCtrl.show();
|
|
}
|
|
};
|
|
|
|
this.__hideKey = () => {
|
|
if (!this.mouseActive) {
|
|
this._overlayCtrl.hide();
|
|
}
|
|
};
|
|
|
|
this._overlayCtrl.addEventListener('hide', this.__resetActive);
|
|
this.addEventListener('mouseenter', this.__showMouse);
|
|
this.addEventListener('mouseleave', this.__hideMouse);
|
|
this._overlayInvokerNode.addEventListener('focusin', this.__showKey);
|
|
this._overlayInvokerNode.addEventListener('focusout', this.__hideKey);
|
|
}
|
|
|
|
disconnectedCallback() {
|
|
super.disconnectedCallback();
|
|
this._overlayCtrl.removeEventListener('hide', this.__resetActive);
|
|
this.removeEventListener('mouseenter', this.__showMouse);
|
|
this.removeEventListener('mouseleave', this._hideMouse);
|
|
this._overlayInvokerNode.removeEventListener('focusin', this._showKey);
|
|
this._overlayInvokerNode.removeEventListener('focusout', this._hideKey);
|
|
}
|
|
}
|