Skip to content

Commit 36c1103

Browse files
authored
Merge pull request #16657 from ethereum/assetsDownload
fix: download buttons for png and svg
2 parents af47079 + ec6dda2 commit 36c1103

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/components/AssetDownload/index.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import type { ImageProps, StaticImageData } from "next/image"
55

66
import AssetDownloadArtist from "@/components/AssetDownload/AssetDownloadArtist"
77
import AssetDownloadImage from "@/components/AssetDownload/AssetDownloadImage"
8+
import { ButtonLink } from "@/components/ui/buttons/Button"
9+
import { Flex, Stack } from "@/components/ui/flex"
810

911
import { cn } from "@/lib/utils/cn"
1012
import { trackCustomEvent } from "@/lib/utils/matomo"
1113

12-
import { ButtonLink } from "../ui/buttons/Button"
13-
import { Flex, Stack } from "../ui/flex"
14-
1514
import { useTranslation } from "@/hooks/useTranslation"
1615

1716
type AssetDownloadProps = {
@@ -41,7 +40,9 @@ const AssetDownload = ({
4140
eventName: title,
4241
})
4342
}
43+
4444
const imgSrc = (image as StaticImageData).src
45+
const fileExtension = extname(imgSrc).slice(1)
4546

4647
return (
4748
<Stack
@@ -56,12 +57,19 @@ const AssetDownload = ({
5657
)}
5758
</div>
5859
<Flex className="mt-4 gap-5">
59-
<ButtonLink href={imgSrc} onClick={matomoHandler} target="_blank">
60-
{t("page-assets-download-download")} (
61-
{extname(imgSrc).slice(1).toUpperCase()})
60+
<ButtonLink
61+
href={imgSrc}
62+
onClick={matomoHandler}
63+
download={`${title.replace(/\s+/g, "-").toLowerCase()}.${fileExtension}`}
64+
>
65+
{t("page-assets-download-download")} ({fileExtension.toUpperCase()})
6266
</ButtonLink>
6367
{svgUrl && (
64-
<ButtonLink href={svgUrl} onClick={matomoHandler} target="_blank">
68+
<ButtonLink
69+
href={svgUrl}
70+
onClick={matomoHandler}
71+
download={`${title.replace(/\s+/g, "-").toLowerCase()}.svg`}
72+
>
6573
{t("page-assets-download-download")} (SVG)
6674
</ButtonLink>
6775
)}

0 commit comments

Comments
 (0)