import * as React from 'react'; import * as PropTypes from 'prop-types'; // @ts-ignore import ConditionalWrap from 'conditional-wrap'; import { Omit } from '../types'; import Group from '../Group'; import Input, { LocalInputProps, InputProps, inputDefaultProps, inputPropTypes } from './Input'; import FieldWrapper, { LocalFieldWrapperProps, fieldWrapperDefaultProps, fieldWrapperPropTypes } from '../FieldWrapper/FieldWrapper'; export type LocalInputFieldProps = Omit & LocalInputProps & { /** Addon component to the input (before). Similar to the addon components in Input. */ addonBefore?: React.ReactElement; /** Addon component to the input (after). Similar to the addon components in Input. */ addonAfter?: React.ReactElement; /** If addonBefore or addonAfter exists, then the addons will render vertically. */ isVertical?: boolean; }; export type InputFieldProps = LocalInputFieldProps & InputProps; export const InputField: React.FunctionComponent = ({ addonBefore, addonAfter, a11yId, description, hint, isOptional, isVertical, label, validationText, after, a11yLabel, autoComplete, autoFocus, before, children, className, defaultValue, disabled, inputRef, isLoading, isRequired, name, size, max, maxLength, min, minLength, multiple, pattern, placeholder, readOnly, spellCheck, step, state, type, value, onBlur, onChange, onFocus, ...props }) => ( {({ elementProps }) => ( {children}} > {addonBefore} {children} {addonAfter} )} ); export const inputFieldPropTypes = { addonBefore: PropTypes.element, addonAfter: PropTypes.element, isVertical: PropTypes.bool, ...fieldWrapperPropTypes, ...inputPropTypes }; InputField.propTypes = inputFieldPropTypes; export const inputFieldDefaultProps = { addonBefore: undefined, addonAfter: undefined, isVertical: false, ...fieldWrapperDefaultProps, ...inputDefaultProps }; InputField.defaultProps = inputFieldDefaultProps; // @ts-ignore const C: React.FunctionComponent = InputField; export default C;