Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

1.7 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.

import {
  cn,
  HoverCard,
  HoverCardContent,
  HoverCardTrigger
} from "@carbon/react";
import type { ComponentPropsWithoutRef, ElementRef } from "react";
import { forwardRef } from "react";
import { path } from "~/utils/path";

type FilePreviewProps = ComponentPropsWithoutRef<typeof HoverCardContent> & {
  bucket: "public" | "private";
  pathToFile: string;
  type: "PDF" | "Image";
};

const FilePreview = forwardRef<
  ElementRef<typeof HoverCardContent>,
  FilePreviewProps
>(({ bucket, pathToFile, type, children, className, ...props }, ref) => {
  return (
    <HoverCard>
      <HoverCardTrigger>{children}</HoverCardTrigger>
      {type === "PDF" ? (
        <HoverCardContent
          align="start"
          ref={ref}
          {...props}
          className={cn("w-[425px] h-[550px] overflow-hidden p-0", className)}
        >
          <iframe
            seamless
            title={pathToFile}
            width="425"
            height="550"
            src={path.to.file.previewFile(`${bucket}/${pathToFile}`)}
          />
        </HoverCardContent>
      ) : (
        <HoverCardContent
          align="start"
          className="w-[400px] h-[400px] overflow-hidden p-0 z-[100]"
        >
          <iframe
            seamless
            title={pathToFile}
            width="400"
            height="400"
            src={path.to.file.previewImage(bucket, pathToFile)}
          />
        </HoverCardContent>
      )}
    </HoverCard>
  );
});
FilePreview.displayName = "FilePreview";

export default FilePreview;