ConceptPortal-public/rsconcept/frontend/src/components/Common/TextInput.tsx

41 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-11-05 16:31:49 +03:00
import { IColorsProps, IEditorProps } from '../commonInterfaces';
2023-07-15 17:46:19 +03:00
import Label from './Label';
2023-11-05 16:31:49 +03:00
interface TextInputProps
extends IEditorProps, IColorsProps, Omit<React.InputHTMLAttributes<HTMLInputElement>, 'className' | 'title'> {
2023-10-23 18:22:55 +03:00
dense?: boolean
2023-11-05 16:31:49 +03:00
allowEnter?: boolean
}
function preventEnterCapture(event: React.KeyboardEvent<HTMLInputElement>) {
if (event.key === 'Enter') {
event.preventDefault();
}
2023-07-15 17:46:19 +03:00
}
2023-07-20 17:11:03 +03:00
function TextInput({
2023-11-05 16:31:49 +03:00
id, label, dense, tooltip, noBorder, noOutline, allowEnter, onKeyDown,
dimensions = 'w-full',
2023-11-05 16:31:49 +03:00
colors = 'clr-input',
...restProps
2023-07-20 17:11:03 +03:00
}: TextInputProps) {
const borderClass = noBorder ? '' : 'border';
const outlineClass = noOutline ? '' : 'clr-outline';
2023-07-15 17:46:19 +03:00
return (
<div className={`flex ${dense ? 'items-center gap-4 ' + dimensions : 'flex-col items-start gap-2'}`}>
{label ?
<Label
text={label}
htmlFor={id}
/> : null}
<input id={id}
title={tooltip}
onKeyDown={!allowEnter && !onKeyDown ? preventEnterCapture : onKeyDown}
className={`px-3 py-2 leading-tight truncate hover:text-clip ${colors} ${outlineClass} ${borderClass} ${dense ? 'w-full' : dimensions}`}
{...restProps}
/>
</div>);
2023-07-15 17:46:19 +03:00
}
2023-07-25 20:27:29 +03:00
export default TextInput;