scratch-www/src/components/formik-forms/formik-input.jsx

66 lines
1.7 KiB
React
Raw Normal View History

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');
require('./formik-input.scss');
const FormikInput = ({
className,
error,
onSetRef,
toolTip,
2019-07-12 11:39:04 -04:00
validationClassName,
wrapperClassName,
...props
}) => (
<div
className={classNames(
'col-sm-9',
'row',
'row-with-tooltip',
wrapperClassName
)}
>
<Field
className={classNames(
'formik-input',
{fail: error},
className
)}
/* formik uses "innerRef" to return the actual input element */
innerRef={onSetRef}
{...props}
/>
{error ? (
2019-07-12 11:39:04 -04:00
<ValidationMessage
className={validationClassName}
message={error}
mode="error"
2019-07-12 11:39:04 -04:00
/>
) : toolTip && (
<ValidationMessage
className={validationClassName}
message={toolTip}
mode="info"
/>
)}
</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]),
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,
validationClassName: PropTypes.string,
wrapperClassName: PropTypes.string
};
module.exports = FormikInput;