
Building a Project Preview Component: Layers, Motion, and Adaptation
ProjectPreview starts as a still image. If a project has a clip or enough screenshots for a preview, you can see them on hover. Click the card to open the project dialog.
I wanted the cards to stay still while you scan the homepage. On hover, the preview appears behind the artwork, and the centered project mark fades as a smaller copy appears in the corner. You can still see the original background through the clip.
The demo uses the same component and project data as the homepage. It's built with React and Next, with next/image for the background, Tailwind for styling, and Motion Primitives for the dialog and carousel.
Layering the hover state
The background and portrait are raster images. ProjectThumbnail places the symbol and wordmark above the background, with the hover credits in a separate group and room for a video behind the artwork. I can move, resize, or hide each piece independently. The card has a 1.91:1 aspect ratio, and both SVGs use a 1200 × 630 coordinate system.
Each artwork entry in project.thumb supplies href, x, y, width, and height. An SVG URL includes the asset's root ID, as in /projects/api/symbol.svg#artwork, while the portrait points to a PNG. Projects can reuse the same credit data. For telli, signature is null, so the bottom-right credit is omitted.
import { type Project } from '@/app/data'
import { cn } from 'cn'
import Image from 'next/image'
import { type ReactNode } from 'react'
const THUMBNAIL_SIZES =
'(max-width: 640px) calc(100vw - 2rem), (max-width: 768px) 50vw, 368px'
interface ProjectThumbnailProps {
project: Project
previewing: boolean
children: ReactNode
}
export function ProjectThumbnail({
project,
previewing,
children,
}: ProjectThumbnailProps) {
const { color, symbol, wordmark, portrait, authorWordmark, signature } =
project.thumb
const cornerScale = authorWordmark.height / wordmark.height
return (
<div className="group relative aspect-[1.91/1] w-full overflow-hidden">
<Image
src={`/projects/backgrounds/${color}.png`}
alt={`${project.name} background`}
className="size-full squircle-thumb object-cover dark:brightness-90 dark:filter"
width={1000}
height={1000}
sizes={THUMBNAIL_SIZES}
draggable={false}
/>
{children}
<svg
viewBox="0 0 1200 630"
aria-hidden="true"
className={cn(
'pointer-events-none absolute inset-0 size-full transition-opacity duration-1000 ease-[cubic-bezier(0.4,0,0.2,1)] motion-reduce:transition-none dark:invert',
previewing
? 'opacity-0 delay-150 duration-700'
: 'opacity-100 delay-0',
)}
style={{ transform: 'translate(-2.5px, 2.5px)' }}
>
<use {...symbol} />
<use {...wordmark} />
</svg>
<svg
viewBox="0 0 1200 630"
aria-hidden="true"
className="pointer-events-none absolute inset-0 z-20 size-full"
>
<g
transform={`translate(${portrait.x} 40) scale(${cornerScale}) translate(${-symbol.x} ${-Math.min(symbol.y, wordmark.y)})`}
className={cn(
'transition-opacity duration-1000 ease-[cubic-bezier(0.4,0,0.2,1)] motion-reduce:transition-none dark:invert',
previewing
? 'opacity-100 delay-150 duration-700'
: 'opacity-0 delay-0',
)}
>
<use {...symbol} />
<use {...wordmark} />
</g>
<g className="opacity-0 transition-opacity delay-0 duration-1000 ease-[cubic-bezier(0.4,0,0.2,1)] group-hover:opacity-100 group-hover:delay-150 group-hover:duration-700 motion-reduce:transition-none">
<image {...portrait} />
<use {...authorWordmark} className="dark:invert" />
{signature && <use {...signature} className="dark:invert" />}
</g>
</svg>
</div>
)
}
The background fills the frame with object-cover, and the shared viewBox keeps the SVG positions proportional as the card scales. One CSS transition fades in the entire credit group. It waits 150 milliseconds, takes 700 milliseconds to fade in, and takes a second to fade out when you move the pointer away.
Video and screenshots on hover
ProjectHoverThumbnail controls playback and passes the media into the artwork component. It waits until the first mouse hover to load a clip, and only does so if the project has a previewVideo. The preview is a muted, looping MP4 even when the full project video is on YouTube.
The marks use the same 150-millisecond delay and 700-millisecond fade as the credits. The centered mark fades out while a smaller copy appears at the top left, with lettering the same height as the author credit. The clip takes 1.1 seconds to reach 60% opacity, so the background stays visible through it.
Move the pointer away and the clip pauses immediately, then fades out over 1.1 seconds. The centered artwork starts fading back in right away and takes a second to return. Hover again to reverse the fade and resume the clip from the frame where it paused.
I kept the shots long, used soft dissolves, and cropped each clip for the card. The clips have no audio tracks. The artwork stays still on touch devices and for people who prefer reduced motion. Playback stops when the card leaves the viewport, when you switch tabs, or when you open the dialog.
Screenshot previews use the same reveal. They alternate between corner crops and full-window views, with the screenshot's own background showing along two edges. Each shot holds still for six seconds, and the text stays distinct when the shot changes. Move the pointer away to pause the cycle, then hover again to pick up where you left off.
Mark a screenshot frame: 'hidden' to keep it in the full gallery and skip it in the hover cycle. Projects with fewer than two eligible screenshots keep their regular thumbnail. The preview and gallery use the same light and dark image variants.
Dark mode by layer
I use dark:brightness-90 to tone down saturated backgrounds on a dark page. The project symbol and wordmark use dark:invert, as do the author wordmark and signature. The portrait keeps its original colors.
From card to focused view
Click or tap the card and it expands into the dialog. I set the spring's bounce to zero so the dialog settles without overshooting. It opens with the project video when there is one. Projects with screenshots open a carousel you can browse with the arrow keys.
<MorphingDialog
open={open}
onOpenChange={setOpen}
transition={{ type: 'spring', bounce: 0, duration: 0.3 }}
>
<MorphingDialogTrigger>
<ProjectHoverThumbnail project={project} disabled={open} />
</MorphingDialogTrigger>
<MorphingDialogContent className="max-w-5xl rounded-2xl bg-zinc-50 p-1 ring-1 ring-zinc-200/50 dark:bg-zinc-900 dark:ring-zinc-800/50">
{project.videos?.length ? (
<iframe /* YouTube embed */ />
) : (
<Carousel>{/* Images */}</Carousel>
)}
</MorphingDialogContent>
</MorphingDialog>
The links in the dialog move slightly toward the pointer. The dialog primitive manages focus and closes the dialog when you press Escape.
next/image sizes and lazy-loads the background. CSS handles the fades, and React starts and stops playback. The background uses draggable={false}, and pointer-events-none keeps the SVG artwork from intercepting clicks. The background alt text names the project, and the decorative SVGs use aria-hidden.
TL;DR
Keep the artwork in separate layers and reuse the same positions and assets for the still card and its hover state. When you want to resize a mark or drop a credit, you can edit the project data without exporting a new thumbnail.
