UNPKG

@securecall/client-component

Version:

SecureCall Core Web Component

66 lines (62 loc) 3.61 kB
import { r as registerInstance, c as createEvent, f as forceUpdate, h, F as Fragment, H as Host } from './index-KxdoBBDC.js'; import { L as Logger } from './logger-By6Qn8nU.js'; const securecallRequestRadioCss = ":host{display:block}.radio-label{color:var(--theme-primary-color);text-align:right;align-items:center;gap:0.5rem;margin-right:1rem}.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}.radio-input{margin-right:0.2rem}"; const SecurecallRequestRadio = class { constructor(hostRef) { registerInstance(this, hostRef); this.requestRadioChangeEvent = createEvent(this, "requestRadioChangeEvent"); this.isValidEvent = createEvent(this, "isValidEvent"); } fieldName; config; requestRadioChangeEvent; isValidEvent; log = new Logger('SecurecallRequestRadio'); get value() { return this.config.value; } set value(value) { this.config.value = value; this.handleLocalStorageChange(); } handleConfigChange(newConfig, oldConfig) { this.log.debug(this.fieldName + ": handleConfigChange: config", newConfig, oldConfig); if (oldConfig.value !== newConfig.value) { this.value = newConfig.value; } else if (oldConfig.valid !== newConfig.valid) { this.validateChange(this.value); } } componentWillLoad() { // Trigger the first time we are loaded so the other fields can be hidden/revealed this.requestRadioChangeEvent.emit({ field: this.fieldName, value: this.value }); this.validateChange(this.value); } handleLocalStorageChange() { this.log.debug("handleChangeFromLocalStorage: string change:", this.value); this.requestRadioChangeEvent.emit({ field: this.fieldName, value: this.value }); this.validateChange(this.value); forceUpdate(this); } handleChange(ev) { this.log.debug("handleChange: string change:", ev.target.value); this.requestRadioChangeEvent.emit({ field: this.fieldName, value: ev.target.value }); this.validateChange(ev.target.value); } validateChange(input) { let isValid = false; if (this.config.possibleValues?.[input] !== undefined) isValid = true; this.isValidEvent.emit({ field: this.fieldName, valid: isValid, value: input }); } render() { return (h(Host, { key: 'f625ce2cb89fafa03508df307374845003086bee' }, h("div", { key: '617f29ccd25742580c1b31bedf88b699902435be', class: "field-container" }, h("label", { key: 'cb30d893bfa51943f507dc4e6d8bb7daee9bb41b', class: "custom-label", htmlFor: this.fieldName }, this.config.label, ":"), h("div", { key: 'f4c3bd88b4dcfaf95181808bf96c403c602a460f', class: "radio-group" }, Object.entries(this.config.possibleValues || {}).map(([val, label], _index) => (h(Fragment, null, h("input", { class: "radio-input", type: "radio", name: this.fieldName, id: this.fieldName + "-" + val, value: val, checked: val === this.config.value, onChange: (ev) => this.handleChange(ev), disabled: this.config.readOnly }), h("label", { class: "radio-label", htmlFor: this.fieldName + "-" + val }, label)))))))); } static get watchers() { return { "config": ["handleConfigChange"] }; } }; SecurecallRequestRadio.style = securecallRequestRadioCss; export { SecurecallRequestRadio as securecall_request_radio }; //# sourceMappingURL=securecall-request-radio.entry.js.map