Skip to content

Commit 2ac1fc2

Browse files
committed
add button to download svg
1 parent 687cf8f commit 2ac1fc2

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/components/actions/svgCopy.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import { appStore } from "../../store";
55
import Modal from "../common/modal";
66
import Highlight from "../common/highlight";
77
import Copy from "../common/ copy";
8+
import Download from "../common/download";
89

910
const SVGCopy = view(({ onClose }) => {
1011
const [isModalOpen, openModal] = useState(false);
12+
const ID = `${appStore.edges}-${appStore.growth}-${appStore.id}`;
1113
const code = `
1214
<svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
1315
<path d="${appStore.path}"></path>
@@ -26,6 +28,7 @@ const SVGCopy = view(({ onClose }) => {
2628
</Button>
2729
<Modal isOpen={isModalOpen} onClose={() => openModal(false)}>
2830
<div className="flex justify-end">
31+
<Download content={code} filename={`blob_${ID}.svg`} />
2932
<Copy text={code} />
3033
</div>
3134
<Highlight code={code} lang={"markup"} />

src/components/common/download.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
3+
export default function Download({ content, filename }) {
4+
const downloadFile = () => {
5+
const url = window.URL.createObjectURL(new Blob([content]));
6+
const link = document.createElement("a");
7+
link.href = url;
8+
link.setAttribute("download", filename);
9+
document.body.appendChild(link);
10+
link.click();
11+
};
12+
return (
13+
<div
14+
className="font-medium leading-none cursor-pointer text-gray-500 hover:bg-gray-300 hover:text-gray-600 p-2 rounded-md flex items-center"
15+
onClick={() => downloadFile()}
16+
>
17+
<i className="ri-download-line text-lg mr-1"></i> <span>Download</span>
18+
</div>
19+
);
20+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy