Skip to content

Commit

Permalink
feat(snippets): save screenshot as svg (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov committed Dec 31, 2022
1 parent 2ba53ac commit 4cf24c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/renderer/components/screenshot/TheScreenshot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@
<div class="right">
<AppActionButton
v-tooltip="i18n.t('saveScreenshot')"
@click="onSaveScreenshot"
@click="onSaveScreenshot('png')"
>
PNG &nbsp;
<UniconsFileDownload />
</AppActionButton>
<AppActionButton
v-tooltip="i18n.t('saveScreenshot')"
@click="onSaveScreenshot('svg')"
>
SVG &nbsp;
<UniconsFileDownload />
</AppActionButton>
</div>
Expand Down Expand Up @@ -174,12 +182,20 @@ const init = () => {
hljs.registerAliases('graphqlschema', { languageName: 'graphql' })
}
const onSaveScreenshot = async () => {
const data = await domToImage.toPng(snippetRef.value!)
const onSaveScreenshot = async (type: 'png' | 'svg' = 'png') => {
let data = ''
if (type === 'png') {
data = await domToImage.toPng(snippetRef.value!)
}
if (type === 'svg') {
data = await domToImage.toSvg(snippetRef.value!)
}
const a = document.createElement('a')
a.href = data
a.download = `${props.name}.png`
a.download = `${props.name}.${type}`
a.click()
track('snippets/create-screenshot')
Expand Down Expand Up @@ -274,6 +290,10 @@ init()
align-items: center;
display: flex;
}
.right {
display: flex;
gap: var(--spacing-xs);
}
}
.content {
flex: 1;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/components/ui/AppActionButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
border: none;
background-color: transparent;
outline: none;
color: var(--color-text);
:deep(svg) {
fill: var(--color-button-action);
}
Expand Down

0 comments on commit 4cf24c9

Please sign in to comment.