import React from 'react' import { ForwardedRef, forwardRef } from 'react' import { InputWrapperStyle, InputContentStyle, InputStyle, InputLeftDecoratorStyle, InputRightDecoratorStyle, InputMessageStyle, } from './InputStyles' import { InputLabelStyle } from './LabelStyles' import { InputProps } from './types' function Input(props: InputProps, ref?: ForwardedRef) { const { label, error, warning, success, active = false, fullwidth = false, placeholder = ' ', leftDecorator, rightDecorator, className, style, variant = 'default', color = 'default', wrapperRef, children, ...rest } = props const { id, disabled = false } = props const wrapperProps = { className, style } const hasLabel = !!label && variant === 'default' const hasError = !!error const hasErrorMessage = hasError && typeof error !== 'boolean' const hasWarning = !hasError && !!warning // `error` overrides `warning` const hasWarningMessage = hasWarning && typeof warning !== 'boolean' const hasSuccess = !!success && !error const hasSuccessMessage = hasSuccess && typeof success !== 'boolean' const hasLeftDecorator = !!leftDecorator const hasRightDecorator = !!rightDecorator return ( {hasLeftDecorator && ( {leftDecorator} )} {hasLabel && {label}} {hasErrorMessage && ( {error} )} {hasWarningMessage && ( {warning} )} {hasSuccessMessage && ( {success} )} {hasRightDecorator && ( {rightDecorator} )} ) } export default forwardRef(Input)