# Animated List

> Reveal items one at a time with the newest on top, as a column or a stack of notifications.

Source: https://www.honestui.com/docs/animated/animated-list

```tsx
"use client";

import { CreditCard, GitPullRequest, MessageSquare, RotateCcw, Rocket, UserPlus } from "honestui/icons";
import { useState, type ComponentType } from "react";

import { AnimatedList, type AnimatedListLayout } from "@/registry/default/animated/animated-list";
import { cn } from "@/lib/utils";

type Notification = {
  id: string;
  icon: ComponentType<{ className?: string }>;
  title: string;
  detail: string;
  time: string;
};

const notifications: Notification[] = [
  { id: "payment", icon: CreditCard, title: "Payment received", detail: "$1,240.00 from Northwind", time: "2m" },
  { id: "signup", icon: UserPlus, title: "New sign-up", detail: "maria@lumen.studio joined Pro", time: "5m" },
  { id: "deploy", icon: Rocket, title: "Deploy succeeded", detail: "web · main · 41s", time: "9m" },
  { id: "review", icon: GitPullRequest, title: "Review requested", detail: "Fix invoice rounding #482", time: "14m" },
  { id: "comment", icon: MessageSquare, title: "New comment", detail: "“Looks good, ship it.”", time: "20m" },
];

function NotificationCard({ icon: Icon, title, detail, time }: Notification) {
  return (
    <div className="flex items-center gap-3 rounded-xl border border-border bg-card p-3 shadow-sm">
      <span className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-muted text-foreground">
        <Icon className="size-4" />
      </span>
      <div className="min-w-0 flex-1">
        <div className="flex items-baseline justify-between gap-2">
          <span className="truncate text-sm font-medium text-foreground">{title}</span>
          <span className="shrink-0 text-xs text-muted-foreground">{time}</span>
        </div>
        <span className="block truncate text-[13px] text-muted-foreground">{detail}</span>
      </div>
    </div>
  );
}

export function AnimatedListDemo() {
  const [layout, setLayout] = useState<AnimatedListLayout>("list");
  const [run, setRun] = useState(0);

  return (
    <div className="flex w-full max-w-sm flex-col gap-4">
      <div className="flex items-center justify-between gap-2">
        <div role="group" aria-label="Layout" className="flex gap-1 rounded-lg bg-muted p-1">
          {(["list", "stack"] as const).map((value) => (
            <button
              key={value}
              type="button"
              aria-pressed={layout === value}
              onClick={() => {
                setLayout(value);
                setRun((count) => count + 1);
              }}
              className={cn(
                "h-7 cursor-pointer rounded-md px-3 text-xs font-medium text-muted-foreground capitalize transition-colors outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
                layout === value && "bg-background text-foreground shadow-sm ring-1 ring-border/60 dark:bg-foreground/10 dark:ring-0",
              )}
            >
              {value}
            </button>
          ))}
        </div>
        <button
          type="button"
          onClick={() => setRun((count) => count + 1)}
          className="inline-flex h-7 cursor-pointer items-center gap-1.5 rounded-md border border-border px-2 text-xs font-medium text-foreground transition-colors outline-none hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring"
        >
          <RotateCcw className="size-3.5" />
          Replay
        </button>
      </div>
      <div className="h-[340px]">
        <AnimatedList key={run} layout={layout} delay={1100} maxVisible={4} live>
          {notifications.map((notification) => (
            <NotificationCard key={notification.id} {...notification} />
          ))}
        </AnimatedList>
      </div>
    </div>
  );
}

```

## Overview [#overview]

Animated List shows a feed arriving. Items appear one at a time at a steady pace, the newest springs in at the top, and older items move down or leave once the list reaches its maximum. The `stack` layout piles items like notifications, with older ones tucked behind the newest. Items added to the list later join the queue, so it also works for live feeds.

## Installation [#installation]

<CliBlock commands="[&#x22;animated-list&#x22;]" />

## Usage [#usage]

```tsx
import { AnimatedList } from "@/components/animated/animated-list"

<AnimatedList delay={1000} maxVisible={4} layout="stack" live>
  {notifications.map((item) => (
    <NotificationCard key={item.id} {...item} />
  ))}
</AnimatedList>
```

Pass items oldest first, each with a stable `key`. Set `delay` to `0` to show every item at once and animate only new arrivals.

## Accessibility [#accessibility]

Set `live` when new items matter to the reader, such as notifications: the list becomes a polite live region that announces additions without interrupting. In the stack layout, items tucked behind the newest one are hidden from assistive technology because they are not readable on screen. With reduced motion enabled, items fade in without scaling or sliding.

## API Reference [#api-reference]


  ### `children`

type: `ReactNode`

Items in arrival order, oldest first, each with a stable key.

  ### `delay`

type: `number` · default: `1000`

Milliseconds between reveals. 

    `0`

     shows every item at once.

  ### `maxVisible`

type: `number` · default: `4`

Maximum items shown. Older items leave as new ones arrive.

  ### `layout`

type: `&#x22;list&#x22; | &#x22;stack&#x22;` · default: `&#x22;list&#x22;`

A column, or a pile of notifications.

  ### `stackOffset`

type: `number` · default: `10`

Vertical offset between stacked items, in px.

  ### `live`

type: `boolean` · default: `false`

Announces new items politely to screen readers.

  ### `className`

type: `string`

Classes for the list.

  ### `itemClassName`

type: `string`

Classes for the wrapper around each item.
