Animated List

Animated

A live list that animates rows arriving, leaving, and the rows they push aside.

Source
$npx @dinachi/cli@latest add animated-list
  • Deploy finished

    web · 2m 14s

  • Rate limit at 80%

    api · us-east-1

  • 3 new sign-ups

    since 09:00

from
duration
dismissed

Usage

import { useState } from "react"
import { AnimatedList, AnimatedListItem } from "@/components/ui/animated-list"

export function Notifications({ initial }: { initial: { id: string; title: string }[] }) {
  const [rows, setRows] = useState(initial)
  const [dismissed, setDismissed] = useState<string | null>(null)

  const dismiss = (id: string) => {
    setDismissed(id)
    setRows((current) => current.filter((row) => row.id !== id))
  }

  return (
    <AnimatedList dismissed={dismissed}>
      {rows.map((row) => (
        <AnimatedListItem key={row.id} itemKey={row.id}>
          {row.title}
          <button type="button" onClick={() => dismiss(row.id)}>
            Dismiss
          </button>
        </AnimatedListItem>
      ))}
    </AnimatedList>
  )
}

Examples

  • Deploy finished

    web · 2m 14s

  • Rate limit at 80%

    api · us-east-1

  • 3 new sign-ups

    since 09:00

A feed whose rows enter, leave and make room for each other.
import { AnimatedList, AnimatedListItem } from '@/components/ui/animated-list';

export function Example() {
  const [rows, setRows] = React.useState(SEED);
  const [dismissed, setDismissed] = React.useState<string | null>(null);

  const dismiss = (id: string) => {
    setDismissed(id);
    setRows((current) => current.filter((row) => row.id !== id));
  };

  return (
    <AnimatedList dismissed={dismissed} className="space-y-2">
      {rows.map((row) => (
        <AnimatedListItem key={row.id} itemKey={row.id}>
          <Row row={row} onDismiss={() => dismiss(row.id)} />
        </AnimatedListItem>
      ))}
    </AnimatedList>
  );
}

Notes

Motion tier

Needs motion. add --all skips it; install with add --motion or by name.

What animates

  • A new row fades in from the from edge.
  • A removed row leaves layout at once, so the gap closes immediately.
  • Every other row springs to its new position.

Dismissed rows

Pass the key of a row the reader closed as dismissed, in the same update that removes it. That row slides out sideways; other removals collapse in place.

const dismiss = (id: string) => {
  setDismissed(id)
  setRows((current) => current.filter((row) => row.id !== id))
}

When to use it

  • A feed, inbox or activity stream that changes a row or two at a time while someone watches.
  • For a list that only appears, use Stagger List.
  • Skip it when the whole list changes on every keystroke.

Behaviour

  • Nothing animates on first render.
  • AnimatedListItem throws outside an AnimatedList.

API

from"top" | "bottom" = "top"
The edge new rows arrive from. A feed that grows downward wants bottom.
dismissedstring | null = null
The itemKey of the row the reader closed. Set it in the same update that removes the row.
durationnumber = 0.3
Seconds for each row's own animation. The reflow spring is scaled from it.

Accessibility

  • Keeps ul and li semantics.
  • Reduced motion drops the travel; rows still move to their new place in one frame.
  • Changes are not announced. Use a live region if a new row matters.