misc: optimize how expandable images are handled
This commit is contained in:
1 parent
60dfbabc60
commit
62044ce3b7
5 files changed
+68
-53
No files matched your search
@@ -1,4 +1,15 @@
|
||||
<script lang="ts" context="module">
|
||||
import { pushState } from '$app/navigation'
|
||||
|
||||
export function showImage(url: string, alt: string = '') {
|
||||
pushState('', {
|
||||
openImage: url,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { Icon, XMark } from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
@@ -7,18 +18,10 @@
|
||||
/**
|
||||
* The full-resolution image URL
|
||||
*/
|
||||
export let url: string
|
||||
export let alt: string = ''
|
||||
export let open: boolean = false
|
||||
</script>
|
||||
|
||||
<svelte:body
|
||||
on:keydown={(e) => {
|
||||
if (open && e.code == 'Escape') open = false
|
||||
}}
|
||||
/>
|
||||
|
||||
{#if open}
|
||||
{#if $page.state.openImage || '' != ''}
|
||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
@@ -27,19 +30,15 @@
|
||||
class="!isolate fixed top-0 left-0 w-screen h-screen overflow-auto bg-black/50
|
||||
flex flex-col z-[200] overscroll-contain"
|
||||
transition:fade={{ duration: 200 }}
|
||||
on:click={() => (open = false)}
|
||||
on:click={() => history.back()}
|
||||
>
|
||||
<Button
|
||||
size="square-md"
|
||||
class="fixed z-[110] top-0 right-0 m-4"
|
||||
on:click={() => (open = false)}
|
||||
>
|
||||
<Button size="square-md" class="fixed z-[110] top-0 right-0 m-4">
|
||||
<Icon src={XMark} size="16" mini slot="prefix" />
|
||||
</Button>
|
||||
<img
|
||||
width={400}
|
||||
height={400}
|
||||
src={url}
|
||||
src={$page.state.openImage}
|
||||
class="w-full h-auto object-contain max-w-screen-sm mx-auto my-auto overscroll-contain bg-white dark:bg-zinc-900"
|
||||
transition:scale={{ start: 0.9, easing: expoOut }}
|
||||
{alt}
|
||||
@@ -47,6 +46,6 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<button on:click={() => (open = !open)} class="contents {$$props.class}">
|
||||
<button on:click={() => history.back()} class="contents {$$props.class}">
|
||||
<slot />
|
||||
</button>
|
||||
Reference in new issue
Block a user