Skip to content

Commit

Permalink
Add transition functions
Browse files Browse the repository at this point in the history
  • Loading branch information
stormwarning committed Nov 26, 2022
1 parent 4f017d3 commit c8225cd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/lib/components/gallery-carousel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type GalleryImage = (ImageRecord | ImageThumbnails) & {
export let images: Array<GalleryImage>
export let initialIndex: number
export let onClose: () => void
export let send
export let receive
let carousel: HTMLElement
Expand Down Expand Up @@ -60,6 +62,8 @@ function handleEscape(event: KeyboardEvent) {
class="flex snap-center items-center justify-center p-2 md:p-4 xl:p-8"
data-index={index}
on:click|self|stopPropagation={onClose}
in:receive={{ key: index }}
out:send={{ key: index }}
>
<div class="group relative">
<ImageLens {image} lazyLoad={false} />
Expand Down
4 changes: 4 additions & 0 deletions src/lib/components/lens-gallery.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import MasonryGrid from './masonry-grid.svelte'
export let images
export let isHidden
export let onOpen
export let send
export let receive
</script>

<MasonryGrid items={images} gapClass="gap-4 md:gap-8 xl:gap-16">
Expand All @@ -17,6 +19,8 @@ export let onOpen
class:opacity-30={isHidden}
data-index={index}
on:click={onOpen(index)}
in:receive={{ key: index }}
out:send={{ key: index }}
>
<ImageLens
image={item.thumbnails}
Expand Down
34 changes: 26 additions & 8 deletions src/routes/photos/screen-shots/[slug]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script>
import { crossfade, scale } from 'svelte/transition'
import GalleryCarousel from '$lib/components/gallery-carousel.svelte'
import LensGallery from '$lib/components/lens-gallery.svelte'
import PageIntro from '$lib/components/page-intro.svelte'
Expand All @@ -9,12 +11,22 @@ export let data
$: ({ title, subtitle, description, images, content } = data.json)
$: fullTitle = subtitle ? [title, subtitle].join(' ') : title
let isCarouselOpen = false
let isCarouselOpen = null
let initialIndex = 0
const [send, receive] = crossfade({
duration: 200,
fallback: scale,
})
async function handleOpenCarousel(index) {
isCarouselOpen = true
initialIndex = index
const image = new Image()
image.addEventListener('load', () => {
isCarouselOpen = true
initialIndex = index
})
image.src = `${images[index].path.replace(/^static/, '')}`
}
function handleCloseCarousel() {
Expand Down Expand Up @@ -44,13 +56,19 @@ function handleCloseCarousel() {
{images}
isHidden={isCarouselOpen}
onOpen={handleOpenCarousel}
{send}
{receive}
/>
{#if isCarouselOpen}
<GalleryCarousel
{images}
{initialIndex}
onClose={handleCloseCarousel}
/>
{#await isCarouselOpen then}
<GalleryCarousel
{images}
{initialIndex}
onClose={handleCloseCarousel}
{send}
{receive}
/>
{/await}
{/if}
<div class="prose prose-invert md:prose-xl">
{@html content}
Expand Down

0 comments on commit c8225cd

Please sign in to comment.