@larva.io/webcomponents
Version:
Fentrica SmartUnits WebComponents package
186 lines (185 loc) • 6.07 kB
JavaScript
/*!
* (C) Fentrica http://fentrica.com - Seee LICENSE.md
*/
import { h } from "@stencil/core";
export class RadioButtonContent {
constructor() {
this.radios = [];
}
getRadios() {
if (typeof this.radios === 'string') {
try {
return JSON.parse(this.radios);
}
catch (e) {
return [];
}
}
return Array.isArray(this.radios) ? this.radios : [];
}
getSelected() {
const selected = typeof this.selected === 'string' ? parseInt(this.selected, 10) : this.selected;
return isNaN(selected) ? undefined : selected;
}
render() {
const selectors = [];
const radios = this.getRadios();
const selected = this.getSelected();
if (!radios || !Array.isArray(radios) || selected === undefined) {
return selectors;
}
for (let i = 0; i < radios.length; i++) {
if (!radios[i] || !radios[i].name) {
continue;
}
const option = radios[i].name;
const secondaryColor = this.color === 'dark' ? 'light' : 'dark';
const color = (i === selected) ? this.color : secondaryColor;
selectors.push(h("lar-button", { expand: "full", color: color, disabled: this.disabled, onClick: () => this.selectoption.emit(i) }, h("lar-translate", { t: option })));
}
return h("div", { class: "radios" }, selectors);
}
static get is() { return "lar-radio-button-content"; }
static get encapsulation() { return "scoped"; }
static get originalStyleUrls() {
return {
"$": ["radio-button.scss"]
};
}
static get styleUrls() {
return {
"$": ["radio-button.css"]
};
}
static get properties() {
return {
"color": {
"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": ""
},
"getter": false,
"setter": false,
"reflect": false,
"attribute": "color"
},
"disabled": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"reflect": false,
"attribute": "disabled"
},
"value": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"reflect": false,
"attribute": "value"
},
"radios": {
"type": "string",
"mutable": false,
"complexType": {
"original": "RadioData[] | string",
"resolved": "RadioData[] | string",
"references": {
"RadioData": {
"location": "import",
"path": "./radio-button-interface",
"id": "src/components/radio-button/radio-button-interface.tsx::RadioData"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"reflect": false,
"attribute": "radios",
"defaultValue": "[]"
},
"selected": {
"type": "any",
"mutable": false,
"complexType": {
"original": "number | string",
"resolved": "number | string",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"reflect": false,
"attribute": "selected"
}
};
}
static get events() {
return [{
"method": "selectoption",
"name": "selectoption",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "number",
"resolved": "number",
"references": {}
}
}];
}
}
//# sourceMappingURL=radio-button-content.js.map