Skip to content

Commit

Permalink
Merge pull request #325 from nextcloud/feat/screenshot
Browse files Browse the repository at this point in the history
feat: Add option to take screenshot of the visible area
  • Loading branch information
juliusknorr authored Jan 8, 2025
2 parents 4aadede + 157127b commit df71ccf
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useCallback, useEffect, useRef, useState } from 'react'
import { Icon } from '@mdi/react'
import { mdiSlashForwardBox } from '@mdi/js'
import { mdiSlashForwardBox, mdiMonitorScreenshot } from '@mdi/js'
import { createRoot } from 'react-dom'
import {
Excalidraw,
Expand Down Expand Up @@ -212,13 +212,28 @@ export default function App({
addWebEmbed(link)
})
}

const takeScreenshot = () => {
const dataUrl = document.querySelector('.excalidraw__canvas').toDataURL('image/png')
const downloadLink = document.createElement('a')
downloadLink.href = dataUrl
downloadLink.download = `${fileNameWithoutExtension} Screenshot.png`
document.body.appendChild(downloadLink)
downloadLink.click()
}

const renderMenu = () => {
return (
<MainMenu>
<MainMenu.DefaultItems.ToggleTheme />
<MainMenu.DefaultItems.ChangeCanvasBackground />
<MainMenu.Separator />
<MainMenu.DefaultItems.SaveAsImage />
<MainMenu.Item
icon={<Icon path={mdiMonitorScreenshot} size="16px" />}
onSelect={() => takeScreenshot()}>
{ 'Download screenshot' }
</MainMenu.Item>
</MainMenu>
)
}
Expand Down

0 comments on commit df71ccf

Please sign in to comment.