UNPKG

@try-at-software/input-elements

Version:

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

63 lines (62 loc) 2.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SingleValueInputElementWrapper = void 0; const React = require("react"); const Presentations_1 = require("../../Presentations"); class SingleValueInputElementWrapper extends React.Component { constructor(props) { var _a, _b; super(props); this.startLoading = () => { if (this.state.isLoading) return; this.setState({ isLoading: true }); }; this.stopLoading = () => { if (!this.state.isLoading) return; this.setState({ isLoading: false }); }; this.hide = () => { if (!this.state.isVisible) return; this.setState({ isVisible: false }); }; this.show = () => { if (this.state.isVisible) return; this.setState({ isVisible: true }); }; this.update = (newValue) => { this.setState({ value: newValue }); }; this.setError = (errorMessage) => { this.setState({ errorMessage: errorMessage }); }; this.changeDynamicProps = (dynamicProps) => { this.setState({ dynamicProps: dynamicProps }); }; this.render = () => { const { isVisible, isLoading } = this.state; const { loadingIndicator } = this.props; return (React.createElement(Presentations_1.PresentationRenderer, { isVisible: isVisible, isLoading: isLoading, renderInternalContent: this.renderInternalContent, loadingIndicator: loadingIndicator })); }; this.renderInternalContent = () => { var _a; const { internalComponent: Component, inputProps, operativeProps } = this.props; if (!Component) return null; const { renderErrors } = this.props; const errorMessages = renderErrors ? this.state.errorMessage : null; return (React.createElement(Component, Object.assign({ dynamicProps: (_a = this.state.dynamicProps) !== null && _a !== void 0 ? _a : {}, operativeProps: operativeProps }, inputProps, { value: this.state.value, errorMessage: errorMessages }))); }; this.state = { isLoading: props.isInitiallyLoading, isVisible: props.isInitiallyVisible, errorMessage: (_a = props.inputProps) === null || _a === void 0 ? void 0 : _a.errorMessage, value: (_b = props.inputProps) === null || _b === void 0 ? void 0 : _b.value, dynamicProps: props.initialDynamicProps }; } } exports.SingleValueInputElementWrapper = SingleValueInputElementWrapper;