@securecall/client-component
Version:
SecureCall Core Web Component
151 lines (150 loc) • 5.97 kB
JavaScript
import { Host, h } from "@stencil/core";
import { Logger } from "../../utils/logger";
export class SecurecallRequestSelect {
fieldName;
config;
isValidEvent;
log = new Logger('SecurecallRequestSelect');
selectElement;
changed;
get value() {
return this.config.value;
}
set value(value) {
if (this.config.value !== value) {
this.config.value = value;
this.validateChange();
}
}
handleConfigChange(newConfig, oldConfig) {
this.log.debug(this.fieldName + ": handleConfigChange: config", newConfig, oldConfig);
if (oldConfig.value !== newConfig.value) {
this.value = newConfig.value;
this.validateChange();
if (this.selectElement)
this.selectElement.value = this.value;
}
else if (oldConfig.valid !== newConfig.valid) {
this.validateChange();
}
}
componentWillLoad() {
this.log.debug(this.fieldName + ": componentWillLoad: config", this.config);
if (this.config.value === undefined)
this.value = Object.entries(this.config.possibleValues)[0][0] || '';
this.validateChange();
}
handleChange(ev) {
this.log.debug(this.fieldName + ": handleChange: select change:", ev.target.value);
this.value = ev.target.value;
}
validateChange() {
const input = this.value;
let isValid = false;
if (input && input.length > 0) {
isValid = true;
}
this.isValidEvent.emit({ field: this.fieldName, valid: isValid, value: input });
}
render() {
return (h(Host, { key: 'bf4aa30394d253ad120d6e82557835d27ecdc7a5' }, h("div", { key: 'fc1641d05b1eb681050625db293858d4a3c48d42', class: "field-container" }, h("label", { key: '97846cf246e9ced0c4b4bac1a0550451b7516c7a', class: "custom-label" }, this.config["label"], ":"), h("select", { key: '6c2daa0379cb8c23010cda56adf91f9bc9eccfb3', class: "custom-select", id: this.fieldName, disabled: this.config.readOnly, onChange: (ev) => this.handleChange(ev), ref: (el) => this.selectElement = el }, typeof this.config.possibleValues === 'object' && this.config.possibleValues !== null ? (Object.entries(this.config.possibleValues).map(([key, val]) => (h("option", { value: key, selected: key === this.value }, val)))) : null), h("div", { key: 'bcabc83fa9ef3313c5c9cd1d288cf4d1898f0f99', class: "validity none" }))));
}
static get is() { return "securecall-request-select"; }
static get encapsulation() { return "shadow"; }
static get originalStyleUrls() {
return {
"$": ["securecall-request-select.css"]
};
}
static get styleUrls() {
return {
"$": ["securecall-request-select.css"]
};
}
static get properties() {
return {
"fieldName": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"reflect": false,
"attribute": "field-name"
},
"config": {
"type": "unknown",
"mutable": true,
"complexType": {
"original": "IRequestField",
"resolved": "{ hidden?: boolean; label?: string; value?: string; max?: number; min?: number; placeholder?: string; readOnly?: boolean; order?: number; component?: string; valid?: boolean; possibleValues?: Record<string, string>; mapping?: string; externalMapping?: string; active?: boolean; hideRelatedFields?: Record<string, object>; secure?: boolean; optional?: boolean; }",
"references": {
"IRequestField": {
"location": "import",
"path": "../../interfaces/configuration",
"id": "src/interfaces/configuration.ts::IRequestField"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false
}
};
}
static get events() {
return [{
"method": "isValidEvent",
"name": "isValidEvent",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "{ field: string; valid: boolean, value: string }",
"resolved": "{ field: string; valid: boolean; value: string; }",
"references": {}
}
}, {
"method": "changed",
"name": "changed",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
}
}];
}
static get watchers() {
return [{
"propName": "config",
"methodName": "handleConfigChange"
}];
}
}
//# sourceMappingURL=securecall-request-select.js.map