Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Added QR Dropdown Component

Max Programmingeb43822115ba
diff --git a/components/app/modals/link-qr-modal.tsx b/components/app/modals/link-qr-modal.tsx
index 80a6629ed3..95d59ff42c 100644
--- a/components/app/modals/link-qr-modal.tsx
+++ b/components/app/modals/link-qr-modal.tsx
@@ -8,7 +8,7 @@ import {
} from "react";
import { HexColorInput, HexColorPicker } from "react-colorful";
import BlurImage from "@/components/shared/blur-image";
-import { ChevronRight, Download, Logo } from "@/components/shared/icons";
+import { ChevronRight, Copy, Download, Logo } from "@/components/shared/icons";
import Modal from "@/components/shared/modal";
import Switch from "@/components/shared/switch";
import Tooltip, { TooltipContent } from "@/components/shared/tooltip";
@@ -17,6 +17,7 @@ import useProject from "@/lib/swr/use-project";
import useUsage from "@/lib/swr/use-usage";
import { SimpleLinkProps } from "@/lib/types";
import { getApexDomain, linkConstructor } from "@/lib/utils";
+import QrDropdown from "@/components/shared/qr-dropdown";
function LinkQRModalHelper({
showLinkQRModal,
@@ -121,41 +122,20 @@ function LinkQRModalHelper({
/>
<div className="flex gap-2 px-4 sm:px-16">
- <button
- onClick={async () =>
- download(
- await getQRAsSVGDataUri({
- ...qrData,
- ...(showLogo && {
- imageSettings: {
- ...qrData.imageSettings,
- src: logo || "https://dub.sh/_static/logo.svg",
- },
- }),
- }),
- "svg",
- )
- }
- className="flex w-full items-center justify-center gap-2 rounded-md border border-black bg-black py-1.5 px-5 text-sm text-white transition-all hover:bg-white hover:text-black"
- >
- <Download /> SVG
- </button>
<button
onClick={async () =>
download(await getQRAsCanvas(qrData, "image/png"), "png")
}
className="flex w-full items-center justify-center gap-2 rounded-md border border-black bg-black py-1.5 px-5 text-sm text-white transition-all hover:bg-white hover:text-black"
>
- <Download /> PNG
- </button>
- <button
- onClick={async () =>
- download(await getQRAsCanvas(qrData, "image/jpeg"), "jpg")
- }
- className="flex w-full items-center justify-center gap-2 rounded-md border border-black bg-black py-1.5 px-5 text-sm text-white transition-all hover:bg-white hover:text-black"
- >
- <Download /> JPEG
+ <Copy /> Copy Image
</button>
+ <QrDropdown
+ download={download}
+ qrData={qrData}
+ showLogo={showLogo}
+ logo={logo}
+ />
</div>
{/* This will be used to prompt downloads. */}
diff --git a/components/shared/icons/copy.tsx b/components/shared/icons/copy.tsx
index fbb5af88c4..fa7a6cd7e3 100644
--- a/components/shared/icons/copy.tsx
+++ b/components/shared/icons/copy.tsx
@@ -1,4 +1,4 @@
-export default function Copy({ className }: { className: string }) {
+export default function Copy({ className }: { className?: string }) {
return (
<svg
fill="none"
diff --git a/components/shared/icons/image.tsx b/components/shared/icons/image.tsx
new file mode 100644
index 0000000000..0dbdaf1f61
--- /dev/null
+++ b/components/shared/icons/image.tsx
@@ -0,0 +1,21 @@
+export default function Image({ className }: { className?: string }) {
+ return (
+ <svg
+ data-testid="geist-icon"
+ fill="none"
+ height="24"
+ shape-rendering="geometricPrecision"
+ stroke="currentColor"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="1.5"
+ viewBox="0 0 24 24"
+ width="24"
+ className={className}
+ >
+ <rect x="3" y="3" width="18" height="18" rx="2" ry="2" />
+ <circle cx="8.5" cy="8.5" r="1.5" />
+ <path d="M21 15l-5-5L5 21" />
+ </svg>
+ );
+}
diff --git a/components/shared/icons/index.tsx b/components/shared/icons/index.tsx
index 5935ccce66..df5e1f6177 100644
--- a/components/shared/icons/index.tsx
+++ b/components/shared/icons/index.tsx
@@ -41,3 +41,4 @@ export { default as Archive } from "./archive";
export { default as Delete } from "./delete";
export { default as Logout } from "./logout";
export { default as Save } from "./save";
+export { default as Image } from "./image";
diff --git a/components/shared/qr-dropdown.tsx b/components/shared/qr-dropdown.tsx
new file mode 100644
index 0000000000..9b753341d2
--- /dev/null
+++ b/components/shared/qr-dropdown.tsx
@@ -0,0 +1,92 @@
+import { getQRAsCanvas, getQRAsSVGDataUri } from "@/lib/qr";
+import { useState } from "react";
+import IconMenu from "./icon-menu";
+import { Download, Image } from "./icons";
+import Popover from "./popover";
+
+interface IQrDropdownProps {
+ download: (url: string, extension: string) => void;
+ showLogo: boolean;
+ logo: string;
+ qrData: {
+ imageSettings: {
+ src: string;
+ height: number;
+ width: number;
+ excavate: boolean;
+ };
+ value: string;
+ bgColor: string;
+ fgColor: string;
+ size: number;
+ level: string;
+ };
+}
+
+export default function QrDropdown({
+ download,
+ qrData,
+ showLogo,
+ logo,
+}: IQrDropdownProps) {
+ const [openPopover, setOpenPopover] = useState(false);
+ return (
+ <>
+ <Popover
+ content={
+ <div className="grid w-full gap-1 p-2 sm:w-40">
+ <button
+ onClick={async () => {
+ setOpenPopover(false);
+ download(
+ await getQRAsSVGDataUri({
+ ...qrData,
+ ...(showLogo && {
+ imageSettings: {
+ ...qrData.imageSettings,
+ src: logo || "https://dub.sh/_static/logo.svg",
+ },
+ }),
+ }),
+ "svg",
+ );
+ }}
+ className="w-full rounded-md p-2 text-left text-sm font-medium text-gray-500 transition-all duration-75 hover:bg-gray-100"
+ >
+ <IconMenu text="SVG" icon={<Image className="h-4 w-4" />} />
+ </button>
+ <button
+ onClick={async () => {
+ setOpenPopover(false);
+ download(await getQRAsCanvas(qrData, "image/png"), "png");
+ }}
+ className="w-full rounded-md p-2 text-left text-sm font-medium text-gray-500 transition-all duration-75 hover:bg-gray-100"
+ >
+ <IconMenu text="PNG" icon={<Image className="h-4 w-4" />} />
+ </button>
+ <button
+ onClick={async () => {
+ setOpenPopover(false);
+ download(await getQRAsCanvas(qrData, "image/jpeg"), "jpg");
+ }}
+ className="w-full rounded-md p-2 text-left text-sm font-medium text-gray-500 transition-all duration-75 hover:bg-gray-100"
+ >
+ <IconMenu text="JPEG" icon={<Image className="h-4 w-4" />} />
+ </button>
+ </div>
+ }
+ align="center"
+ openPopover={openPopover}
+ setOpenPopover={setOpenPopover}
+ >
+ <button
+ onClick={() => setOpenPopover(!openPopover)}
+ className="flex w-full items-center justify-center gap-2 rounded-md border border-black bg-black py-1.5 px-5 text-sm text-white transition-all hover:bg-white hover:text-black"
+ >
+ <Download />
+ Download
+ </button>
+ </Popover>
+ </>
+ );
+}