Skip to content

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

improvement: small screen shows only icon in btn with tooltip

Ashish Viradiyadbb435729d93
diff --git a/components/datarooms/actions/download-dataroom.tsx b/components/datarooms/actions/download-dataroom.tsx
index 47269116..4f609c1e 100644
--- a/components/datarooms/actions/download-dataroom.tsx
+++ b/components/datarooms/actions/download-dataroom.tsx
@@ -3,8 +3,7 @@ import { useState } from "react";
import { DownloadIcon } from "lucide-react";
import { toast } from "sonner";
-import { Button } from "@/components/ui/button";
-import { ButtonTooltip } from "@/components/ui/tooltip";
+import { ResponsiveButton } from "@/components/responsive-button";
export default function DownloadDataroomButton({
teamId,
@@ -57,16 +56,13 @@ export default function DownloadDataroomButton({
}
};
return (
- <ButtonTooltip content="Download Dataroom" sideOffset={4}>
- <Button
- onClick={downloadDataroom}
- variant="outline"
- className=""
- size="sm"
- loading={isLoading}
- >
- <DownloadIcon />
- </Button>
- </ButtonTooltip>
+ <ResponsiveButton
+ icon={<DownloadIcon className="h-4 w-4" />}
+ text="Download"
+ onClick={downloadDataroom}
+ variant="outline"
+ size="sm"
+ loading={isLoading}
+ />
);
}
diff --git a/components/datarooms/actions/generate-index-dialog.tsx b/components/datarooms/actions/generate-index-dialog.tsx
index 73f37e5a..9f27e7db 100644
--- a/components/datarooms/actions/generate-index-dialog.tsx
+++ b/components/datarooms/actions/generate-index-dialog.tsx
@@ -15,6 +15,7 @@ import { useDataroomLinks } from "@/lib/swr/use-dataroom";
import { IndexFileFormat } from "@/lib/types/index-file";
import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
+import { ResponsiveButton } from "@/components/responsive-button";
import { Button } from "@/components/ui/button";
import {
Dialog,
@@ -135,10 +136,13 @@ export default function GenerateIndexDialog({
return (
<Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger asChild>
- <Button variant="outline" size="sm" disabled={disabled}>
- <FileSlidersIcon />
- Generate Index File
- </Button>
+ <ResponsiveButton
+ icon={<FileSlidersIcon className="h-4 w-4" />}
+ text="Generate Index"
+ variant="outline"
+ size="sm"
+ disabled={disabled}
+ />
</DialogTrigger>
<DialogContent className="sm:max-w-md">
<DialogHeader>
diff --git a/components/responsive-button.tsx b/components/responsive-button.tsx
new file mode 100644
index 00000000..68353a53
--- /dev/null
+++ b/components/responsive-button.tsx
@@ -0,0 +1,55 @@
+import React, { cloneElement } from "react";
+
+import { useBreakpoint } from "@/lib/hooks/use-breakpoint";
+
+import { Button, ButtonProps } from "@/components/ui/button";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+} from "@/components/ui/tooltip";
+
+interface ResponsiveButtonProps extends ButtonProps {
+ icon: React.ReactElement;
+ text: string;
+ breakpoint?: number;
+}
+
+export const ResponsiveButton = React.forwardRef<
+ HTMLButtonElement,
+ ResponsiveButtonProps
+>(({ icon, text, breakpoint = 1024, ...props }, ref) => {
+ const isSmaller = useBreakpoint(breakpoint);
+
+ if (isSmaller) {
+ return (
+ <TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button ref={ref} {...props}>
+ {icon}
+ <span className="sr-only">{text}</span>
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>{text}</p>
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ );
+ }
+
+ const iconWithAriaHidden = cloneElement(icon, {
+ "aria-hidden": "true",
+ });
+
+ return (
+ <Button ref={ref} {...props}>
+ {iconWithAriaHidden}
+ {text}
+ </Button>
+ );
+});
+
+ResponsiveButton.displayName = "ResponsiveButton";
diff --git a/lib/hooks/use-breakpoint.ts b/lib/hooks/use-breakpoint.ts
new file mode 100644
index 00000000..26c5f1b1
--- /dev/null
+++ b/lib/hooks/use-breakpoint.ts
@@ -0,0 +1,20 @@
+import { useState, useEffect } from 'react';
+
+export function useBreakpoint(breakpoint: number) {
+ const [isSmaller, setIsSmaller] = useState(false);
+
+ useEffect(() => {
+ const handleResize = () => {
+ setIsSmaller(window.innerWidth < breakpoint);
+ };
+
+ handleResize();
+ window.addEventListener('resize', handleResize);
+
+ return () => {
+ window.removeEventListener('resize', handleResize);
+ };
+ }, [breakpoint]);
+
+ return isSmaller;
+}
\ No newline at end of file
diff --git a/pages/datarooms/[id]/documents/index.tsx b/pages/datarooms/[id]/documents/index.tsx
index 94c6e86f..51e34573 100644
--- a/pages/datarooms/[id]/documents/index.tsx
+++ b/pages/datarooms/[id]/documents/index.tsx
@@ -3,6 +3,8 @@ import { useState } from "react";
import { useTeam } from "@/context/team-context";
import { ArrowUpDownIcon, FolderPlusIcon, PlusIcon } from "lucide-react";
+import { useDataroom, useDataroomItems } from "@/lib/swr/use-dataroom";
+
import DownloadDataroomButton from "@/components/datarooms/actions/download-dataroom";
import GenerateIndexButton from "@/components/datarooms/actions/generate-index-button";
import { DataroomHeader } from "@/components/datarooms/dataroom-header";
@@ -14,11 +16,9 @@ import { AddDocumentModal } from "@/components/documents/add-document-modal";
import { LoadingDocuments } from "@/components/documents/loading-document";
import { AddFolderModal } from "@/components/folders/add-folder-modal";
import AppLayout from "@/components/layouts/app";
-import { Button } from "@/components/ui/button";
+import { ResponsiveButton } from "@/components/responsive-button";
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
-import { useDataroom, useDataroomItems } from "@/lib/swr/use-dataroom";
-
export default function Documents() {
const { dataroom } = useDataroom();
const { items, folderCount, documentCount, isLoading } = useDataroomItems({
@@ -58,40 +58,30 @@ export default function Documents() {
dataroomId={dataroom?.id}
key={1}
>
- <Button
+ <ResponsiveButton
+ icon={<PlusIcon className="h-5 w-5 shrink-0" />}
+ text="Add Document"
size="sm"
- className="group flex items-center justify-start gap-x-3 px-3 text-left"
- title="Add Document"
- >
- <PlusIcon className="h-5 w-5 shrink-0" aria-hidden="true" />
- <span>Add Document</span>
- </Button>
+ />
</AddDocumentModal>
<AddFolderModal isDataroom={true} dataroomId={dataroom?.id} key={2}>
- <Button
+ <ResponsiveButton
+ icon={<FolderPlusIcon className="h-5 w-5 shrink-0" />}
+ text="Add Folder"
size="sm"
variant="outline"
- className="group flex items-center justify-start gap-x-3 px-3 text-left"
- >
- <FolderPlusIcon
- className="h-5 w-5 shrink-0"
- aria-hidden="true"
- />
- <span>Add Folder</span>
- </Button>
+ />
</AddFolderModal>
<div id="dataroom-reordering-action">
{!isReordering ? (
- <Button
+ <ResponsiveButton
+ icon={<ArrowUpDownIcon className="h-4 w-4" />}
+ text="Edit index"
size="sm"
variant="outline"
- className="gap-x-1"
onClick={() => setIsReordering(!isReordering)}
- >
- <ArrowUpDownIcon className="h-4 w-4" />
- Edit index
- </Button>
+ />
) : null}
</div>
</div>