import React, { Component } from "react"; import PropTypes from "prop-types"; export default class CustomInput extends Component { static propTypes = { type: PropTypes.string, inputType: PropTypes.string, name: PropTypes.string, value: PropTypes.string, label: PropTypes.string, placeholder: PropTypes.string, customInputEvents: PropTypes.object, }; static defaultProps = { type: "text", inputType: "text", name: "", value: "", label: "", placeholder: "", customInputEvents: {}, }; constructor(props) { super(props); this.state = { customInputEvents: props.customInputEvents, errors: "", value: props.value, }; if (this.state.customInputEvents.onBlur) { const oldOnBlur = this.state.customInputEvents.onBlur; this.state.customInputEvents.onBlur = () => { this.onBlurHandler(); oldOnBlur(); }; } else this.state.customInputEvents.onBlur = this.onBlurHandler; if (this.state.customInputEvents.onChange) { const oldOnChange = this.state.customInputEvents.onChange; this.state.customInputEvents.onChange = (event) => { this.onChangeHandler(event); oldOnChange(event); }; } else this.state.customInputEvents.onChange = this.onChangeHandler; } onBlurHandler = () => { this.validateInput(); }; onChangeHandler = (event) => { this.setState({ value: event.target.value, }); }; listErrors = () => { let errors = this.state.errors; if (errors.length > 0) { errors = errors.map((error) => { return (