@kelvininc/ui-components
Version:
Kelvin UI Components
193 lines (192 loc) • 7.21 kB
JavaScript
import { h, Host } from "@stencil/core";
import { EComponentSize } from "../../types";
/**
* @part toggle-switch-option-container - Container of toggle options.
*/
export class KvToggleSwitch {
constructor() {
/** @inheritdoc */
this.options = [];
/** @inheritdoc */
this.disabled = false;
/** @inheritdoc */
this.size = EComponentSize.Small;
/** @inheritdoc */
this.selectedOption = '';
/** @inheritdoc */
this.disabledButtons = {};
}
render() {
return (h(Host, { key: '94071d84c6043b263c17e3a912c8198ae27e809b' }, h("div", { key: '3fbb05bd6df3229bb8b259865439f281d37da47e', class: "toggle-switch-container" }, this.options.map(option => {
var _a;
return (h("kv-toggle-button", { part: "toggle-switch-option-container", exportparts: "toggle-button", value: option.value, label: option.label, icon: option.icon, preventDefault: option.preventDefault, size: (_a = this.size) !== null && _a !== void 0 ? _a : option.size, disabled: this.disabled || this.disabledButtons[option.value] || option.disabled, checked: this.selectedOption === option.value }));
}))));
}
static get is() { return "kv-toggle-switch"; }
static get encapsulation() { return "shadow"; }
static get originalStyleUrls() {
return {
"$": ["toggle-switch.scss"]
};
}
static get styleUrls() {
return {
"$": ["toggle-switch.css"]
};
}
static get properties() {
return {
"options": {
"type": "unknown",
"attribute": "options",
"mutable": false,
"complexType": {
"original": "IToggleSwitchOption[]",
"resolved": "IToggleSwitchOption[]",
"references": {
"IToggleSwitchOption": {
"location": "import",
"path": "./toggle-switch.types",
"id": "src/components/toggle-switch/toggle-switch.types.ts::IToggleSwitchOption"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [{
"name": "inheritdoc",
"text": undefined
}],
"text": "(optional) List of toggle switch options"
},
"getter": false,
"setter": false,
"defaultValue": "[]"
},
"disabled": {
"type": "boolean",
"attribute": "disabled",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [{
"name": "inheritdoc",
"text": undefined
}],
"text": "(optional) If `true` all toggle buttons will be disabled"
},
"getter": false,
"setter": false,
"reflect": true,
"defaultValue": "false"
},
"size": {
"type": "string",
"attribute": "size",
"mutable": false,
"complexType": {
"original": "EComponentSize",
"resolved": "EComponentSize.Large | EComponentSize.Small",
"references": {
"EComponentSize": {
"location": "import",
"path": "../../types",
"id": "src/types.ts::EComponentSize"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [{
"name": "inheritdoc",
"text": undefined
}],
"text": "(optional) Sets the size for all toggle buttons"
},
"getter": false,
"setter": false,
"reflect": true,
"defaultValue": "EComponentSize.Small"
},
"selectedOption": {
"type": "string",
"attribute": "selected-option",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [{
"name": "inheritdoc",
"text": undefined
}],
"text": "(optional) Toggle switch selected option key"
},
"getter": false,
"setter": false,
"reflect": true,
"defaultValue": "''"
},
"disabledButtons": {
"type": "unknown",
"attribute": "disabled-buttons",
"mutable": false,
"complexType": {
"original": "Record<string, boolean>",
"resolved": "{ [x: string]: boolean; }",
"references": {
"Record": {
"location": "global",
"id": "global::Record"
}
}
},
"required": false,
"optional": true,
"docs": {
"tags": [{
"name": "inheritdoc",
"text": undefined
}],
"text": "(optional) A record with the button's key and its individual disabled state"
},
"getter": false,
"setter": false,
"defaultValue": "{}"
}
};
}
static get events() {
return [{
"method": "checkedChange",
"name": "checkedChange",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [{
"name": "inheritdoc",
"text": undefined
}],
"text": "When the toggle switch selection changes, emit the requested value"
},
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
}
}];
}
}