mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2025-09-05 17:00:39 +00:00
qr code
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
"copy-to-clipboard": "^3.3.3",
|
||||
"dompurify": "^2.4.1",
|
||||
"file-saver": "^2.0.5",
|
||||
"pretty-bytes": "^6.0.0"
|
||||
"pretty-bytes": "^6.0.0",
|
||||
"qrious": "^4.0.2"
|
||||
}
|
||||
}
|
||||
|
41
packages/frontend/src/lib/ui/Canvas.svelte
Normal file
41
packages/frontend/src/lib/ui/Canvas.svelte
Normal file
@@ -0,0 +1,41 @@
|
||||
<script lang="ts">
|
||||
import QR from 'qrious'
|
||||
|
||||
import { getCSSVariable } from '$lib/utils'
|
||||
|
||||
export let label: string
|
||||
export let value: string
|
||||
|
||||
let canvas: HTMLCanvasElement
|
||||
|
||||
$: {
|
||||
new QR({
|
||||
value,
|
||||
level: 'Q',
|
||||
size: 800,
|
||||
background: getCSSVariable('--ui-bg-0'),
|
||||
foreground: getCSSVariable('--ui-text-0'),
|
||||
element: canvas,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<small>{label}</small>
|
||||
<div>
|
||||
<canvas bind:this={canvas} />
|
||||
</div>
|
||||
|
||||
<style>
|
||||
div {
|
||||
padding: 0.5rem;
|
||||
width: fit-content;
|
||||
border: 2px solid var(--ui-bg-1);
|
||||
background-color: var(--ui-bg-0);
|
||||
margin-top: 0.125rem;
|
||||
}
|
||||
|
||||
canvas {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
</style>
|
@@ -10,9 +10,12 @@
|
||||
|
||||
import Button from '$lib/ui/Button.svelte'
|
||||
import TextInput from '$lib/ui/TextInput.svelte'
|
||||
import Canvas from './Canvas.svelte'
|
||||
|
||||
export let result: NoteResult
|
||||
|
||||
$: url = `${window.location.origin}/note/${result.id}#${result.password}`
|
||||
|
||||
function reset() {
|
||||
window.location.reload()
|
||||
}
|
||||
@@ -22,11 +25,15 @@
|
||||
type="text"
|
||||
readonly
|
||||
label={$t('common.share_link')}
|
||||
value="{window.location.origin}/note/{result.id}#{result.password}"
|
||||
value={url}
|
||||
copy
|
||||
data-testid="share-link"
|
||||
/>
|
||||
<br />
|
||||
|
||||
<div>
|
||||
<Canvas label={'qr code'} value={url} />
|
||||
</div>
|
||||
|
||||
<p>
|
||||
{@html $t('home.new_note_notice')}
|
||||
</p>
|
||||
@@ -34,4 +41,9 @@
|
||||
<Button on:click={reset}>{$t('home.new_note')}</Button>
|
||||
|
||||
<style>
|
||||
div {
|
||||
width: min(12rem, 100%);
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
</style>
|
||||
|
@@ -9,3 +9,8 @@ export function copy(value: string) {
|
||||
const msg = get(t)('common.copied_to_clipboard')
|
||||
notify.success(msg)
|
||||
}
|
||||
|
||||
export function getCSSVariable(variable: string): string {
|
||||
if (typeof window === 'undefined') return ''
|
||||
return window.getComputedStyle(window.document.body).getPropertyValue(variable)
|
||||
}
|
||||
|
Reference in New Issue
Block a user