@diondre27/smart-components
Version:
Smart Web Components
69 lines (68 loc) • 2.34 kB
JavaScript
import { r as registerInstance, h, g as getAssetPath, H as Host } from './core-7cea914b.js';
var SmtButton = /** @class */ (function () {
function SmtButton(hostRef) {
registerInstance(this, hostRef);
}
SmtButton.prototype.render = function () {
return (h("div", { class: "container" }, h("div", { class: "row" }, h("button", { type: "button", class: "btn btn-primary" }, this.buttonText))));
};
return SmtButton;
}());
var requests = new Map();
var getSvgContent = function (url) {
// see if we already have a request for this url
var req = requests.get(url);
if (!req) {
// we don't already have a request
req = fetch(url).then(function (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;
};
var SmartIcons = /** @class */ (function () {
function SmartIcons(hostRef) {
registerInstance(this, hostRef);
}
SmartIcons.prototype.connectedCallback = function () {
this.loadIcon();
};
SmartIcons.prototype.loadIcon = function () {
var _this = this;
var svg = "svg/smart-" + this.icon + ".svg";
var url = getAssetPath(svg);
if (this.icon) {
getSvgContent(url).then(function (content) { return (_this.svgContent = content); });
}
};
SmartIcons.prototype.render = function () {
return (h(Host, { role: "img" }, this.svgContent ? (h("div", { innerHTML: this.svgContent })) : (h("div", null))));
};
Object.defineProperty(SmartIcons, "assetsDirs", {
get: function () { return ["svg"]; },
enumerable: true,
configurable: true
});
Object.defineProperty(SmartIcons, "watchers", {
get: function () {
return {
"icon": ["loadIcon"]
};
},
enumerable: true,
configurable: true
});
Object.defineProperty(SmartIcons, "style", {
get: function () { return ":host{display:block}"; },
enumerable: true,
configurable: true
});
return SmartIcons;
}());
export { SmtButton as smart_button, SmartIcons as smart_icon };