UNPKG

@try-at-software/input-elements

Version:

A package providing different input elements that are extensible and easily configurable for your custom needs.

71 lines (70 loc) 2.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExtendedInputElement = void 0; const React = require("react"); const ChangingInputElement_1 = require("./ChangingInputElement"); class ExtendedInputElement extends ChangingInputElement_1.ChangingInputElement { constructor(update) { super(update); this._isVisible = true; this._isLoading = false; this._componentRef = React.createRef(); } /** @inheritdoc */ get isVisible() { return this._isVisible; } /** @inheritdoc */ hide() { var _a; this._isVisible = false; if ((_a = this._componentRef) === null || _a === void 0 ? void 0 : _a.current) this._componentRef.current.hide(); this.updateInternally(); } /** @inheritdoc */ show() { var _a; this._isVisible = true; if ((_a = this._componentRef) === null || _a === void 0 ? void 0 : _a.current) this._componentRef.current.show(); this.updateInternally(); } /** @inheritdoc */ get isLoading() { return this._isLoading; } /** @inheritdoc */ load(action) { var _a; if (!action) return; const callback = () => { var _a; this._isLoading = false; if ((_a = this._componentRef) === null || _a === void 0 ? void 0 : _a.current) this._componentRef.current.stopLoading(); this.updateInternally(); }; try { // If a new value is provided, we should execute asynchronously the `onDependentValueChanged` callback to retrieve the requested selectable models. this._isLoading = true; if ((_a = this._componentRef) === null || _a === void 0 ? void 0 : _a.current) this._componentRef.current.startLoading(); this.updateInternally(); action(callback); } catch (error) { let newErrorMessage; if (error instanceof Error) newErrorMessage = error.message; if (typeof error === 'string') newErrorMessage = error; else throw error; this.errorMessage = newErrorMessage; callback(); } } } exports.ExtendedInputElement = ExtendedInputElement;