Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

refactor(icons): add icons function

Marc Seitz2a62a6684ab4
diff --git a/components/datarooms/dataroom-document-card.tsx b/components/datarooms/dataroom-document-card.tsx
index 5d40d91a..a633aa07 100644
--- a/components/datarooms/dataroom-document-card.tsx
+++ b/components/datarooms/dataroom-document-card.tsx
@@ -11,7 +11,6 @@ import { toast } from "sonner";
import { mutate } from "swr";
import BarChart from "@/components/shared/icons/bar-chart";
-import NotionIcon from "@/components/shared/icons/notion";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
@@ -25,6 +24,7 @@ import {
import { type DataroomFolderDocument } from "@/lib/swr/use-dataroom";
import { type DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";
import { cn, nFormatter, timeAgo } from "@/lib/utils";
+import { fileIcon } from "@/lib/utils/get-file-icon";
import { MoveToDataroomFolderModal } from "./move-dataroom-folder-modal";
@@ -171,16 +171,11 @@ export default function DataroomDocumentCard({
<div className="flex min-w-0 shrink items-center space-x-2 sm:space-x-4">
{!isSelected && !isHovered ? (
<div className="mx-0.5 flex w-8 items-center justify-center text-center sm:mx-1">
- {dataroomDocument.document.type === "notion" ? (
- <NotionIcon className="h-8 w-8" />
- ) : (
- <Image
- src={`/_icons/${dataroomDocument.document.type}${isLight ? "-light" : ""}.svg`}
- alt="File icon"
- width={50}
- height={50}
- />
- )}
+ {fileIcon({
+ fileType: dataroomDocument.document.type ?? "",
+ className: "h-8 w-8",
+ isLight,
+ })}
</div>
) : (
<div className="mx-0.5 w-8 sm:mx-1"></div>
diff --git a/components/document-upload.tsx b/components/document-upload.tsx
index 91b1354f..2c625c45 100644
--- a/components/document-upload.tsx
+++ b/components/document-upload.tsx
@@ -1,18 +1,13 @@
import { useMemo } from "react";
-import {
- Upload as ArrowUpTrayIcon,
- File as DocumentIcon,
- FileText as DocumentTextIcon,
- FileSpreadsheetIcon,
- Image as PhotoIcon,
- Presentation as PresentationChartBarIcon,
-} from "lucide-react";
+import { UploadIcon } from "lucide-react";
+import { useTheme } from "next-themes";
import { useDropzone } from "react-dropzone";
import { toast } from "sonner";
import { usePlan } from "@/lib/swr/use-billing";
import { bytesToSize } from "@/lib/utils";
+import { fileIcon } from "@/lib/utils/get-file-icon";
import { getPagesCount } from "@/lib/utils/get-page-number-count";
const fileSizeLimits: { [key: string]: number } = {
@@ -22,30 +17,6 @@ const fileSizeLimits: { [key: string]: number } = {
"application/vnd.oasis.opendocument.spreadsheet": 30, // 30 MB
};
-function fileIcon(fileType: string) {
- switch (fileType) {
- case "application/pdf":
- return <DocumentTextIcon className="mx-auto h-6 w-6" />;
- case "image/png":
- case "image/jpeg":
- case "image/gif":
- case "image/jpg":
- return <PhotoIcon className="mx-auto h-6 w-6" />;
- case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
- case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
- case "application/vnd.ms-powerpoint":
- case "application/msword":
- return <PresentationChartBarIcon className="mx-auto h-6 w-6" />;
- case "application/vnd.ms-excel":
- case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
- case "text/csv":
- case "application/vnd.oasis.opendocument.spreadsheet":
- return <FileSpreadsheetIcon className="mx-auto h-6 w-6" />;
- default:
- return <DocumentIcon className="mx-auto h-6 w-6" />;
- }
-}
-
export default function DocumentUpload({
currentFile,
setCurrentFile,
@@ -53,7 +24,10 @@ export default function DocumentUpload({
currentFile: File | null;
setCurrentFile: React.Dispatch<React.SetStateAction<File | null>>;
}) {
- const { plan, loading } = usePlan();
+ const { theme, systemTheme } = useTheme();
+ const isLight =
+ theme === "light" || (theme === "system" && systemTheme === "light");
+ const { plan } = usePlan();
const maxSize = plan === "business" || plan === "datarooms" ? 100 : 30;
const maxNumPages = plan === "business" || plan === "datarooms" ? 500 : 100;
@@ -138,13 +112,18 @@ export default function DocumentUpload({
) : null}
<div className="text-center">
{currentFile ? (
- <div className="flex flex-col items-center space-y-1 text-foreground sm:flex-row sm:space-x-2">
- <div>{fileIcon(currentFile.type)}</div>
+ <div className="flex flex-col items-center text-foreground sm:flex-row sm:space-x-2">
+ <div>
+ {fileIcon({
+ fileType: currentFile.type,
+ isLight,
+ })}
+ </div>
<p>{currentFile.name}</p>
<p className="text-gray-500">{bytesToSize(currentFile.size)}</p>
</div>
) : (
- <ArrowUpTrayIcon
+ <UploadIcon
className="mx-auto h-10 w-10 text-gray-500"
aria-hidden="true"
/>
diff --git a/components/documents/document-card.tsx b/components/documents/document-card.tsx
index c154446f..20e16a3f 100644
--- a/components/documents/document-card.tsx
+++ b/components/documents/document-card.tsx
@@ -19,7 +19,6 @@ import { mutate } from "swr";
import BarChart from "@/components/shared/icons/bar-chart";
import Check from "@/components/shared/icons/check";
import Copy from "@/components/shared/icons/copy";
-import NotionIcon from "@/components/shared/icons/notion";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
@@ -32,6 +31,7 @@ import {
import { DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";
import { cn, nFormatter, timeAgo } from "@/lib/utils";
+import { fileIcon } from "@/lib/utils/get-file-icon";
import { useCopyToClipboard } from "@/lib/utils/use-copy-to-clipboard";
import { AddToDataroomModal } from "./add-document-to-dataroom-modal";
@@ -193,16 +193,11 @@ export default function DocumentsCard({
<div className="flex min-w-0 shrink items-center space-x-2 sm:space-x-4">
{!isSelected && !isHovered ? (
<div className="mx-0.5 flex w-8 items-center justify-center text-center sm:mx-1">
- {prismaDocument.type === "notion" ? (
- <NotionIcon className="h-8 w-8" />
- ) : (
- <Image
- src={`/_icons/${prismaDocument.type}${isLight ? "-light" : ""}.svg`}
- alt="File icon"
- width={50}
- height={50}
- />
- )}
+ {fileIcon({
+ fileType: prismaDocument.type ?? "",
+ className: "h-8 w-8",
+ isLight,
+ })}
</div>
) : (
<div className="mx-0.5 w-8 sm:mx-1"></div>
diff --git a/components/documents/document-header.tsx b/components/documents/document-header.tsx
index 0292632e..95bae3ce 100644
--- a/components/documents/document-header.tsx
+++ b/components/documents/document-header.tsx
@@ -18,7 +18,6 @@ import { mutate } from "swr";
import FileUp from "@/components/shared/icons/file-up";
import MoreVertical from "@/components/shared/icons/more-vertical";
-import NotionIcon from "@/components/shared/icons/notion";
import PapermarkSparkle from "@/components/shared/icons/papermark-sparkle";
import { Button } from "@/components/ui/button";
import {
@@ -34,6 +33,7 @@ import {
import { usePlan } from "@/lib/swr/use-billing";
import { DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";
import { cn, getExtension } from "@/lib/utils";
+import { fileIcon } from "@/lib/utils/get-file-icon";
import AdvancedSheet from "../shared/icons/advanced-sheet";
import PortraitLandscape from "../shared/icons/portrait-landscape";
@@ -329,18 +329,11 @@ export default function DocumentHeader({
return (
<header className="!mb-16 flex items-center justify-between gap-x-8">
<div className="flex items-center space-x-2">
- {primaryVersion.type === "notion" ? (
- <NotionIcon className="h-7 w-7 lg:h-8 lg:w-8" />
- ) : (
- <div className="h-[25px] w-[25px] lg:h-[32px] lg:w-[32px]">
- <Image
- src={`/_icons/${primaryVersion.type}${isLight ? "-light" : ""}.svg`}
- alt="File icon"
- width={50}
- height={50}
- />
- </div>
- )}
+ {fileIcon({
+ fileType: prismaDocument.type ?? "",
+ className: "size-7 sm:size-8",
+ isLight,
+ })}
<div className="mt-1 flex flex-col lg:mt-0">
<h2
diff --git a/components/upload-zone.tsx b/components/upload-zone.tsx
index 93d96ad8..1a3de19a 100644
--- a/components/upload-zone.tsx
+++ b/components/upload-zone.tsx
@@ -4,14 +4,6 @@ import { useCallback, useRef, useState } from "react";
import { useTeam } from "@/context/team-context";
import { DocumentStorageType } from "@prisma/client";
-import {
- Upload as ArrowUpTrayIcon,
- File as DocumentIcon,
- FileText as DocumentTextIcon,
- FileSpreadsheetIcon,
- Image as PhotoIcon,
- Presentation as PresentationChartBarIcon,
-} from "lucide-react";
import { useSession } from "next-auth/react";
import { FileRejection, useDropzone } from "react-dropzone";
import { mutate } from "swr";
@@ -36,30 +28,6 @@ const fileSizeLimits: { [key: string]: number } = {
"application/vnd.oasis.opendocument.spreadsheet": 30, // 30 MB
};
-function fileIcon(fileType: string) {
- switch (fileType) {
- case "application/pdf":
- return <DocumentTextIcon className="mx-auto h-6 w-6" />;
- case "image/png":
- case "image/jpeg":
- case "image/gif":
- case "image/jpg":
- return <PhotoIcon className="mx-auto h-6 w-6" />;
- case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
- case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
- case "application/vnd.ms-powerpoint":
- case "application/msword":
- return <PresentationChartBarIcon className="mx-auto h-6 w-6" />;
- case "application/vnd.ms-excel":
- case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
- case "text/csv":
- case "application/vnd.oasis.opendocument.spreadsheet":
- return <FileSpreadsheetIcon className="mx-auto h-6 w-6" />;
- default:
- return <DocumentIcon className="mx-auto h-6 w-6" />;
- }
-}
-
export default function UploadZone({
children,
onUploadStart,
diff --git a/components/view/dataroom/document-card.tsx b/components/view/dataroom/document-card.tsx
index c0293cc6..4cd1f23f 100644
--- a/components/view/dataroom/document-card.tsx
+++ b/components/view/dataroom/document-card.tsx
@@ -4,7 +4,7 @@ import React from "react";
import { useTheme } from "next-themes";
-import NotionIcon from "@/components/shared/icons/notion";
+import { fileIcon } from "@/lib/utils/get-file-icon";
import { TDocumentData } from "./dataroom-view";
@@ -40,16 +40,11 @@ export default function DocumentCard({
<li className="group/row relative flex items-center justify-between rounded-lg border-0 p-3 ring-1 ring-gray-200 transition-all hover:bg-secondary hover:ring-gray-300 dark:bg-secondary dark:ring-gray-700 hover:dark:ring-gray-500 sm:p-4">
<div className="flex min-w-0 shrink items-center space-x-2 sm:space-x-4">
<div className="mx-0.5 flex w-8 items-center justify-center text-center sm:mx-1">
- {document.versions[0].type === "notion" ? (
- <NotionIcon className="h-8 w-8" />
- ) : (
- <Image
- src={`/_icons/${document.versions[0].type}${isLight ? "-light" : ""}.svg`}
- alt="File icon"
- width={50}
- height={50}
- />
- )}
+ {fileIcon({
+ fileType: document.versions[0].type ?? "",
+ className: "h-8 w-8",
+ isLight,
+ })}
</div>
<div className="flex-col">
diff --git a/components/welcome/next.tsx b/components/welcome/next.tsx
index dbf2f1a8..ada9c294 100644
--- a/components/welcome/next.tsx
+++ b/components/welcome/next.tsx
@@ -1,13 +1,7 @@
import { useRouter } from "next/router";
import { motion } from "framer-motion";
-import {
- File as DocumentIcon,
- Presentation as PresentationChartBarIcon,
- ServerIcon,
-} from "lucide-react";
-
-import NotionIcon from "@/components/shared/icons/notion";
+import { FileIcon, ServerIcon } from "lucide-react";
import { STAGGER_CHILD_VARIANTS } from "@/lib/constants";
@@ -57,7 +51,7 @@ export default function Next() {
}
className="flex min-h-[200px] flex-col items-center justify-center space-y-5 overflow-hidden p-5 transition-colors hover:bg-gray-200 hover:dark:bg-gray-800 md:p-10"
>
- <DocumentIcon className="pointer-events-none h-auto w-12 sm:w-12" />
+ <FileIcon className="pointer-events-none h-auto w-12 sm:w-12" />
<p>Document</p>
</button>
<button
diff --git a/components/welcome/select.tsx b/components/welcome/select.tsx
index 4c5bf37a..535975eb 100644
--- a/components/welcome/select.tsx
+++ b/components/welcome/select.tsx
@@ -1,13 +1,9 @@
import { useRouter } from "next/router";
import { motion } from "framer-motion";
-import {
- File as DocumentIcon,
- FileChartPieIcon,
- Presentation as PresentationChartBarIcon,
-} from "lucide-react";
+import { FileChartPieIcon, FileIcon, PresentationIcon } from "lucide-react";
-import NotionIcon from "@/components/shared/icons/notion";
+import NotionIcon from "@/components/shared/icons/files/notion";
import { STAGGER_CHILD_VARIANTS } from "@/lib/constants";
@@ -57,7 +53,7 @@ export default function Next() {
}
className="flex min-h-[200px] flex-col items-center justify-center space-y-5 overflow-hidden p-5 transition-colors hover:bg-gray-200 hover:dark:bg-gray-800 md:p-10"
>
- <PresentationChartBarIcon className="pointer-events-none h-auto w-12 sm:w-12" />
+ <PresentationIcon className="pointer-events-none h-auto w-12 sm:w-12" />
<p>Pitchdeck</p>
</button>
@@ -101,7 +97,7 @@ export default function Next() {
}
className="flex min-h-[200px] flex-col items-center justify-center space-y-5 overflow-hidden p-5 transition-colors hover:bg-gray-200 hover:dark:bg-gray-800 md:p-10"
>
- <DocumentIcon className="pointer-events-none h-auto w-12 sm:w-12" />
+ <FileIcon className="pointer-events-none h-auto w-12 sm:w-12" />
<p>Another document</p>
</button>
</motion.div>
diff --git a/lib/utils/get-file-icon.tsx b/lib/utils/get-file-icon.tsx
new file mode 100644
index 00000000..c5b5f668
--- /dev/null
+++ b/lib/utils/get-file-icon.tsx
@@ -0,0 +1,48 @@
+import { FileIcon, ImageIcon } from "lucide-react";
+
+import DocsIcon from "@/components/shared/icons/files/docs";
+import NotionIcon from "@/components/shared/icons/files/notion";
+import PdfIcon from "@/components/shared/icons/files/pdf";
+import SheetIcon from "@/components/shared/icons/files/sheet";
+import SlidesIcon from "@/components/shared/icons/files/slides";
+
+export function fileIcon({
+ fileType,
+ className = "mx-auto h-6 w-6",
+ isLight = true,
+}: {
+ fileType: string;
+ className?: string;
+ isLight?: boolean;
+}) {
+ switch (fileType) {
+ case "pdf":
+ case "application/pdf":
+ return <PdfIcon className={className} isLight={isLight} />;
+ case "image/png":
+ case "image/jpeg":
+ case "image/gif":
+ case "image/jpg":
+ return <ImageIcon className={className} />;
+ case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
+ case "application/msword":
+ case "application/vnd.oasis.opendocument.text":
+ case "docs":
+ return <DocsIcon className={className} isLight={isLight} />;
+ case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
+ case "application/vnd.ms-powerpoint":
+ case "application/vnd.oasis.opendocument.presentation":
+ case "slides":
+ return <SlidesIcon className={className} isLight={isLight} />;
+ case "application/vnd.ms-excel":
+ case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
+ case "text/csv":
+ case "application/vnd.oasis.opendocument.spreadsheet":
+ case "sheet":
+ return <SheetIcon className={className} isLight={isLight} />;
+ case "notion":
+ return <NotionIcon className={className} />;
+ default:
+ return <FileIcon className={className} />;
+ }
+}