2023-01-25 13:45:33 -08:00
|
|
|
import React from 'react';
|
|
|
|
|
2023-02-02 15:37:37 -08:00
|
|
|
import { ProgressBar, Textarea } from 'soapbox/components/ui';
|
2023-01-25 13:45:33 -08:00
|
|
|
import { Attachment } from 'soapbox/types/entities';
|
|
|
|
|
2023-01-26 10:30:26 -08:00
|
|
|
import ChatUpload from './chat-upload';
|
|
|
|
|
2023-01-25 13:45:33 -08:00
|
|
|
interface IChatTextarea extends React.ComponentProps<typeof Textarea> {
|
|
|
|
attachments?: Attachment[]
|
2023-01-26 10:30:26 -08:00
|
|
|
onDeleteAttachment?: () => void
|
2023-02-02 15:37:37 -08:00
|
|
|
isUploading?: boolean
|
|
|
|
uploadProgress?: number
|
2023-01-25 13:45:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Custom textarea for chats. */
|
2023-02-02 15:37:37 -08:00
|
|
|
const ChatTextarea: React.FC<IChatTextarea> = ({
|
|
|
|
attachments,
|
|
|
|
onDeleteAttachment,
|
|
|
|
isUploading = false,
|
|
|
|
uploadProgress = 0,
|
|
|
|
...rest
|
|
|
|
}) => {
|
2023-01-25 13:45:33 -08:00
|
|
|
return (
|
|
|
|
<div className={`
|
|
|
|
bg-white
|
2023-02-02 12:20:40 -08:00
|
|
|
dark:bg-gray-800
|
2023-01-25 13:45:33 -08:00
|
|
|
shadow-sm block w-full
|
|
|
|
sm:text-sm rounded-md
|
|
|
|
text-gray-900 dark:text-gray-100
|
2023-02-02 11:27:38 -08:00
|
|
|
border
|
2023-01-25 13:45:33 -08:00
|
|
|
placeholder:text-gray-600 dark:placeholder:text-gray-600 border-gray-400 dark:border-gray-800
|
2023-02-02 11:27:38 -08:00
|
|
|
dark:ring-1 focus-within:ring-1 dark:ring-gray-800 focus-within:ring-primary-500 focus-within:border-primary-500
|
2023-01-25 13:45:33 -08:00
|
|
|
dark:focus-within:ring-primary-500 dark:focus-within:border-primary-500
|
|
|
|
`}
|
|
|
|
>
|
2023-02-02 15:37:37 -08:00
|
|
|
{(!!attachments?.length || isUploading) && (
|
2023-01-26 10:30:26 -08:00
|
|
|
<div className='p-3 pb-0'>
|
2023-02-02 15:37:37 -08:00
|
|
|
{isUploading && (
|
|
|
|
<div className='relative p-4 inline-flex items-center justify-center w-24 h-24 rounded-lg overflow-hidden isolate bg-gray-200 dark:bg-primary-900'>
|
|
|
|
<ProgressBar progress={uploadProgress} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2023-01-26 10:30:26 -08:00
|
|
|
{attachments?.map(attachment => (
|
|
|
|
<ChatUpload
|
|
|
|
key={attachment.id}
|
|
|
|
attachment={attachment}
|
|
|
|
onDelete={onDeleteAttachment}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)}
|
2023-01-25 13:45:33 -08:00
|
|
|
|
|
|
|
<Textarea theme='transparent' {...rest} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ChatTextarea;
|