import React from 'react'; import PropTypes from 'prop-types'; import cn from 'classnames'; import styles from './InputField.css'; import ErrorMessage from './ErrorMessage'; import { Icon } from 'plugin-api/beta/client/components/ui'; const InputField = ({ id = '', label = '', type = 'text', name = '', onChange = () => {}, showError = true, hasError = false, errorMsg = '', children, columnDisplay = false, showSuccess = false, validationType = '', icon = '', value = '', defaultValue = '', disabled = false, }) => { const inputValue = { ...(value ? { value } : {}), ...(defaultValue ? { defaultValue } : {}), }; return (
{label && ( )}
{icon && }
{!hasError && showSuccess && value && ( )} {hasError && showError && {errorMsg}}
{children}
); }; InputField.propTypes = { id: PropTypes.string, disabled: PropTypes.bool, label: PropTypes.string, type: PropTypes.string, name: PropTypes.string.isRequired, onChange: PropTypes.func, value: PropTypes.string, defaultValue: PropTypes.string, icon: PropTypes.string, showError: PropTypes.bool, hasError: PropTypes.bool, errorMsg: PropTypes.string, children: PropTypes.node, columnDisplay: PropTypes.bool, showSuccess: PropTypes.bool, validationType: PropTypes.string, }; export default InputField;