UNPKG

@securecall/client-component

Version:

SecureCall Core Web Component

133 lines (132 loc) 5.29 kB
import { Host, h } from "@stencil/core"; import { Logger } from "../../utils/logger"; export class SecurecallRequestCurrency { fieldName; config; isValidEvent; log = Logger('SecurecallRequestCurrency'); get value() { return this.config.value; } set value(value) { if (this.config.value !== value) { this.config.value = value; this.handleLocalStorageChange(); } } handleConfigChange(newConfig, oldConfig) { if (oldConfig.value !== newConfig.value) { this.value = newConfig.value; this.validateChange(this.value); } else if (oldConfig.valid !== newConfig.valid) { this.validateChange(this.value); } } componentWillLoad() { this.validateChange(this.value); } handleLocalStorageChange() { this.log.debug("handleChangeFromLocalStorage: string change:", this.value); this.validateChange(this.value); } handleChange(ev) { this.log.debug("handleChange: string change:", ev.target.value); this.validateChange(ev.target.value); } validateChange(input) { const num = parseFloat(input); const isValidCurrency = /^(\d+(\.\d{1,2})?)?$/.test(input); const valid = !isNaN(num) && num !== 0 && isValidCurrency && num >= (this.config.min || 0.01) && num <= (this.config.max || 99999.99); this.isValidEvent.emit({ field: this.fieldName, valid: valid, value: input }); } render() { return (h(Host, { key: '3fe918e381fc22f1f64259dc341e602bc96b8828' }, h("div", { key: '460b5686e0ad353d695b8a1e0e1916b20757621c', class: "field-container" }, h("label", { key: '2391480757aec9e1644da01fe66af61c2ccf4c8b', class: "custom-label", htmlFor: this.fieldName }, this.config.label, ":"), h("input", { key: '087aca1b62588daee0da3c745aeaa5d9370093ad', 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: '1873c92d1c2c232b0a63782e52c0845311dd64e7', class: "validity none" })))); } static get is() { return "securecall-request-currency"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["securecall-request-currency.css"] }; } static get styleUrls() { return { "$": ["securecall-request-currency.css"] }; } static get properties() { return { "fieldName": { "type": "string", "attribute": "field-name", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "reflect": false }, "config": { "type": "unknown", "attribute": "config", "mutable": true, "complexType": { "original": "IRequestField", "resolved": "{ label?: string; hidden?: boolean; 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-currency.js.map