File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 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";
55import Modal from "../common/modal" ;
66import Highlight from "../common/highlight" ;
77import Copy from "../common/ copy" ;
8+ import Download from "../common/download" ;
89
910const 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" } />
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