Skip to content
Browse documentation

One call for a move: the element’s edges let go first and everything spirals into its own centre, as if it went somewhere.

Used forInbox and feedsFile managerAI image historyTask boards

Install with the shadcn CLI

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

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

  • Inbox and feeds

    Archive a message, a card or a notification.

  • File manager

    Move an image into a folder and see it go in.

  • AI image history

    Send a generation to a collection or a project.

  • Task boards

    Mark a card done and drain it from the board.

What it handles for you

Archiving usually looks like deleting, which makes people wonder whether they just lost something.

Instead of wiring upvortex animationgenie effectarchive animationframer-motion exit animation
  1. Says where it went

    A spiral into the centre reads as moved, not destroyed, so archive and delete look different.

  2. One call, any element

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

  3. Edges first

    The outside lets go first and the middle last, so the picture shrinks into itself.

  4. Undo spins it out

    undoAway plays it back from the centre, from wherever it is.

  5. Real colours

    Pictures are read pixel by pixel, so the spiral is the picture itself.

  6. Pictures from anywhere

    Without CORS the element closes behind a shrinking round mask and the grains take its own colours.

Overview

For the removal that isn’t a delete. When something is archived, moved to a folder or sent, it hasn’t been destroyed, it has gone somewhere, and sand or embers would say the wrong thing. Call drainAway on it: the edges let go first and every grain spirals in towards the middle, shrinking as it turns, until the picture is a point and then nothing. The promise resolves and you remove it from the list it left. undoAway spins it back out from the centre.

States

draining
The edge lets go first over the first 58% of the run; each grain is pulled to the centre as the square of its life, turning up to 3.6 radians and shrinking to a quarter. About 1s on a picture, 0.6s on a row.
gone
The last grain reaches the centre and fades. drainAway resolves true; the element stays hidden in place until you remove it.
undoing
undoAway plays it back 30% quicker: the grains spin out from the centre into place.
reduced motion
The element fades out and back in, in 160ms.

Usage

usage.tsx
import { drainAway } from "@/components/drain-away";await drainAway(cardRef.current);await archive(card.id);setCards((list) => list.filter((c) => c.id !== card.id));

Archive with Undo

Drain the card away, archive it on your server, and let Undo spin it back out. This uses sonner, but any toast works.

example.tsx
"use client";import * as React from "react";import { toast } from "sonner";import { drainAway, undoAway } from "@/components/drain-away";export function ArchiveButton({ target, id, onArchived }: { target: React.RefObject<HTMLElement | null>; id: string; onArchived: (id: string) => void }) {  return (    <button      onClick={async () => {        if (!(await drainAway(target.current))) return;        await fetch(`/api/cards/${id}/archive`, { method: "POST" });        toast("Archived", {          action: {            label: "Undo",            onClick: async () => {              await fetch(`/api/cards/${id}/unarchive`, { method: "POST" });              undoAway(target.current);            },          },          onAutoClose: () => onArchived(id),        });      }}    >      Archive    </button>  );}

Props

drainAway(element, options?)
Promise<boolean>
Drains the element away. 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>
Spins it back out 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= 1000 (600 on rows)
number
Milliseconds for the whole removal.

Accessibility and motion

  • The spiral is worked out per grain from where it sat, so wide rows drain into a flat point and squares into a round one.
  • 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.
  • Announce the move in your own status line; 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";/* ───────────────────────────────────────────────────────── * DRAIN AWAY: it spirals into its own centre * * One call on any element: `await drainAway(element)`. The edges * let go first and everything spirals into a point at the middle, * shrinking as it goes. For moves where the thing went somewhere: * archive, move to a folder, send. `undoAway(element)` spins it * back out. * * 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 drainAway(element: HTMLElement | null | undefined, options?: AwayOptions): Promise<boolean> {  return playAway(element, "drain", options);}

Registry item: /r/drain-away.json