File size: 785 Bytes
76a620b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class TooltipElement extends HTMLElement {
  connectedCallback() {
    this.attachShadow({ mode: 'open' });
    this.shadowRoot.innerHTML = `
      <style>
        :host {
          position: absolute;
          background: rgba(0,0,0,0.7);
          color: white;
          padding: 4px 8px;
          border-radius: 4px;
          font-size: 12px;
          pointer-events: none;
          z-index: 100;
          transform: translate(10px, 10px);
          display: none;
        }
      </style>
      <slot></slot>
    `;
  }

  show(x, y, text) {
    this.style.display = 'block';
    this.style.left = `${x}px`;
    this.style.top = `${y}px`;
    this.textContent = text;
  }

  hide() {
    this.style.display = 'none';
  }
}

customElements.define('tool-tip', TooltipElement);