File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -5,9 +5,11 @@ import { appStore } from "../../store";
5
5
import Modal from "../common/modal" ;
6
6
import Highlight from "../common/highlight" ;
7
7
import Copy from "../common/ copy" ;
8
+ import Download from "../common/download" ;
8
9
9
10
const SVGCopy = view ( ( { onClose } ) => {
10
11
const [ isModalOpen , openModal ] = useState ( false ) ;
12
+ const ID = `${ appStore . edges } -${ appStore . growth } -${ appStore . id } ` ;
11
13
const code = `
12
14
<svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
13
15
<path d="${ appStore . path } "></path>
@@ -26,6 +28,7 @@ const SVGCopy = view(({ onClose }) => {
26
28
</ Button >
27
29
< Modal isOpen = { isModalOpen } onClose = { ( ) => openModal ( false ) } >
28
30
< div className = "flex justify-end" >
31
+ < Download content = { code } filename = { `blob_${ ID } .svg` } />
29
32
< Copy text = { code } />
30
33
</ div >
31
34
< Highlight code = { code } lang = { "markup" } />
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments