Commit 04a91152 authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

feat: esc image preview

parent 7874bea5
<script lang="ts">
import { onMount } from 'svelte';
export let show = false;
export let src = '';
export let alt = '';
let mounted = false;
const downloadImage = (url, filename) => {
fetch(url)
.then((response) => response.blob())
......@@ -18,6 +22,27 @@
})
.catch((error) => console.error('Error downloading image:', error));
};
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
console.log('Escape');
show = false;
}
};
onMount(() => {
mounted = true;
});
$: if (mounted) {
if (show) {
window.addEventListener('keydown', handleKeyDown);
document.body.style.overflow = 'hidden';
} else {
window.removeEventListener('keydown', handleKeyDown);
document.body.style.overflow = 'unset';
}
}
</script>
{#if show}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment