2023-07-25 20:27:29 +03:00
|
|
|
import { type InputHTMLAttributes } from 'react';
|
|
|
|
|
2023-07-15 17:46:19 +03:00
|
|
|
import Label from './Label';
|
|
|
|
|
2023-07-25 20:27:29 +03:00
|
|
|
interface TextInputProps
|
2023-08-26 17:26:49 +03:00
|
|
|
extends Omit<InputHTMLAttributes<HTMLInputElement>, 'className' | 'title'> {
|
2023-07-15 17:46:19 +03:00
|
|
|
id: string
|
|
|
|
label: string
|
2023-08-26 17:26:49 +03:00
|
|
|
tooltip?: string
|
2023-07-15 17:46:19 +03:00
|
|
|
widthClass?: string
|
2023-08-10 14:13:34 +03:00
|
|
|
colorClass?: string
|
2023-08-16 18:32:37 +03:00
|
|
|
singleRow?: boolean
|
2023-07-15 17:46:19 +03:00
|
|
|
}
|
|
|
|
|
2023-07-20 17:11:03 +03:00
|
|
|
function TextInput({
|
2023-08-26 17:26:49 +03:00
|
|
|
id, required, label, singleRow, tooltip,
|
2023-08-10 14:13:34 +03:00
|
|
|
widthClass = 'w-full',
|
|
|
|
colorClass = 'clr-input',
|
2023-07-23 15:23:01 +03:00
|
|
|
...props
|
2023-07-20 17:11:03 +03:00
|
|
|
}: TextInputProps) {
|
2023-07-15 17:46:19 +03:00
|
|
|
return (
|
2023-08-23 01:36:17 +03:00
|
|
|
<div className={`flex [&:not(:first-child)]:mt-3 ${singleRow ? 'items-center gap-4 ' + widthClass : 'flex-col items-start'}`}>
|
2023-07-25 20:27:29 +03:00
|
|
|
<Label
|
2023-07-15 17:46:19 +03:00
|
|
|
text={label}
|
|
|
|
required={required}
|
|
|
|
htmlFor={id}
|
|
|
|
/>
|
|
|
|
<input id={id}
|
2023-08-26 17:26:49 +03:00
|
|
|
title={tooltip}
|
2023-08-23 01:36:17 +03:00
|
|
|
className={`px-3 py-2 mt-2 leading-tight border shadow truncate hover:text-clip ${colorClass} ${singleRow ? '' : widthClass}`}
|
2023-07-15 17:46:19 +03:00
|
|
|
required={required}
|
2023-07-23 15:23:01 +03:00
|
|
|
{...props}
|
2023-07-15 17:46:19 +03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-07-25 20:27:29 +03:00
|
|
|
export default TextInput;
|