Skip to content
Snippets Groups Projects
tooltip.js 2.05 KiB
Newer Older
import {css, html} from 'lit-element';
import {ScopedElementsMixin} from '@open-wc/scoped-elements';
import * as commonUtils from '@dbp-toolkit/common/utils';
import * as commonStyles from '@dbp-toolkit/common/styles';
import DBPLitElement from '@dbp-toolkit/common/dbp-lit-element';
import tippy from 'tippy.js';
import {Icon} from '@dbp-toolkit/common';
import tippy2CSSPath from 'tippy.js/dist/tippy.css';
export class TooltipElement extends ScopedElementsMixin(DBPLitElement) {
        this.tippy = '';
        this.textContent = '';
    static get scopedElements() {
        return {
            'dbp-icon': Icon,
        };
    }

    static get properties() {
        return {
            ...super.properties,
            tippy: { type: Object, attribute: false },
            textContent: { type: String, attribute: 'text-content' },
            iconName: { type: String, attribute: 'icon-name' },
    firstUpdated() {

        tippy(this._('#tooltip-icon'), {
            content: this.textContent,
            appendTo: this.shadowRoot,
        });
    }

    static get styles() {
        // language=css
        return css`
            ${commonStyles.getThemeCSS()}
            ${commonStyles.getGeneralCSS(false)}
            ${commonStyles.getButtonCSS()}

                display: inline;
                /* color: TODO CSS var */
                /* opacity: 0.7; TODO CSS var */

        const tippy2CSS = commonUtils.getAssetURL(tippy2CSSPath);
       
        if (this._('#tooltip-icon')) {
            this.tippy = tippy(this._('#tooltip-icon'), { content: this.textContent });
        }
            <link rel="stylesheet" href="${tippy2CSS}">
                <!-- https://icons.getbootstrap.com/icons/info-circle/ -->
                <dbp-icon name="${this.iconName}" id="tooltip-icon"></dbp-icon>