/**
*
* Inputs
*/
import React from 'react';
import PropTypes from 'prop-types';
import { ErrorMessage, Label } from '@buffetjs/styles';
import { Error, InputText } from '@buffetjs/core';
import Wrapper from './Wrapper';
import HeadersInput from '../HeadersInput';
import EventInput from '../EventInput';
function Inputs({
error: inputError,
label,
name,
onChange,
onBlur: handleBlur,
onClick,
onRemove,
type,
validations,
value,
}) {
if (type === 'headers') {
return (
{inputError && This value is required}
);
}
return (
{({ canCheck, error, dispatch }) => {
const hasError = error && error !== null;
const handleChange = e => {
if (!canCheck) {
dispatch({
type: 'SET_CHECK',
});
}
dispatch({
type: 'SET_ERROR',
error: null,
});
onChange(e);
};
return (
{type === 'events' ? (
{
handleChange(e);
handleBlur(e);
}}
/>
) : (
)}
{hasError && {error}}
);
}}
);
}
Inputs.defaultProps = {
error: null,
label: '',
onBlur: () => {},
onClick: () => {},
onRemove: () => {},
type: 'text',
validations: {},
value: null,
};
Inputs.propTypes = {
error: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
label: PropTypes.oneOfType([PropTypes.string]),
name: PropTypes.string.isRequired,
onBlur: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
onClick: PropTypes.func,
onRemove: PropTypes.func,
type: PropTypes.string,
validations: PropTypes.object,
value: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
PropTypes.array,
]),
};
export default Inputs;