-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sharing): added qr code when note is created (#282)
- Loading branch information
1 parent
53a9d74
commit d2c26cb
Showing
9 changed files
with
203 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { castError } from '@corentinth/chisels'; | ||
|
||
export { svgToBase64Png }; | ||
|
||
function svgToBase64Png({ svg, width, height }: { svg: string; width: number; height: number }): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
const img = new Image(); | ||
|
||
img.width = width; | ||
img.height = height; | ||
|
||
img.onload = () => { | ||
const canvas = document.createElement('canvas'); | ||
const ctx = canvas.getContext('2d'); | ||
if (!ctx) { | ||
reject(new Error('Could not get 2d context')); | ||
return; | ||
} | ||
canvas.width = img.width; | ||
canvas.height = img.height; | ||
ctx.drawImage(img, 0, 0); | ||
resolve(canvas.toDataURL('image/png')); | ||
}; | ||
img.onerror = (err) => { | ||
reject(castError(err)); | ||
}; | ||
img.src = `data:image/svg+xml;base64,${btoa(svg)}`; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export { downloadBase64File, downloadFile, downloadSvgFile }; | ||
|
||
function downloadSvgFile({ svg, fileName }: { svg: string; fileName: string }) { | ||
const blob = new Blob([svg], { type: 'image/svg+xml' }); | ||
downloadFile({ blob, fileName }); | ||
} | ||
|
||
function downloadFile({ blob, fileName }: { blob: Blob; fileName: string }) { | ||
const url = URL.createObjectURL(blob); | ||
const a = document.createElement('a'); | ||
a.href = url; | ||
a.download = fileName; | ||
a.click(); | ||
URL.revokeObjectURL(url); | ||
} | ||
|
||
function downloadBase64File({ base64, fileName }: { base64: string; fileName: string }) { | ||
const a = document.createElement('a'); | ||
a.href = base64; | ||
a.download = fileName; | ||
a.click(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Toaster as Sonner } from 'solid-sonner'; | ||
|
||
export { toast } from 'solid-sonner'; | ||
|
||
export function Toaster(props: Parameters<typeof Sonner>[0]) { | ||
return ( | ||
<Sonner | ||
class="toaster group" | ||
toastOptions={{ | ||
classes: { | ||
toast: 'group toast group-[.toaster]:(bg-background text-foreground border border-border shadow-lg)', | ||
description: 'group-[.toast]:text-muted-foreground', | ||
actionButton: 'group-[.toast]:(bg-primary text-primary-foreground)', | ||
cancelButton: 'group-[.toast]:(bg-muted text-muted-foreground)', | ||
}, | ||
}} | ||
{...props} | ||
/> | ||
); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.