reachat 1.4.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1357,10 +1357,69 @@
1357
1357
  const MessageFiles = ({ files, children }) => {
1358
1358
  const { theme } = React.useContext(ChatContext);
1359
1359
  const Comp = children ? reactSlot.Slot : MessageFile;
1360
+ const [expanded, setExpanded] = React.useState(false);
1360
1361
  if (!files || files.length === 0) {
1361
1362
  return null;
1362
1363
  }
1363
- return files.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: reablocks.cn(theme.messages.message.files.base), children: files.map((file, index) => /* @__PURE__ */ jsxRuntime.jsx(Comp, { ...file, children }, index)) });
1364
+ const { imageFiles, otherFiles } = files.reduce(
1365
+ (acc, file) => {
1366
+ if (file.type.startsWith("image/")) {
1367
+ acc.imageFiles.push(file);
1368
+ } else {
1369
+ acc.otherFiles.push(file);
1370
+ }
1371
+ return acc;
1372
+ },
1373
+ {
1374
+ imageFiles: [],
1375
+ otherFiles: []
1376
+ }
1377
+ );
1378
+ const maxImageLength = 3;
1379
+ const truncateImages = !expanded && imageFiles.length > maxImageLength;
1380
+ const renderImageFiles = (images) => {
1381
+ return truncateImages ? images.slice(0, maxImageLength).map((image, index) => /* @__PURE__ */ jsxRuntime.jsxs(
1382
+ "figure",
1383
+ {
1384
+ className: index === 0 ? "col-span-2 row-span-2" : "relative",
1385
+ children: [
1386
+ /* @__PURE__ */ jsxRuntime.jsx(
1387
+ "img",
1388
+ {
1389
+ src: image.url,
1390
+ alt: image.name,
1391
+ className: "relative w-full h-full object-cover rounded-lg"
1392
+ }
1393
+ ),
1394
+ index === maxImageLength - 1 && /* @__PURE__ */ jsxRuntime.jsxs(
1395
+ "div",
1396
+ {
1397
+ className: "absolute top-0 left-0 w-full h-full flex justify-center items-center bg-black bg-opacity-50 rounded-lg cursor-pointer",
1398
+ onClick: () => setExpanded(true),
1399
+ children: [
1400
+ "+",
1401
+ (imageFiles.length - maxImageLength).toLocaleString()
1402
+ ]
1403
+ }
1404
+ )
1405
+ ]
1406
+ },
1407
+ index
1408
+ )) : images.map((image, index) => /* @__PURE__ */ jsxRuntime.jsx(Comp, { ...image, children }, index));
1409
+ };
1410
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1411
+ "div",
1412
+ {
1413
+ className: reablocks.cn(
1414
+ theme.messages.message.files.base,
1415
+ truncateImages ? "grid grid-rows-2 grid-flow-col gap-2 w-1/3" : ""
1416
+ ),
1417
+ children: [
1418
+ imageFiles.length > 0 && renderImageFiles(imageFiles),
1419
+ otherFiles.length > 0 && otherFiles.map((file, index) => /* @__PURE__ */ jsxRuntime.jsx(Comp, { ...file, children }, index))
1420
+ ]
1421
+ }
1422
+ );
1364
1423
  };
1365
1424
  const MessageQuestion = ({
1366
1425
  children,