import React, { Fragment } from 'react';
import { FieldLevelHelp } from 'patternfly-react';
import PropTypes from 'prop-types';
import CommonForm from 'foremanReact/components/common/forms/CommonForm';
const InputField = ({
name,
label,
info,
value,
onChange,
required,
type,
disabled,
options,
checked,
error,
}) => {
const renderOptions = opts =>
opts.map(option => );
let renderComponent;
switch (type) {
case 'textarea':
renderComponent = (
);
break;
case 'select':
renderComponent = (
);
break;
case 'checkbox':
renderComponent = (
);
break;
default:
renderComponent = (
);
break;
}
return (
{info}}
/>
)
}
>
{renderComponent}
{error && (
{error}
)}
);
};
InputField.propTypes = {
name: PropTypes.string,
label: PropTypes.string,
info: PropTypes.string,
value: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
PropTypes.bool,
]),
onChange: PropTypes.func.isRequired,
required: PropTypes.bool,
type: PropTypes.oneOf([
'text',
'number',
'password',
'textarea',
'select',
'checkbox',
]),
disabled: PropTypes.bool,
checked: PropTypes.bool,
options: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.string.isRequired,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
.isRequired,
})
),
error: PropTypes.string,
};
InputField.defaultProps = {
name: '',
label: '',
info: undefined,
value: '',
required: false,
type: 'text',
disabled: false,
checked: false,
options: [],
error: '',
};
export default InputField;