,
| 'type'
| 'value'
| 'size'
| 'color'
| 'valid'
| 'invalid'
| 'fullWidth'
| 'withIcon'
| 'errorMessage'
| 'className'
| 'setInputRef'
>;
const Input = (props: InputPropsType) => {
const {
type = 'text',
size = SIZE.M,
color = COLOR.DEFAULT,
fullWidth,
withIcon,
value,
valid,
invalid,
className,
setInputRef,
errorMessage,
disabled,
...additionalProps
} = props;
if (valid === true && invalid === true) {
throw {
name: 'WrongValidation',
message: 'Input can be either valid or invalid!',
};
}
const inputClass = classnames(
'sg-input',
{
[`sg-input--${String(size)}`]: size !== SIZE.M,
[`sg-input--${String(color)}`]: color !== COLOR.DEFAULT,
'sg-input--valid': valid,
'sg-input--invalid': invalid,
'sg-input--full-width': fullWidth,
'sg-input--with-icon': withIcon,
},
className
);
const wrapperClass = classnames('sg-input__wrapper', {
'sg-input__wrapper--full-width': fullWidth,
'sg-input__wrapper--disabled': disabled,
});
const errorMessageDisplayed =
invalid === true && errorMessage !== undefined && errorMessage !== '';
return (
{errorMessageDisplayed && (
{errorMessage}
)}
);
};
export default Input;