This commit is contained in:
2023-01-04 19:40:37 +01:00
parent da527a0857
commit ad6f136dd0
7 changed files with 71 additions and 5 deletions

View File

@@ -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"
}
}

View 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>

View File

@@ -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>

View File

@@ -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)
}