✨ (textAreaWrapper): refactor TextAreaWrapper to improve readability and maintainability
✨ (uploadFileButton): add UploadFileButton component for file uploads in chat input
This commit is contained in:
parent
89943b2c3e
commit
0d17211177
2 changed files with 54 additions and 18 deletions
|
|
@ -18,7 +18,35 @@ const TextAreaWrapper = ({
|
||||||
inputRef,
|
inputRef,
|
||||||
setInputFocus,
|
setInputFocus,
|
||||||
files,
|
files,
|
||||||
|
isDragging,
|
||||||
}) => {
|
}) => {
|
||||||
|
const getPlaceholderText = (
|
||||||
|
isDragging: boolean,
|
||||||
|
noInput: boolean,
|
||||||
|
): string => {
|
||||||
|
if (isDragging) {
|
||||||
|
return "Drop here";
|
||||||
|
} else if (noInput) {
|
||||||
|
return CHAT_INPUT_PLACEHOLDER;
|
||||||
|
} else {
|
||||||
|
return CHAT_INPUT_PLACEHOLDER_SEND;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const lockClass =
|
||||||
|
lockChat || saveLoading
|
||||||
|
? "form-modal-lock-true bg-input"
|
||||||
|
: noInput
|
||||||
|
? "form-modal-no-input bg-input"
|
||||||
|
: "form-modal-lock-false bg-background";
|
||||||
|
|
||||||
|
const fileClass =
|
||||||
|
files.length > 0
|
||||||
|
? "rounded-b-md border-t-0 border-border focus:border-t-0 focus:border-ring"
|
||||||
|
: "rounded-md border-t-2 border-border focus:border-ring";
|
||||||
|
|
||||||
|
const additionalClassNames = "form-modal-lockchat pl-10";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Textarea
|
<Textarea
|
||||||
onFocus={(e) => {
|
onFocus={(e) => {
|
||||||
|
|
@ -52,24 +80,8 @@ const TextAreaWrapper = ({
|
||||||
onChange={(event): void => {
|
onChange={(event): void => {
|
||||||
setChatValue(event.target.value);
|
setChatValue(event.target.value);
|
||||||
}}
|
}}
|
||||||
className={classNames(
|
className={classNames(lockClass, fileClass, additionalClassNames)}
|
||||||
lockChat || saveLoading
|
placeholder={getPlaceholderText(isDragging, noInput)}
|
||||||
? " form-modal-lock-true bg-input"
|
|
||||||
: noInput
|
|
||||||
? "form-modal-no-input bg-input"
|
|
||||||
: " form-modal-lock-false bg-background",
|
|
||||||
|
|
||||||
"form-modal-lockchat",
|
|
||||||
`${
|
|
||||||
files.length > 0
|
|
||||||
? "rounded-b-md border-t-0 border-border focus:border-t-0 focus:border-ring"
|
|
||||||
: "rounded-md border-t-2 border-border focus:border-ring"
|
|
||||||
}`,
|
|
||||||
"pl-10",
|
|
||||||
)}
|
|
||||||
placeholder={
|
|
||||||
noInput ? CHAT_INPUT_PLACEHOLDER : CHAT_INPUT_PLACEHOLDER_SEND
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
const UploadFileButton = ({
|
||||||
|
fileInputRef,
|
||||||
|
handleFileChange,
|
||||||
|
handleButtonClick,
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
ref={fileInputRef}
|
||||||
|
style={{ display: "none" }}
|
||||||
|
onChange={handleFileChange}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
className="absolute rounded bg-blue-500 px-4 py-2 font-bold text-white hover:bg-blue-700"
|
||||||
|
onClick={handleButtonClick}
|
||||||
|
>
|
||||||
|
Upload File
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UploadFileButton;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue