UNPKG

@securecall/client-component

Version:

SecureCall Core Web Component

141 lines (140 loc) 5.59 kB
import { Host, h, forceUpdate } from "@stencil/core"; import { Logger } from "../../utils/logger"; export class SecurecallRequestString { 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 is() { return "securecall-request-string"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["securecall-request-string.css"] }; } static get styleUrls() { return { "$": ["securecall-request-string.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": {} } }]; } static get watchers() { return [{ "propName": "config", "methodName": "handleConfigChange" }]; } } //# sourceMappingURL=securecall-request-string.js.map