2019-06-25 09:43:49 -04:00
|
|
|
const classNames = require('classnames');
|
|
|
|
const PropTypes = require('prop-types');
|
|
|
|
const React = require('react');
|
|
|
|
import {Field} from 'formik';
|
|
|
|
|
|
|
|
const ValidationMessage = require('../forms/validation-message.jsx');
|
|
|
|
|
|
|
|
require('../forms/row.scss');
|
2019-08-09 22:59:01 -04:00
|
|
|
require('./formik-input.scss');
|
2019-06-25 09:43:49 -04:00
|
|
|
|
|
|
|
const FormikInput = ({
|
|
|
|
className,
|
|
|
|
error,
|
2019-08-26 16:01:42 -04:00
|
|
|
onSetRef,
|
2019-08-12 17:52:16 -04:00
|
|
|
toolTip,
|
2019-07-12 11:39:04 -04:00
|
|
|
validationClassName,
|
2019-07-26 13:55:46 -04:00
|
|
|
wrapperClassName,
|
2019-06-25 09:43:49 -04:00
|
|
|
...props
|
|
|
|
}) => (
|
2019-07-26 13:55:46 -04:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'col-sm-9',
|
|
|
|
'row',
|
|
|
|
'row-with-tooltip',
|
|
|
|
wrapperClassName
|
|
|
|
)}
|
|
|
|
>
|
2019-06-25 09:43:49 -04:00
|
|
|
<Field
|
|
|
|
className={classNames(
|
2019-09-16 21:45:11 -04:00
|
|
|
'formik-input',
|
2019-08-09 22:59:01 -04:00
|
|
|
{fail: error},
|
2019-06-25 09:43:49 -04:00
|
|
|
className
|
|
|
|
)}
|
2019-08-13 17:42:21 -04:00
|
|
|
/* formik uses "innerRef" to return the actual input element */
|
2019-08-26 16:01:42 -04:00
|
|
|
innerRef={onSetRef}
|
2019-06-25 09:43:49 -04:00
|
|
|
{...props}
|
|
|
|
/>
|
2019-08-12 17:52:16 -04:00
|
|
|
{error ? (
|
2019-07-12 11:39:04 -04:00
|
|
|
<ValidationMessage
|
|
|
|
className={validationClassName}
|
|
|
|
message={error}
|
2019-08-16 17:58:10 -04:00
|
|
|
mode="error"
|
2019-07-12 11:39:04 -04:00
|
|
|
/>
|
2019-08-12 17:52:16 -04:00
|
|
|
) : toolTip && (
|
|
|
|
<ValidationMessage
|
|
|
|
className={validationClassName}
|
|
|
|
message={toolTip}
|
2019-08-16 17:58:10 -04:00
|
|
|
mode="info"
|
2019-08-12 17:52:16 -04:00
|
|
|
/>
|
2019-06-25 09:43:49 -04:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
FormikInput.propTypes = {
|
|
|
|
className: PropTypes.string,
|
2019-08-25 10:10:58 -04:00
|
|
|
// error and toolTip can be false, in which case we ignore them
|
|
|
|
error: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
2019-08-26 16:01:42 -04:00
|
|
|
onSetRef: PropTypes.func,
|
2019-08-21 11:19:05 -04:00
|
|
|
toolTip: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
2019-07-12 11:39:04 -04:00
|
|
|
type: PropTypes.string,
|
2019-07-26 13:56:46 -04:00
|
|
|
validationClassName: PropTypes.string,
|
2019-07-26 13:55:46 -04:00
|
|
|
wrapperClassName: PropTypes.string
|
2019-06-25 09:43:49 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = FormikInput;
|