Files
ohif-viewer/platform/ui/src/components/Input/Input.tsx
T

76 lines
1.8 KiB
TypeScript
Raw Normal View History

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 =
'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 = ({
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,
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
data-cy={`input-${id}`}
2020-03-12 13:26:31 -03:00
className={classnames(
label && 'mt-2',
2020-03-12 13:26:31 -03:00
className,
baseInputClasses,
transparentClasses[transparent],
{ 'cursor-not-allowed': disabled }
2020-03-12 13:26:31 -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}
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,
readOnly: PropTypes.bool,
2020-07-02 17:53:38 -03:00
onKeyPress: PropTypes.func,
onKeyDown: PropTypes.func,
disabled: PropTypes.bool
2020-02-13 19:43:20 -03:00
};
export default Input;