@securecall/client-component
Version:
SecureCall Core Web Component
69 lines (65 loc) • 3.49 kB
JavaScript
import { r as registerInstance, c as createEvent, h, H as Host } from './index-CHf4eHvJ.js';
import { L as Logger } from './logger-CgjdSc_8.js';
const securecallRequestSelectCss = ":host{display:block}.field-container{display:grid;grid-template-columns:10em 1fr 20px;align-items:center;gap:1rem}.custom-label{color:var(--theme-primary-color);text-align:right;align-items:center;font-weight:bold;gap:0.5rem}.custom-select{padding:0.2rem;border:1px solid var(--theme-secondary-color);border-radius:4px;font-size:1rem;background-color:var(--theme-input-active-background)}";
const SecurecallRequestSelect = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.isValidEvent = createEvent(this, "isValidEvent");
this.changed = createEvent(this, "changed");
}
fieldName;
config;
isValidEvent;
log = 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: 'bacd866cd442d114e13275e7281ee9721f39c3ea' }, h("div", { key: 'da69e70ab782a9ff504dca671e571834c9f40818', class: "field-container" }, h("label", { key: 'bf50ef84ca47511e90042544b00f2459415cac38', class: "custom-label" }, this.config["label"], ":"), h("select", { key: 'f466798b577aa3c67e1d95e69c939ec9102199bf', 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: 'f8382bcc86d5b949617dfb60e3f7f2ac9e2d8030', class: "validity none" }))));
}
static get watchers() { return {
"config": ["handleConfigChange"]
}; }
};
SecurecallRequestSelect.style = securecallRequestSelectCss;
export { SecurecallRequestSelect as securecall_request_select };
//# sourceMappingURL=securecall-request-select.entry.js.map
//# sourceMappingURL=securecall-request-select.entry.js.map