import React from 'react' import { asField } from 'informed' import { Input as Base } from 'styled-system-html' import { withTheme } from 'styled-components' import { Flex } from 'rebass' import FormFieldMessage from 'components/UI/FormFieldMessage' /** * @render react * @name Input * @example * */ class Input extends React.PureComponent { static displayName = 'Input' render() { const { onChange, onBlur, initialValue, field, forwardedRef, theme, fieldApi, fieldState, justifyContent, ...rest } = this.props const { setValue, setTouched } = fieldApi const { value } = fieldState let borderColor if (fieldState.touched) { if (fieldState.error) { borderColor = theme.colors.superRed } else if (value && !fieldState.error) { borderColor = theme.colors.superGreen } } return ( { setValue(e.target.value) if (onChange) { onChange(e) } }} onBlur={e => { setTouched() if (onBlur) { onBlur(e) } }} error={fieldState.error} /> {fieldState.error && ( {fieldState.error} )} ) } } export default asField(withTheme(Input))