2020-02-13 19:43:20 -03:00
|
|
|
import React from 'react';
|
2020-03-12 13:26:31 -03:00
|
|
|
import PropTypes from 'prop-types';
|
2020-02-13 19:43:20 -03:00
|
|
|
import Label from '../Label';
|
2020-03-12 13:26:31 -03:00
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
|
|
const baseInputClasses =
|
2020-08-19 16:02:59 -03:00
|
|
|
'shadow transition duration-300 appearance-none border border-primary-main hover:border-gray-500 focus:border-gray-500 focus:outline-none rounded w-full py-2 px-3 text-sm text-white leading-tight focus:outline-none';
|
2020-03-12 13:26:31 -03:00
|
|
|
|
|
|
|
|
const transparentClasses = {
|
|
|
|
|
true: 'bg-transparent',
|
2020-06-26 12:34:43 -03:00
|
|
|
false: 'bg-black',
|
2020-03-12 13:26:31 -03:00
|
|
|
};
|
2020-02-13 19:43:20 -03:00
|
|
|
|
2020-02-13 20:14:59 -03:00
|
|
|
const Input = ({
|
2021-03-01 16:52:54 +01:00
|
|
|
id,
|
2020-02-13 20:14:59 -03:00
|
|
|
label,
|
|
|
|
|
containerClassName = '',
|
2020-02-14 19:46:37 -03:00
|
|
|
labelClassName = '',
|
2020-02-13 20:14:59 -03:00
|
|
|
className = '',
|
2020-06-26 12:34:43 -03:00
|
|
|
transparent = false,
|
2020-03-12 13:26:31 -03:00
|
|
|
type = 'text',
|
|
|
|
|
value,
|
|
|
|
|
onChange,
|
2020-03-19 19:58:13 -03:00
|
|
|
onFocus,
|
2020-07-02 17:53:38 -03:00
|
|
|
autoFocus,
|
|
|
|
|
onKeyPress,
|
2020-08-19 16:02:59 -03:00
|
|
|
onKeyDown,
|
|
|
|
|
readOnly,
|
|
|
|
|
disabled,
|
2020-03-12 13:26:31 -03:00
|
|
|
...otherProps
|
2020-02-13 20:14:59 -03:00
|
|
|
}) => {
|
2020-03-12 13:26:31 -03:00
|
|
|
return (
|
|
|
|
|
<div className={classnames('flex flex-col flex-1', containerClassName)}>
|
|
|
|
|
<Label className={labelClassName} text={label}></Label>
|
|
|
|
|
<input
|
2021-03-01 16:52:54 +01:00
|
|
|
data-cy={`input-${id}`}
|
2020-03-12 13:26:31 -03:00
|
|
|
className={classnames(
|
2020-08-19 16:02:59 -03:00
|
|
|
label && 'mt-2',
|
2020-03-12 13:26:31 -03:00
|
|
|
className,
|
|
|
|
|
baseInputClasses,
|
2020-08-19 16:02:59 -03:00
|
|
|
transparentClasses[transparent],
|
|
|
|
|
{ 'cursor-not-allowed': disabled }
|
2020-03-12 13:26:31 -03:00
|
|
|
)}
|
2020-08-19 16:02:59 -03:00
|
|
|
disabled={disabled}
|
|
|
|
|
readOnly={readOnly}
|
|
|
|
|
autoFocus={autoFocus}
|
2020-03-12 13:26:31 -03:00
|
|
|
type={type}
|
|
|
|
|
value={value}
|
|
|
|
|
onChange={onChange}
|
2020-03-19 19:58:13 -03:00
|
|
|
onFocus={onFocus}
|
2020-07-02 17:53:38 -03:00
|
|
|
onKeyPress={onKeyPress}
|
2020-08-19 16:02:59 -03:00
|
|
|
onKeyDown={onKeyDown}
|
2020-03-12 13:26:31 -03:00
|
|
|
{...otherProps}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2020-02-13 19:43:20 -03:00
|
|
|
);
|
2020-02-13 20:14:59 -03:00
|
|
|
};
|
|
|
|
|
|
2020-03-12 13:26:31 -03:00
|
|
|
Input.propTypes = {
|
|
|
|
|
label: PropTypes.string,
|
|
|
|
|
containerClassName: PropTypes.string,
|
|
|
|
|
labelClassName: PropTypes.string,
|
|
|
|
|
className: PropTypes.string,
|
|
|
|
|
transparent: PropTypes.bool,
|
|
|
|
|
type: PropTypes.string,
|
|
|
|
|
value: PropTypes.any,
|
|
|
|
|
onChange: PropTypes.func,
|
2020-03-19 19:58:13 -03:00
|
|
|
onFocus: PropTypes.func,
|
2020-07-02 17:53:38 -03:00
|
|
|
autoFocus: PropTypes.bool,
|
2020-08-19 16:02:59 -03:00
|
|
|
readOnly: PropTypes.bool,
|
2020-07-02 17:53:38 -03:00
|
|
|
onKeyPress: PropTypes.func,
|
2020-08-19 16:02:59 -03:00
|
|
|
onKeyDown: PropTypes.func,
|
|
|
|
|
disabled: PropTypes.bool
|
2020-02-13 19:43:20 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Input;
|