Morphiq

Components / Animations / Shatter Reveal

Shatter Reveal

An image over content that breaks when struck. The shards are a Voronoi diagram seeded densely around the impact and Lloyd-relaxed out of slivers, and each is a rigid body: its mass is its area and its moment of inertia is its own polygon’s. The strike lands at each shard’s nearest corner, so r × J spins the small pieces near the impact and barely turns the far ones, and quadratic drag lets the small ones flutter down last. Press and hold to crack it, let go to strike, slide off to change your mind; Space does the same from the centre and Enter strikes outright. Setting shattered back to false springs every shard home from wherever it is.

Usage

import ShatterReveal from '@/components/shatter-reveal'

<ShatterReveal src={photo} alt="Cover" shattered={open} onShatter={() => setOpen(true)}>
  {content}
</ShatterReveal>

Installation

npx shadcn@latest add https://morphiq.prathampatel.design/r/shatter-reveal.json

Model

ω = (r × J) / I,   m·a = mg − c·|v|·v·√A

I the shard’s own polygon inertia · m its area · J the strike

Props

PropertyTypeDefaultDescription
srcstring—The image that breaks.
altstring''Describes the image; the strike button is named from it.
shatteredboolean—Controlled state. Leave undefined to shatter on click or Enter. Setting it back to false mends the image.
defaultShatteredbooleanfalseUncontrolled: start already broken, with the content showing. Default false.
onShatter(point: { x: number; y: number }) => void—Called with the impact point, in px from the top-left, when the image is struck.
onSettle() => void—Called once the last shard has fallen out of view.
onRestore() => void—Called once the image is whole again after shattered goes back to false. Not called if it is struck again first.
shardsnumber56Number of shards. Default 56.
relaxnumber2Lloyd relaxation passes. 0 leaves raw Voronoi cells, slivers included. Default 2.
impulsenumber560Strike speed at the point of impact, px/s. Default 560.
gravitynumber2400px/s². Default 2400.
dragnumber0.0011Quadratic drag coefficient. Higher makes small shards flutter. Default 0.0011.
cracknumber5200Speed of the crack front, px/s. A shard lets go a beat after the front passes it. 0 breaks everything at once. Default 5200.
mendnumber0.5Seconds for the struck shard to come home when the image is restored; the far ones seat sooner. 0 restores instantly. Default 0.5.
sheennumber0.08Strength of the light under a hovering pointer, 0–1. 0 turns it off. Default 0.08.
seednumber7Seed for the fracture pattern. The same seed breaks the same way. Default 7.
fit'cover' | 'contain''cover'How the image fills the box. Default 'cover'.
childrenReactNode—What the image covers.