Skip to content

Commit db64bdd

Browse files
authoredAug 30, 2021
Download using useEditorContext() hook
Download the current image using useEditorContext() hook
1 parent 49e7677 commit db64bdd

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed
 

‎src/components/Navbar/Navbar.tsx

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Flex, IconButton, Input } from 'theme-ui'
22
import { useState } from 'react'
33
import { DownloadIcon, LogoIcon, GithubIcon } from './NavbarIcons'
4+
import context from "../../uibox/editor";
5+
import { useEditorContext, useHandlers } from '@/uibox'
46

57
function Navbar() {
6-
// const { canvas } = useCanvasContext()
8+
const { canvas } = useEditorContext()
79
const [templateName, setTemplateName] = useState('My First Design')
810
const downloadImage = () => {
911
//@ts-ignore
@@ -21,6 +23,20 @@ function Navbar() {
2123
// a.download = 'drawing.png'
2224
// a.click()
2325
// }
26+
const data = canvas?.toDataURL({
27+
multiplier: 3,
28+
top: 0,
29+
left: 0,
30+
height: canvas.height,
31+
width: canvas.width,
32+
});
33+
// const data= canvas?.toDataURL("image/png");
34+
if (data) {
35+
const a = document.createElement('a')
36+
a.href = data
37+
a.download = 'drawing.png'
38+
a.click()
39+
}
2440
}
2541

2642
return (

0 commit comments

Comments
 (0)