Grain revealNew
A generated image gathers from grains of its own colours, centre first, and locks sharp. Sand away, in reverse.
Used forImage generatorsAI avatarsUpscalersGalleries
Install with the shadcn CLI
Registered the namespace? Then it’s shadcn add @hairline/grain-reveal. Set it up
Templates
Need the whole page?
61 Next.js landing pages, each designed from scratch. Try any of them live; one is $39, all of them $159, and 6 are free.
Where it’s used
Image generators
The result of a prompt assembling in place.
AI avatars
A generated portrait gathering into its frame.
Upscalers
The upscaled image arriving over the old one.
Galleries
New generations landing in a grid, paired with Sand away for deletes.
What it handles for you
Generated images usually pop in, or fade in from a grey box, which says nothing about the work behind them.
Grains of the real picture
Each grain carries a real pixel colour, so the gather is the image itself arriving.
Nothing before pixels
While it waits the grains are neutral; colour only appears once the image exists.
Centre first
The middle locks in first and the edges follow, so the subject is readable early.
Pairs with Sand away
The same engine runs both ways: gather here, blow away there.
Safe without CORS
If the image can’t be read, it sharpens out of a blur instead of failing.
Sleeps off screen
The waiting grains only draw while the frame is on screen.
Overview
A reveal that is honest about where the picture comes from. While your generation runs, a few neutral grains drift in the frame: no colours, because there are no pixels yet. When the image is ready and loaded, it is cut into grains of its real colours that swirl in from around their places, the centre first and the edges after, and lock into the sharp picture over 1.5s. It is Sand away played backwards, so the two make a pair: what you generate gathers, what you delete blows away. Reading the colours needs an image served with CORS; without it, the picture simply sharpens out of a blur.
States
- waiting
- 150 neutral grains in the text colour drift slowly at 12–28% opacity, drawn only while the frame is on screen.
- gathering
- Up to 7,000 grains of the image’s colours swirl in from 18–62px around their places, centre first, over 1.5s; the last 20% crossfades into the sharp picture.
- shown
- The plain image. onReady fires.
- without CORS
- The image sharpens from blur(12px) over 0.9s instead of gathering.
- failed
- The well with “This image couldn’t be created.” and Try again when onRetry is passed.
Usage
Works with
Polling your generation API
Start a generation, poll its status, and hand the component the real state. Any API that reports generating, ready and failed works the same way.
Props
- src
- string
- The generated image. It can arrive before or with status "ready"; the reveal waits until it has loaded and decoded.
- status
- "generating" | "ready" | "error"
- Your generation’s real state. Nothing plays on a timer.
- progress
- number
- 0 to 1, if your API reports it. Shown as a small rolling figure; without it, no number is shown.
- alt
- string
- The image’s text alternative, usually its prompt.
- crossOrigin
- "anonymous" | "use-credentials"
- Set it when your image host sends CORS headers.
- onReady
- () => void
- Called once the reveal has played, or the image is shown without one.
- onRetry
- () => void
- Shows Try again when the generation fails.
- labels
- { generating?, ready?, failed?, retry? }
- Words for the progress tag, the announcements and the failure.
- className
- string
- Size the frame here, e.g. "aspect-square w-72".
Accessibility and motion
- It follows your status: it waits while "generating", and plays only once status is "ready" and the image has loaded and decoded (img.decode), so it can never finish before the picture does. An image that was already there when the page loaded is simply shown.
- The figure has aria-busy while it waits, and a status line announces Generating, Image ready or the failure; the image keeps its alt text.
- The gather draws on one canvas only while it plays, and is removed when the image is shown.
- Serve your images with CORS and pass crossOrigin="anonymous" for the grains; setting crossOrigin on a host without CORS headers makes the image fail to load, so leave it off there.
- Under reduced motion the image appears in place, with no drift while waiting.
Requirements
React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.
The CLI also installs Number roll.
Source
Registry item: /r/grain-reveal.json


