Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: make toolbar draggable
Marc Seitz6bd48a55cc6e
diff --git a/components/shared/icons/grip-vertical.tsx b/components/shared/icons/grip-vertical.tsxnew file mode 100644index 00000000..18f4178b--- /dev/null+++ b/components/shared/icons/grip-vertical.tsx@@ -0,0 +1,23 @@+export default function GripVertical({ className }: { className?: string }) {+ return (+ <svg+ width="14"+ height="14"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ className={className}+ shapeRendering="geometricPrecision"+ >+ <circle cx="9" cy="12" r="1" />+ <circle cx="9" cy="5" r="1" />+ <circle cx="9" cy="19" r="1" />+ <circle cx="15" cy="12" r="1" />+ <circle cx="15" cy="5" r="1" />+ <circle cx="15" cy="19" r="1" />+ </svg>+ );+}diff --git a/components/view/toolbar.tsx b/components/view/toolbar.tsxindex 374a7385..01fba241 100644--- a/components/view/toolbar.tsx+++ b/components/view/toolbar.tsx@@ -2,7 +2,8 @@ import { useEffect, useRef, useState } from "react";import { Avatar, AvatarFallback } from "../ui/avatar";import UserRound from "../shared/icons/user-round";import { REACTIONS } from "@/lib/constants";-import { set } from "date-fns";+import GripVertical from "../shared/icons/grip-vertical";+import Draggable from "react-draggable";function getKeyByValue(object: { [x: string]: any }, value: any) {return Object.keys(object).find((key) => object[key] === value);@@ -33,7 +34,7 @@ export default function Toolbar({};}, []);- const handleEmojiClick = async (emoji: string) => {+ const handleEmojiClick = async (emoji: string, label: string) => {// Clear any existing timeoutif (clearEmojiTimeout.current) {clearTimeout(clearEmojiTimeout.current);@@ -54,61 +55,60 @@ export default function Toolbar({},body: JSON.stringify({viewId: viewId,- type: getKeyByValue(REACTIONS, emoji) as string,+ type: label,pageNumber: pageNumber,}),});};- const Emoji = (props: any) => (- <button- className="emoji text-2xl leading-6 hover:bg-gray-800 rounded-full p-2"- role="img"- aria-label={props.label ? props.label : ""}- aria-hidden={props.label ? "false" : "true"}- onClick={() => handleEmojiClick(props.symbol)}- >- {/* {(props.symbol === "π" ||- props.symbol === "π" ||- props.symbol === "β€οΈ" ||- props.symbol === "πΈ") &&- flyEmojis === props.symbol && (+ const Emoji = ({ label, emoji }: { label: string; emoji: string }) => (+ <div className="relative w-fit">+ <button+ className="font-emoji text-2xl leading-6 bg-transparent p-1 relative transition-bg-color duration-600 inline-flex justify-center items-center align-middle rounded-full ease-in-out hover:bg-gray-200 active:bg-gray-400 active:duration-0"+ role="img"+ aria-label={label ? label : ""}+ aria-hidden={label ? "false" : "true"}+ onClick={() => handleEmojiClick(emoji, label)}+ >+ {emoji}+ {currentEmoji && currentEmoji.emoji === emoji && (<span- className={`absolute -top-10 left-0 right-0 mx-auto animate-flyEmoji duration-3000`}+ key={currentEmoji.id}+ className="font-emoji absolute -top-10 left-0 right-0 mx-auto animate-flyEmoji duration-3000">- {flyEmojis}+ {currentEmoji.emoji}</span>- )} */}- {props.symbol}- {currentEmoji && currentEmoji.emoji === props.symbol && (- <span- key={currentEmoji.id}- className="absolute -top-10 left-0 right-0 mx-auto animate-flyEmoji duration-3000"- >- {currentEmoji.emoji}- </span>- )}- </button>+ )}+ </button>+ </div>);return (<>- <div className="fixed bottom-10 left-1/2 transform -translate-x-1/2 bg-gray-950/50 rounded-full py-1 px-4 flex items-center justify-start space-x-2 shadow-lg z-10">- <div className="p-1 rounded-full bg-emerald-500 -ml-2">- <Avatar className="h-6 w-6">- {/* <AvatarImage src= /> */}- <AvatarFallback>- <UserRound />- </AvatarFallback>- </Avatar>+ <Draggable+ bounds="parent"+ handle=".moveable-icon"+ defaultClassName="mt-12"+ >+ <div className="fixed bottom-10 left-1/2 flex z-10">+ <div className="bg-gray-950/50 border border-gray-900 rounded-full mx-auto mt-4 mb-4">+ <div className="grid items-center justify-start">+ <div className="p-2">+ <div className="grid items-center justify-start grid-flow-col">+ {REACTIONS.map((reaction) => (+ <Emoji+ key={reaction.emoji}+ emoji={reaction.emoji}+ label={reaction.label}+ />+ ))}+ <GripVertical className="h-6 w-6 text-gray-100 active:text-gray-300 moveable-icon" />+ </div>+ </div>+ </div>+ </div></div>- <div className="flex items-center">- <Emoji symbol="β€οΈ" label="heart" />- <Emoji symbol="πΈ" label="money" />- <Emoji symbol="π" label="thumbs-up" />- <Emoji symbol="π" label="thumbs-down" />- </div>- </div>+ </Draggable></>);}diff --git a/lib/constants.ts b/lib/constants.tsindex 3475c2e9..20663582 100644--- a/lib/constants.ts+++ b/lib/constants.ts@@ -17,9 +17,21 @@ export const PAPERMARK_HEADERS = {},};-export const REACTIONS = {- heart: "β€οΈ",- money: "πΈ",- thumbsUp: "π",- thumbsDown: "π",-};+export const REACTIONS = [+ {+ emoji: "β€οΈ",+ label: "heart",+ },+ {+ emoji: "πΈ",+ label: "money",+ },+ {+ emoji: "π",+ label: "up",+ },+ {+ emoji: "π",+ label: "down",+ },+];diff --git a/package-lock.json b/package-lock.jsonindex a2ce33e0..6655a26e 100644--- a/package-lock.json+++ b/package-lock.json@@ -73,6 +73,7 @@"postcss": "^8.4.32","react": "^18.2.0","react-dom": "^18.2.0",+ "react-draggable": "^4.4.6","react-dropzone": "^14.2.3","react-email": "^1.9.5","react-intersection-observer": "^9.5.3",@@ -9624,6 +9625,27 @@"react": "^18.2.0"}},+ "node_modules/react-draggable": {+ "version": "4.4.6",+ "resolved": "https://registry.npmjs.org/react-draggable/-/react-draggable-4.4.6.tgz",+ "integrity": "sha512-LtY5Xw1zTPqHkVmtM3X8MUOxNDOUhv/khTgBgrUvwaS064bwVvxT+q5El0uUFNx5IEPKXuRejr7UqLwBIg5pdw==",+ "dependencies": {+ "clsx": "^1.1.1",+ "prop-types": "^15.8.1"+ },+ "peerDependencies": {+ "react": ">= 16.3.0",+ "react-dom": ">= 16.3.0"+ }+ },+ "node_modules/react-draggable/node_modules/clsx": {+ "version": "1.2.1",+ "resolved": "https://registry.npmjs.org/clsx/-/clsx-1.2.1.tgz",+ "integrity": "sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==",+ "engines": {+ "node": ">=6"+ }+ },"node_modules/react-dropzone": {"version": "14.2.3","resolved": "https://registry.npmjs.org/react-dropzone/-/react-dropzone-14.2.3.tgz",diff --git a/package.json b/package.jsonindex 24c5facf..a4faa196 100644--- a/package.json+++ b/package.json@@ -80,6 +80,7 @@"postcss": "^8.4.32","react": "^18.2.0","react-dom": "^18.2.0",+ "react-draggable": "^4.4.6","react-dropzone": "^14.2.3","react-email": "^1.9.5","react-intersection-observer": "^9.5.3",