Skip to content
Browse documentation

One call to discard: the element cracks into shards that kick outward and drop, bottom first.

Used forImage variationsDraftsReview queuesGames and rewards

Install with the shadcn CLI

$ npx shadcn@latest add https://hairlineui.com/r/shatter-away.json

Registered the namespace? Then it’s shadcn add @hairline/shatter-away. 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.

All 61 templates

Where it’s used

  • Image variations

    Reject the takes you didn’t pick from a batch of generations.

  • Drafts

    Scrap a draft, a version or a suggestion you won’t use.

  • Review queues

    Reject a submission or a flagged item and see it break up.

  • Games and rewards

    Break a card, a crate or a badge open in a product moment.

What it handles for you

A reject usually looks like a delete, so it carries no sense of the choice you just made.

Instead of wiring upshatter effect cssglass break animationframer-motion exit animationdiscard animation
  1. Pieces, not dust

    Grains in a shard share their seeds, so each shard moves as one piece with a hairline crack around it.

  2. One call, any element

    shatterAway(element) works on an image, a card or a row; your state and API stay yours.

  3. Bottom first

    The lower shards drop first, so the break reads as falling, not exploding.

  4. Undo puts it back

    undoAway plays it back: the shards rise and lock into place.

  5. Real colours

    Pictures are read pixel by pixel, so the shards are the picture itself.

  6. Pictures from anywhere

    Without CORS the element is masked in place and the shards take its own colours.

Overview

For throwing something out rather than deleting it. Call shatterAway on the take, draft or card being rejected: it cracks along a hidden grid into shards of a few dozen grains each, the bottom ones go first, and every shard is kicked outward and then pulled down as one piece, so you see pieces falling, not dust. It suits the moment you reject an option (the generations you didn’t keep, a draft you scrap) where sand would feel too gentle. The promise resolves and you remove it from your state; undoAway puts the shards back.

States

shattering
Shards (a 7 × 9 grid, broken up by noise) let go bottom first over the first 58% of the run. Each is kicked up to 32px outward and 12px up, then falls 90 to 170px, fading late. About 1.05s on a picture, 0.6s on a row.
gone
The last shard fades. shatterAway resolves true; the element stays hidden in place until you remove it.
undoing
undoAway plays it back 30% quicker: the shards rise and lock together.
reduced motion
The element fades out and back in, in 160ms.

Usage

usage.tsx
import { shatterAway } from "@/components/shatter-away";await shatterAway(cardRef.current);setDrafts((list) => list.filter((d) => d.id !== draft.id));

Rejecting the takes you didn’t keep

Keep one generation and break up the rest at once, then save the choice.

example.tsx
"use client";import * as React from "react";import { shatterAway } from "@/components/shatter-away";export function Takes({ images, onKeep }: { images: { id: string; url: string }[]; onKeep: (id: string) => Promise<void> }) {  const tiles = React.useRef(new Map<string, HTMLElement>());  async function keep(id: string) {    await Promise.all(images.filter((i) => i.id !== id).map((i) => shatterAway(tiles.current.get(i.id))));    await onKeep(id);  }  return (    <div className="grid grid-cols-2 gap-2">      {images.map((i) => (        <button key={i.id} ref={(el) => { if (el) tiles.current.set(i.id, el); }} onClick={() => keep(i.id)}>          <img src={i.url} alt="" crossOrigin="anonymous" className="aspect-square rounded-xl object-cover" />        </button>      ))}    </div>  );}

Props

shatterAway(element, options?)
Promise<boolean>
Shatters the element. Resolves true once it has gone (it stays hidden in place until you remove it), or false if undoAway brought it back first.
undoAway(element)
Promise<boolean>
Puts the shards back and shows the element again. Resolves true once it is back.
isAway(element)
boolean
True while the element is removed or being removed and not brought back.
options.duration= 1050 (630 on rows)
number
Milliseconds for the whole removal.

Accessibility and motion

  • Shards are groups of grains on one grid that share their motion and meet edge to edge, so each is a solid piece; the cracks open as neighbouring shards part.
  • Pictures are drawn from their pixels in a canvas over the page while the element is hidden in place; serve pictures from other origins with CORS and crossOrigin="anonymous" for their real colours.
  • Move focus somewhere sensible after a discard; the element leaves the accessibility tree once hidden.
  • Under reduced motion the element fades out and in instead.

Requirements

React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

Source

"use client";/* ───────────────────────────────────────────────────────── * SHATTER AWAY: it cracks into shards and drops * * One call on any element: `await shatterAway(element)`. The * picture cracks into shards along a hidden grid; the bottom ones * go first, each shard kicked outward and then pulled down as one * piece. For rejecting and discarding: the takes you didn't keep. * `undoAway(element)` puts the shards back. * * Nothing about your app is taken over: no list, no toast, no * timer, no API. Pictures (an <img>, <canvas> or <video>, or an * element holding one) are drawn grain by grain from their real * pixels in a layer over the page while the element itself is * hidden in place; anything else, or a picture from another * origin without CORS, keeps its own element behind a moving * mask with grains in its own colours. * ───────────────────────────────────────────────────────── */import { isAway, playAway, undoAway, type AwayOptions } from "./image-grains";export type { AwayOptions };export { isAway, undoAway };/** Removes the element. Resolves true once it has gone (it stays hidden in place until you remove it), or false if undoAway brought it back first. */export function shatterAway(element: HTMLElement | null | undefined, options?: AwayOptions): Promise<boolean> {  return playAway(element, "shatter", options);}

Registry item: /r/shatter-away.json