@larva.io/webcomponents
Version:
Fentrica SmartUnits WebComponents package
108 lines (104 loc) • 4 kB
JavaScript
/*!
* (C) Fentrica http://fentrica.com - Seee LICENSE.md
*/
import { r as registerInstance, c as createEvent, h, g as getElement } from './index-C4h1muVj.js';
import { h as hooks } from './moment-DAuPur-P.js';
import { i as isObject } from './isObject-C7eoH3L1.js';
const utilityMeterCss = "slot-fb[hidden],slot[hidden]{display:initial !important}";
const UtilityMeter = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.output = createEvent(this, "output");
this.request = createEvent(this, "request");
/////// LarvaNode base properties
/**
* Component main icon
*/
this.icon = 'chart-bar';
/**
* The color to use from your application's color palette.
* Detrouble options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`.
*/
this.color = 'primary';
/**
* Is logging for this component enabled (lar-log subcomponent loaded)
*/
this.log = false;
/**
* Node size
*/
this.nodeSize = 'default';
/////// LarvaNode base properties and events - end
this.loading = true;
this.values = [];
this.measuringUnit = '';
this.webComponentValueType = 'abs';
}
/**
* Larva error input
*/
async error(data) {
if (this.node) {
this.node.error(data);
}
this.loading = false;
}
/**
* Larva input message
*/
async input(state) {
this.loading = false;
if (isObject(state) && state.months) {
this.values = state.months;
// tslint:disable-next-line: strict-boolean-conditions
if (state.webComponentValueType) {
this.webComponentValueType = state.webComponentValueType;
}
// tslint:disable-next-line: strict-boolean-conditions
if (state.measuringUnit) {
this.measuringUnit = state.measuringUnit;
}
}
}
componentDidLoad() {
const el = this.el.shadowRoot || this.el;
this.node = el.querySelector('lar-node');
this.loading = true;
this.output.emit();
}
render() {
const months = this.values && Array.isArray(this.values) ? this.values : [];
let latestMonth = months.length > 0 ? months[0] : null;
if (latestMonth && latestMonth.date !== hooks().format('MM-YYYY')) {
latestMonth = null;
}
let value;
switch (this.webComponentValueType) {
case 'abs': {
if (latestMonth) {
value = `${latestMonth.abs}${this.measuringUnit}`;
}
break;
}
case 'rel': {
if (latestMonth) {
value = `${latestMonth.rel}${this.measuringUnit}`;
}
break;
}
// none
}
const componentProps = {
measuringUnit: this.measuringUnit,
webComponentValueType: this.webComponentValueType,
values: JSON.stringify(this.values)
};
return [
h("lar-node", { key: '4c80ddb0e20874f545b46ece6fcecd57792b905b', value: value, hideTitles: this.hideTitles, icon: this.icon, color: this.color, supTitle: this.supTitle, mainTitle: this.mainTitle, subTitle: this.subTitle, colorModal: this.colorModal, colorInputs: this.colorInputs, colorIconSmall: this.colorIconSmall, log: this.log, loading: this.loading, nodeSize: this.nodeSize, component: "lar-utility-log", componentProps: componentProps }, h("slot", { key: 'b62a3056f604be88b50df3d2caf9fae2a7fc5433' }))
];
}
get el() { return getElement(this); }
};
UtilityMeter.style = utilityMeterCss;
export { UtilityMeter as lar_utility_meter };
//# sourceMappingURL=lar-utility-meter.entry.js.map