@securecall/client-component
Version:
SecureCall Core Web Component
92 lines (87 loc) • 4.48 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 securecallRequestCurrencyCss = ":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 SecurecallRequestCurrency$1 = /*@__PURE__*/ proxyCustomElement(class SecurecallRequestCurrency extends H {
constructor(registerHost) {
super();
if (registerHost !== false) {
this.__registerHost();
}
this.__attachShadow();
this.isValidEvent = createEvent(this, "isValidEvent");
}
fieldName;
config;
isValidEvent;
log = new Logger('SecurecallRequestCurrency');
get value() {
return this.config.value;
}
set value(value) {
if (this.config.value !== value) {
this.config.value = value;
this.validateChange();
}
}
handleConfigChange(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("handleChange: string change:", ev.target.value);
this.value = ev.target.value;
}
validateChange() {
const input = this.value;
const num = parseFloat(input);
const isValidCurrency = /^(\d+(\.\d{1,2})?)?$/.test(input);
const isValid = !isNaN(num) && num !== 0 && isValidCurrency
&& num >= (this.config.min || 0.01)
&& num <= (this.config.max || 99999.99);
this.log.debug(this.fieldName + ": validateChange: string:", input, "isValid:", isValid, 'config.valid', this.config.valid);
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: 'e66b2d00594641d78171b84eeaf892cd24421a54' }, h("div", { key: '809d5891d05f4389b99b31188772a5e9467c8259', class: "field-container" }, h("label", { key: '4d600c4ab2bd2d60eb67d1e948c87acf8a377ddb', class: "custom-label", htmlFor: this.fieldName }, this.config.label, ":"), h("input", { key: '156e37b7333b64567ae0b9d75b19ef0275af633e', 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: '8d027ba0bc68e9ad3fb6d8056520205b2e149b5d', class: this.config.valid ? 'field-valid' : 'field-invalid' }))));
}
static get watchers() { return {
"config": ["handleConfigChange"]
}; }
static get style() { return securecallRequestCurrencyCss; }
}, [257, "securecall-request-currency", {
"fieldName": [1, "field-name"],
"config": [1040]
}, undefined, {
"config": ["handleConfigChange"]
}]);
function defineCustomElement$1() {
if (typeof customElements === "undefined") {
return;
}
const components = ["securecall-request-currency"];
components.forEach(tagName => { switch (tagName) {
case "securecall-request-currency":
if (!customElements.get(tagName)) {
customElements.define(tagName, SecurecallRequestCurrency$1);
}
break;
} });
}
const SecurecallRequestCurrency = SecurecallRequestCurrency$1;
const defineCustomElement = defineCustomElement$1;
export { SecurecallRequestCurrency, defineCustomElement };
//# sourceMappingURL=securecall-request-currency.js.map
//# sourceMappingURL=securecall-request-currency.js.map