@securecall/client-component
Version:
SecureCall Core Web Component
98 lines (93 loc) • 4.59 kB
JavaScript
import { p as proxyCustomElement, H, c as createEvent, f as forceUpdate, h, d as Host } from './p-0D76SiW-.js';
import { L as Logger } from './p-By6Qn8nU.js';
const securecallRequestStringCss = ":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-input{padding:0.2rem;border:1px solid #ccc;border-radius:4px;font-size:1rem}.field-invalid{background-color:var(--theme-primary-color);-webkit-mask:var(--icon-invalid);mask:var(--icon-invalid);height:1.0rem;width:1.0rem}.field-valid{background-color:var(--theme-primary-color);-webkit-mask:var(--icon-valid);mask:var(--icon-valid);height:1.0rem;width:1.0rem}";
const SecurecallRequestString$1 = /*@__PURE__*/ proxyCustomElement(class SecurecallRequestString extends H {
constructor(registerHost) {
super();
if (registerHost !== false) {
this.__registerHost();
}
this.__attachShadow();
this.isValidEvent = createEvent(this, "isValidEvent");
}
fieldName;
config;
isValidEvent;
log = new Logger('SecurecallRequestString');
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();
}
else if (oldConfig.valid !== newConfig.valid) {
this.validateChange();
}
}
componentWillLoad() {
this.log.debug(this.fieldName + ": componentWillLoad: config", this.config);
this.validateChange();
}
handleChange(ev) {
this.log.debug(this.fieldName + ": handleChange: string change:", ev.target.value);
this.value = ev.target.value;
}
validateChange() {
let input = this.value;
this.log.debug(this.fieldName + ": validateChange: string:", input);
let isValid = false;
if (this.config.optional && (!input || input.trim() === '')) {
isValid = true;
input = '';
}
else {
const minLength = this.config.min || 1;
const maxLength = this.config.max;
isValid = input?.length >= minLength && (!maxLength || input.length <= maxLength);
}
if (this.config.valid !== isValid) {
this.config.valid = isValid;
forceUpdate(this);
}
this.isValidEvent.emit({ field: this.fieldName, valid: isValid, value: input });
}
render() {
return (h(Host, { key: '4a85bda081774d79ad9741d907b43a789c2da216' }, h("div", { key: 'c929b17cede5db4e19ea4472e5b24416119027d9', class: "field-container" }, h("label", { key: '64a0f6a89fca43a0164b13591d167859c00dcfa4', class: "custom-label" }, this.config.label, ":"), h("input", { key: 'c17c58bca84f13869a83fb8127027312aff944f7', type: "text", class: "custom-input", id: this.fieldName, placeholder: this.config.placeholder || this.config.label, value: this.value, disabled: this.config.readOnly, onInput: (ev) => this.handleChange(ev) }), h("div", { key: 'd74e8fb6aecb615228156b5c900ec63ab9a8d5ec', class: this.config.valid ? 'field-valid' : 'field-invalid' }))));
}
static get watchers() { return {
"config": ["handleConfigChange"]
}; }
static get style() { return securecallRequestStringCss; }
}, [257, "securecall-request-string", {
"fieldName": [1, "field-name"],
"config": [1040]
}, undefined, {
"config": ["handleConfigChange"]
}]);
function defineCustomElement$1() {
if (typeof customElements === "undefined") {
return;
}
const components = ["securecall-request-string"];
components.forEach(tagName => { switch (tagName) {
case "securecall-request-string":
if (!customElements.get(tagName)) {
customElements.define(tagName, SecurecallRequestString$1);
}
break;
} });
}
const SecurecallRequestString = SecurecallRequestString$1;
const defineCustomElement = defineCustomElement$1;
export { SecurecallRequestString, defineCustomElement };
//# sourceMappingURL=securecall-request-string.js.map
//# sourceMappingURL=securecall-request-string.js.map