@diondre27/smart-components
Version:
Smart Web Components
61 lines (54 loc) • 1.78 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
const core = require('./core-3bf196d3.js');
const SmtButton = class {
constructor(hostRef) {
core.registerInstance(this, hostRef);
}
render() {
return (core.h("div", { class: "container" }, core.h("div", { class: "row" }, core.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) {
core.registerInstance(this, hostRef);
}
connectedCallback() {
this.loadIcon();
}
loadIcon() {
const svg = `svg/smart-${this.icon}.svg`;
const url = core.getAssetPath(svg);
if (this.icon) {
getSvgContent(url).then(content => (this.svgContent = content));
}
}
render() {
return (core.h(core.Host, { role: "img" }, this.svgContent ? (core.h("div", { innerHTML: this.svgContent })) : (core.h("div", null))));
}
static get assetsDirs() { return ["svg"]; }
static get watchers() { return {
"icon": ["loadIcon"]
}; }
static get style() { return ":host{display:block}"; }
};
exports.smart_button = SmtButton;
exports.smart_icon = SmartIcons;