UNPKG

@diondre27/smart-components

Version:

Smart Web Components

56 lines (51 loc) 1.69 kB
import { r as registerInstance, h, g as getAssetPath, H as Host } from './core-7cea914b.js'; const SmtButton = class { constructor(hostRef) { registerInstance(this, hostRef); } render() { return (h("div", { class: "container" }, h("div", { class: "row" }, h("button", { type: "button", class: "btn btn-primary" }, this.buttonText)))); } }; const requests = new Map(); const getSvgContent = (url) => { // see if we already have a request for this url let req = requests.get(url); if (!req) { // we don't already have a request req = fetch(url).then(rsp => { if (rsp.status <= 299) { return rsp.text(); } console.warn('Icon not found'); return Promise.resolve(null); }); // cache for the same requests requests.set(url, req); } return req; }; const SmartIcons = class { constructor(hostRef) { registerInstance(this, hostRef); } connectedCallback() { this.loadIcon(); } loadIcon() { const svg = `svg/smart-${this.icon}.svg`; const url = getAssetPath(svg); if (this.icon) { getSvgContent(url).then(content => (this.svgContent = content)); } } render() { return (h(Host, { role: "img" }, this.svgContent ? (h("div", { innerHTML: this.svgContent })) : (h("div", null)))); } static get assetsDirs() { return ["svg"]; } static get watchers() { return { "icon": ["loadIcon"] }; } static get style() { return ":host{display:block}"; } }; export { SmtButton as smart_button, SmartIcons as smart_icon };