Skip to content
Snippets Groups Projects
icon.js 2.25 KiB
Newer Older
import {html, LitElement, css} from 'lit';
import * as commonUtils from '../utils.js';
import {name as pkgName} from './../package.json';
export function getIconSVGURL(name) {
    return commonUtils.getAssetURL(pkgName, 'icons/' + encodeURI(name) + '.svg');
}

export function getIconCSS(name) {
    const iconURL = getIconSVGURL(name);
    return `
        background-color: currentColor;
Reiter, Christoph's avatar
Reiter, Christoph committed
        mask-image: url(${iconURL});
        -webkit-mask-image: url(${iconURL});
        mask-size: contain;
        -webkit-mask-size: contain;
        mask-repeat: no-repeat;
        -webkit-mask-repeat: no-repeat;
        mask-position: center center;
        -webkit-mask-position: center center;
        margin-left: 0.2em;
        padding-left: 0.3em;
 * For icon names see https://lineicons.com
    constructor() {
        super();
Reiter, Christoph's avatar
Reiter, Christoph committed
        this.name = 'bolt';
    }

    static get properties() {
Reiter, Christoph's avatar
Reiter, Christoph committed
        return {
            name: {type: String},

    static get styles() {
        return css`
            :host {
                display: inline-block;
                height: 1em;
Reiter, Christoph's avatar
Reiter, Christoph committed
                top: 0.125em;
                position: relative;
            }

            #svg {
                height: 100%;
                width: 100%;
                background-repeat: no-repeat;
                background-position: center;
                background-color: currentColor;
                mask-repeat: no-repeat;
                mask-position: center;
                mask-size: 100% 100%;
                -webkit-mask-repeat: no-repeat;
                -webkit-mask-position: center;
                -webkit-mask-size: 100% 100%;
                
        const iconURL = getIconSVGURL(this.name);
        const iconPart = this.name.trim().split(' ').join('');
        return html`
                    -webkit-mask-image: var(--dbp-override-icon-${iconPart}, url(${iconURL}));
                    mask-image: var(--dbp-override-icon-${iconPart}, url(${iconURL}));
                }
            </style>
            <div id="svg"></div>