import {OOElement} from '../../oo-element' import {html} from '../../../lib/html' type Position = 'left' | 'right' | 'center' const ATTR = { DATA_TOOLTIP_POSITION: 'data-tooltip-position' } const asValidString = (data: string): Position => { if (data === 'left' || data === 'right' || data === 'center') { return data } return 'left' } const tooltipPosition: WeakMap = new WeakMap() export default class extends OOElement { static get observedAttributes() { return [ATTR.DATA_TOOLTIP_POSITION] } constructor() { super() tooltipPosition.set(this, asValidString(this.getAttribute(ATTR.DATA_TOOLTIP_POSITION))) } attributeChangedCallback(attr, prev, next) { if (prev === next) { return } tooltipPosition.set(this, asValidString(next)) if (this.connected) { this.update() } } render() { const position = tooltipPosition.get(this) return html`
` } }