← Components

Communication

Activity stack

A compact stack of recent events. New ones push in on top; older ones compress into a deck of three; hover or focus fans it out.

Examples and variants

Deck

Push an event, then hover the stack.

  1. Alex commented“Love the new toast.”
  2. Mo joined NorthwindEditor
  3. Pushed 3 commitsfix/minimal-base
Example
function ActivityDeck() {
  const [items, setItems] = useState(events)
  return (
    <div className="flex w-full max-w-xs flex-col gap-4">
      <ActivityStack items={items} />
      <Button
        size="sm"
        variant="secondary"
        className="self-center"
        onClick={() => setItems((all) => [{ id: Date.now(), title: "New upload", description: "brief-v2.pdf", icon: <UploadIcon /> }, ...all])}
      >
        Push an event
      </Button>
    </div>
  )
}

Spec drawing

Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.

Install

With the CLI

The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.

Terminal
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/activity-stack.json

By hand

No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.

  1. Install the packages it uses.

    Terminal
    npm install cn
  2. Copy this file to the same paths in your project. Imports use the @/ alias for your project root.

    • components/ui/activity-stack.tsxactivity-stack
      components/ui/activity-stack.tsx
      "use client"
      
      import * as React from "react"
      import { cn } from "cn"
      
      /*
        Activity stack: a compact stack of recent events. New events push in at
        the top; older ones compress behind it into a deck of three. Hover or
        focus expands the deck into a list.
      */
      type Activity = { id: string | number; title: React.ReactNode; description?: React.ReactNode; icon?: React.ReactNode }
      
      function ActivityStack({ items, label = "Recent activity", className }: { items: Activity[]; label?: string; className?: string }) {
        const [open, setOpen] = React.useState(false)
        const visible = items.slice(0, open ? items.length : 3)
        return (
          <ol
            aria-label={label}
            data-slot="activity-stack"
            data-open={open || undefined}
            tabIndex={0}
            onPointerEnter={() => setOpen(true)}
            onPointerLeave={() => setOpen(false)}
            onFocus={() => setOpen(true)}
            onBlur={(event) => {
              if (!event.currentTarget.contains(event.relatedTarget as Node)) setOpen(false)
            }}
            className={cn("activity-stack relative grid w-full outline-none focus-visible:shadow-(--focus-ring)", className)}
          >
            {visible.map((item, index) => (
              <li
                key={item.id}
                className="activity-card col-start-1 flex items-center gap-3 rounded-(--activity-corner) bg-(--activity-container) p-3 shadow-(--activity-elevation)"
                style={{ "--depth": index, zIndex: visible.length - index } as React.CSSProperties}
              >
                {item.icon ? <span className="flex size-8 shrink-0 items-center justify-center rounded-(--shape-full) bg-(--surface-container) [&_svg]:size-(--size-icon-sm)">{item.icon}</span> : null}
                <span className="min-w-0">
                  <span className="block truncate text-sm font-medium">{item.title}</span>
                  {item.description ? <span className="block truncate text-caption text-muted-foreground">{item.description}</span> : null}
                </span>
              </li>
            ))}
          </ol>
        )
      }
      
      export { ActivityStack }
      export type { Activity }
      

Imports

What the examples on this page import:

Imports
import {
import { ActivityStack, type Activity } from "@/components/ui/activity-stack"
import { Button } from "@/components/ui/button"
import { Dropzone } from "@/components/ui/dropzone"
import { DynamicIsland } from "@/components/ui/dynamic-island"
import { Progress } from "@/components/ui/progress"
import { RollingNumber } from "@/components/ui/rolling-number"
import { Spinner } from "@/components/ui/spinner"
import { Toggle } from "@/components/ui/toggle"
import { tokenMs } from "@/lib/motion/token-ms"

Anatomy

  1. 1Card · --activity-container, --activity-corner, --activity-elevation.
  2. 2Icon, title, description · Per event.

Props

PropTypeDefaultDescription
items{ id, title, description?, icon? }[]—Newest first.
labelstring"Recent activity"Accessible name.

Tokens

Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.

TokenPoints toLightDark
--activity-containervar(--surface-container-raised)oklch(1 0 0)oklch(0.22 0 0)
--activity-cornervar(--shape-lg)22pxsame
--activity-elevationvar(--elevation-2)0 1px 1px -0.5px oklch(0.22 0.01 260 / 6%), 0 3px 3px -1.5px oklch(0.22 0.01 260 / 6%), 0 6px 6px -3px oklch(0.22 0.01 260 / 6%), 0 12px 12px -6px oklch(0.22 0.01 260 / 6%), 0 24px 24px -12px oklch(0.22 0.01 260 / 6%)0 4px 12px oklch(0 0 0 / 40%), 0 12px 28px oklch(0 0 0 / 35%)

Motion

TriggerWhat happensTokens
Push / hoverNew card drops in; the deck compresses; hover expands it.--spring-snappy

Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.

Accessibility

  • An ordered list; focus expands it like hover.

Usage

Do

  • Use for a glanceable feed.

Don’t

  • Don't use for long histories (use List).

Code

components/ui/activity-stack.tsx
"use client"

import * as React from "react"
import { cn } from "cn"

/*
  Activity stack: a compact stack of recent events. New events push in at
  the top; older ones compress behind it into a deck of three. Hover or
  focus expands the deck into a list.
*/
type Activity = { id: string | number; title: React.ReactNode; description?: React.ReactNode; icon?: React.ReactNode }

function ActivityStack({ items, label = "Recent activity", className }: { items: Activity[]; label?: string; className?: string }) {
  const [open, setOpen] = React.useState(false)
  const visible = items.slice(0, open ? items.length : 3)
  return (
    <ol
      aria-label={label}
      data-slot="activity-stack"
      data-open={open || undefined}
      tabIndex={0}
      onPointerEnter={() => setOpen(true)}
      onPointerLeave={() => setOpen(false)}
      onFocus={() => setOpen(true)}
      onBlur={(event) => {
        if (!event.currentTarget.contains(event.relatedTarget as Node)) setOpen(false)
      }}
      className={cn("activity-stack relative grid w-full outline-none focus-visible:shadow-(--focus-ring)", className)}
    >
      {visible.map((item, index) => (
        <li
          key={item.id}
          className="activity-card col-start-1 flex items-center gap-3 rounded-(--activity-corner) bg-(--activity-container) p-3 shadow-(--activity-elevation)"
          style={{ "--depth": index, zIndex: visible.length - index } as React.CSSProperties}
        >
          {item.icon ? <span className="flex size-8 shrink-0 items-center justify-center rounded-(--shape-full) bg-(--surface-container) [&_svg]:size-(--size-icon-sm)">{item.icon}</span> : null}
          <span className="min-w-0">
            <span className="block truncate text-sm font-medium">{item.title}</span>
            {item.description ? <span className="block truncate text-caption text-muted-foreground">{item.description}</span> : null}
          </span>
        </li>
      ))}
    </ol>
  )
}

export { ActivityStack }
export type { Activity }