2020-07-01 15:51:21 +02:00
|
|
|
/**
|
|
|
|
* @copyright Alfredo Medrano Sánchez and the Converse.js contributors
|
|
|
|
* @description
|
|
|
|
* Component inspired by the one from fa-icons
|
|
|
|
* https://github.com/obsidiansoft-io/fa-icons/blob/master/LICENSE
|
|
|
|
* @license Mozilla Public License (MPLv2)
|
|
|
|
*/
|
|
|
|
|
2021-08-06 13:38:12 +02:00
|
|
|
import { html } from 'lit';
|
2020-07-01 15:51:21 +02:00
|
|
|
import { CustomElement } from './element.js';
|
|
|
|
|
2021-08-06 13:38:12 +02:00
|
|
|
import './styles/icon.scss';
|
|
|
|
|
2020-07-01 15:51:21 +02:00
|
|
|
|
|
|
|
class ConverseIcon extends CustomElement {
|
|
|
|
|
|
|
|
static get properties () {
|
|
|
|
return {
|
|
|
|
color: String,
|
|
|
|
class_name: { attribute: "class" },
|
|
|
|
style: String,
|
|
|
|
size: String
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor () {
|
|
|
|
super();
|
|
|
|
this.class_name = "";
|
|
|
|
this.style = "";
|
|
|
|
this.size = "";
|
|
|
|
this.color = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
getSource () {
|
2021-11-14 09:09:58 +01:00
|
|
|
return `#icon-${this.class_name.trim().split(" ")[1].replace("fa-", "")}`;
|
2020-07-01 15:51:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getStyles () {
|
2021-07-26 19:27:59 +02:00
|
|
|
const cssprop = this.color.match(/var\((--.*)\)/)?.[1];
|
|
|
|
const color = cssprop ? getComputedStyle(this).getPropertyValue(cssprop) : this.color;
|
2020-07-01 15:51:21 +02:00
|
|
|
return `
|
|
|
|
${this.size ? `width: ${this.size};` : ''}
|
|
|
|
${this.size ? `height: ${this.size};` : ''}
|
2021-07-26 19:27:59 +02:00
|
|
|
${color ? `fill: ${color};` : ''}
|
2020-07-01 15:51:21 +02:00
|
|
|
${this.style}
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return html`<svg .style="${this.getStyles()}"> <use href="${this.getSource()}"> </use> </svg>`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("converse-icon", ConverseIcon);
|