Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2ac1fc2

Browse files
committed
add button to download svg
1 parent687cf8f commit2ac1fc2

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
importModalfrom"../common/modal";
66
importHighlightfrom"../common/highlight";
77
importCopyfrom"../common/ copy";
8+
importDownloadfrom"../common/download";
89

910
constSVGCopy=view(({ onClose})=>{
1011
const[isModalOpen,openModal]=useState(false);
12+
constID=`${appStore.edges}-${appStore.growth}-${appStore.id}`;
1113
constcode=`
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
<ModalisOpen={isModalOpen}onClose={()=>openModal(false)}>
2830
<divclassName="flex justify-end">
31+
<Downloadcontent={code}filename={`blob_${ID}.svg`}/>
2932
<Copytext={code}/>
3033
</div>
3134
<Highlightcode={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+
importReactfrom"react";
2+
3+
exportdefaultfunctionDownload({ content, filename}){
4+
constdownloadFile=()=>{
5+
consturl=window.URL.createObjectURL(newBlob([content]));
6+
constlink=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+
<iclassName="ri-download-line text-lg mr-1"></i><span>Download</span>
18+
</div>
19+
);
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp