UNPKG

@larva.io/webcomponents

Version:

Fentrica SmartUnits WebComponents package

455 lines (454 loc) 16 kB
/*! * (C) Fentrica http://fentrica.com - Seee LICENSE.md */ import { h } from "@stencil/core"; import moment from "moment"; import isObject from "lodash-es/isObject"; export class UtilityMeter { constructor() { /////// 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 !== moment().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; } default: // 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' })) ]; } static get is() { return "lar-utility-meter"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["utility-meter.scss"] }; } static get styleUrls() { return { "$": ["utility-meter.css"] }; } static get properties() { return { "icon": { "type": "string", "mutable": true, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Component main icon" }, "getter": false, "setter": false, "reflect": false, "attribute": "icon", "defaultValue": "'chart-bar'" }, "color": { "type": "string", "mutable": true, "complexType": { "original": "Color", "resolved": "string", "references": { "Color": { "location": "import", "path": "../../interface", "id": "src/interface.d.ts::Color" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "The color to use from your application's color palette.\nDetrouble options are: `\"primary\"`, `\"secondary\"`, `\"tertiary\"`, `\"success\"`, `\"warning\"`, `\"danger\"`, `\"light\"`, `\"medium\"`, and `\"dark\"`." }, "getter": false, "setter": false, "reflect": false, "attribute": "color", "defaultValue": "'primary'" }, "colorModal": { "type": "string", "mutable": true, "complexType": { "original": "Color", "resolved": "string", "references": { "Color": { "location": "import", "path": "../../interface", "id": "src/interface.d.ts::Color" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "The color to use from your application's color palette for Components modal window." }, "getter": false, "setter": false, "reflect": false, "attribute": "color-modal" }, "colorInputs": { "type": "string", "mutable": true, "complexType": { "original": "Color", "resolved": "string", "references": { "Color": { "location": "import", "path": "../../interface", "id": "src/interface.d.ts::Color" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "The color to use from your application's color palette for inputs" }, "getter": false, "setter": false, "reflect": false, "attribute": "color-inputs" }, "colorIconSmall": { "type": "string", "mutable": false, "complexType": { "original": "Color", "resolved": "string", "references": { "Color": { "location": "import", "path": "../../interface", "id": "src/interface.d.ts::Color" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "The color to use from your application's color palette for indication icon" }, "getter": false, "setter": false, "reflect": false, "attribute": "color-icon-small" }, "hideTitles": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Hide node titles" }, "getter": false, "setter": false, "reflect": false, "attribute": "hide-titles" }, "supTitle": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Component superscript title" }, "getter": false, "setter": false, "reflect": false, "attribute": "sup-title" }, "subTitle": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Component subtitle" }, "getter": false, "setter": false, "reflect": false, "attribute": "sub-title" }, "log": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Is logging for this component enabled (lar-log subcomponent loaded)" }, "getter": false, "setter": false, "reflect": false, "attribute": "log", "defaultValue": "false" }, "mainTitle": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": true, "optional": false, "docs": { "tags": [], "text": "Component main title" }, "getter": false, "setter": false, "reflect": false, "attribute": "main-title" }, "nodeSize": { "type": "string", "mutable": false, "complexType": { "original": "Size", "resolved": "\"default\" | \"small\"", "references": { "Size": { "location": "import", "path": "../../interface", "id": "src/interface.d.ts::Size" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Node size" }, "getter": false, "setter": false, "reflect": false, "attribute": "node-size", "defaultValue": "'default'" } }; } static get states() { return { "loading": {}, "values": {} }; } static get events() { return [{ "method": "output", "name": "output", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [{ "name": "see", "text": "{@link ../readme.md} chapter \"Components input and output\" for further information." }], "text": "" }, "complexType": { "original": "any", "resolved": "any", "references": {} } }, { "method": "request", "name": "request", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [{ "name": "see", "text": "{@link ../readme.md} chapter \"Sub-Components requests and responses\" for further information." }], "text": "" }, "complexType": { "original": "any", "resolved": "any", "references": {} } }]; } static get methods() { return { "error": { "complexType": { "signature": "(data: any) => Promise<void>", "parameters": [{ "name": "data", "type": "any", "docs": "" }], "references": { "Promise": { "location": "global", "id": "global::Promise" } }, "return": "Promise<void>" }, "docs": { "text": "Larva error input", "tags": [] } }, "input": { "complexType": { "signature": "(state: UtilityMeterState) => Promise<void>", "parameters": [{ "name": "state", "type": "UtilityMeterState", "docs": "" }], "references": { "Promise": { "location": "global", "id": "global::Promise" }, "UtilityMeterState": { "location": "import", "path": "./utility-meter-interfaces", "id": "src/components/utility-meter/utility-meter-interfaces.tsx::UtilityMeterState" } }, "return": "Promise<void>" }, "docs": { "text": "Larva input message", "tags": [] } } }; } static get elementRef() { return "el"; } } //# sourceMappingURL=utility-meter.js.map