diff --git a/.storybook/index.css b/.storybook/index.css index b5c61c9..bd6213e 100644 --- a/.storybook/index.css +++ b/.storybook/index.css @@ -1,3 +1,3 @@ @tailwind base; @tailwind components; -@tailwind utilities; +@tailwind utilities; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 72ae5bc..97bf6fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "reachat", - "version": "1.4.0", + "version": "1.4.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "reachat", - "version": "1.4.0", + "version": "1.4.2", "license": "Apache-2.0", "dependencies": { "@radix-ui/react-slot": "^1.1.0", diff --git a/src/ChatInput/ChatInput.tsx b/src/ChatInput/ChatInput.tsx index 9477f45..2f17b97 100644 --- a/src/ChatInput/ChatInput.tsx +++ b/src/ChatInput/ChatInput.tsx @@ -37,7 +37,7 @@ interface ChatInputProps { sendIcon?: ReactElement; /** - * Icon to show for send. + * Icon to show for stop. */ stopIcon?: ReactElement; diff --git a/src/SessionMessages/SessionMessage/MessageFiles.tsx b/src/SessionMessages/SessionMessage/MessageFiles.tsx index 62632f8..863b3e8 100644 --- a/src/SessionMessages/SessionMessage/MessageFiles.tsx +++ b/src/SessionMessages/SessionMessage/MessageFiles.tsx @@ -1,7 +1,7 @@ import { ChatContext } from '@/ChatContext'; import { ConversationFile } from '@/types'; import { cn } from 'reablocks'; -import { FC, PropsWithChildren, useContext } from 'react'; +import { FC, PropsWithChildren, useContext, useState } from 'react'; import { MessageFile } from './MessageFile'; import { Slot } from '@radix-ui/react-slot'; @@ -15,20 +15,77 @@ interface MessageFilesProps extends PropsWithChildren { export const MessageFiles: FC = ({ files, children }) => { const { theme } = useContext(ChatContext); const Comp = children ? Slot : MessageFile; + const [expanded, setExpanded] = useState(false); if (!files || files.length === 0) { return null; } + // Group image and other files + const { imageFiles, otherFiles } = files.reduce( + (acc, file) => { + if (file.type.startsWith('image/')) { + acc.imageFiles.push(file); + } else { + acc.otherFiles.push(file); + } + + return acc; + }, + { + imageFiles: [] as ConversationFile[], + otherFiles: [] as ConversationFile[] + } + ); + + const maxImageLength = 3; + const truncateImages = !expanded && imageFiles.length > maxImageLength; + + // Renders the image files based on the current expansion state + const renderImageFiles = (images: ConversationFile[]) => { + return truncateImages + ? images.slice(0, maxImageLength).map((image, index) => ( +
+ {image.name} + {index === maxImageLength - 1 && ( +
setExpanded(true)} + > + +{(imageFiles.length - maxImageLength).toLocaleString()} +
+ )} +
+ )) + : images.map((image, index) => ( + + {children} + + )); + }; + return ( - files.length > 0 && ( -
- {files.map((file, index) => ( +
+ {imageFiles.length > 0 && renderImageFiles(imageFiles)} + + {otherFiles.length > 0 && + otherFiles.map((file, index) => ( {children} ))} -
- ) +
); };