UIPin
ComponentsIconsIllustrationsMotionTemplatesApps
Boards
UIPin

Free, open-source UI components, icons, illustrations, motion, templates and apps, in one search. Every item links to its source and licence.

UIPin is free. If it saved you time, you can keep it running:

Buy me a coffee
ComponentsIconsIllustrationsMotionTemplatesAppsLibrariesCompareNew this weekMCP for agentsBoardsPrivacy

Components, icons and artwork belong to their authors and are shown under their open-source licences.

SmoothUI/Animated List

Data display
1 of 6
Compiling

Theme it

Every preview, live

Brand colour

Corner radius

Font

Recolours shadcn’s tokens, Tailwind’s accent colours and colours set in the code. Red, amber and green classes stay, since they usually mean error, warning or success.

6 versions·5 libraries

  • Animated List
  • Cult UI
  • Eldora UI
  • Magic UI
  • React Bits
  • Ai Task List

Animated List

A list that animates additions, removals and reordering, with an optional auto-feed mode.

npx shadcn@latest add https://smoothui.dev/r/animated-list.json
Open in v0 Docs Repo
Library
SmoothUI
License
MIT
Stack
React · Tailwind CSS · animated · base-ui
Packages
@base-ui/reactclass-variance-authoritymotion
Also adds
index
Size
162 lines
Demo
Written by UIPin: the library doesn’t ship a usage example, so the preview uses one of ours (in the code below).

Code

components/smoothui/animated-list/index.tsx

"use client";

import SmoothButton from "@/components/smoothui/smooth-button";
import { cn } from "@/lib/utils";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import type { ReactNode } from "react";
import { useEffect, useState } from "react";

const DEFAULT_MAX_VISIBLE = 5;
const DEFAULT_STAGGER = 0.05;
const DEFAULT_FEED_INTERVAL = 2000;
const MAX_STAGGER_DELAY = 0.3;
const RECEDE_OPACITY_STEP = 0.18;
const RECEDE_SCALE_STEP = 0.05;
const MIN_RECEDE_OPACITY = 0.35;
const MIN_RECEDE_SCALE = 0.85;
const ENTER_OFFSET = 14;
const SPRING_TRANSITION = {
  bounce: 0.1,
  duration: 0.25,
  type: "spring" as const,
};

export type AnimatedListItem = {
  content: ReactNode;
  id: string;
};

export type AnimatedListDirection = "up" | "down";

export type AnimatedListProps = {
  className?: string;
  direction?: AnimatedListDirection;
  feed?: boolean;
  feedInterval?: number;
  items: AnimatedListItem[];
  maxVisible?: number;
  onItemClick?: (id: string) => void;
  pauseOnHover?: boolean;
  stagger?: number;
};

const AnimatedList = ({
  items,
  direction = "down",
  maxVisible = DEFAULT_MAX_VISIBLE,
  stagger = DEFAULT_STAGGER,
  feed = false,
  feedInterval = DEFAULT_FEED_INTERVAL,
  pauseOnHover = true,
  onItemClick,
  className,
}: AnimatedListProps) => {
  const shouldReduceMotion = useReducedMotion();
  const [feedCount, setFeedCount] = useState(feed ? 0 : items.length);
  const [isPaused, setIsPaused] = useState(false);

  useEffect(() => {
    setFeedCount(feed ? 0 : items.length);
  }, [feed, items]);

  useEffect(() => {
    if (!feed || isPaused || feedCount >= items.length) {
      return;
    }

    const timer = window.setInterval(() => {
      setFeedCount((count) => Math.min(count + 1, items.length));
    }, feedInterval);

    return () => window.clearInterval(timer);
  }, [feed, isPaused, feedCount, items.length, feedInterval]);

  const activeItems = feed ? items.slice(0, feedCount) : items;
  const visibleItems = activeItems.slice(
    Math.max(0, activeItems.length - maxVisible)
  );
  const orderedItems =
    direction === "down" ? [...visibleItems].reverse() : visibleItems;

  const handleMouseEnter = () => {
    if (pauseOnHover) {
      setIsPaused(true);
    }
  };

  const handleMouseLeave = () => {
    if (pauseOnHover) {
      setIsPaused(false);
    }
  };

  return (
    <ul
      aria-live="polite"
      className={cn("flex flex-col gap-2", className)}
      onMouseEnter={handleMouseEnter}
      onMouseLeave={handleMouseLeave}
    >
      <AnimatePresence mode="popLayout">
        {orderedItems.map((item, index) => {
          const recedeOpacity = Math.max(
            MIN_RECEDE_OPACITY,
            1 - index * RECEDE_OPACITY_STEP
          );
          const recedeScale = Math.max(
            MIN_RECEDE_SCALE,
            1 - index * RECEDE_SCALE_STEP
          );
          const enterY = direction === "down" ? -ENTER_OFFSET : ENTER_OFFSET;
          const delay = shouldReduceMotion
            ? 0
            : Math.min(index * stagger, MAX_STAGGER_DELAY);

          return (
            <motion.li
              animate={
                shouldReduceMotion
                  ? { opacity: 1, scale: 1, y: 0 }
                  : { opacity: recedeOpacity, scale: recedeScale, y: 0 }
              }
              className="list-none"
              exit={
                shouldReduceMotion
                  ? { opacity: 0, transition: { duration: 0 } }
                  : { opacity: 0, scale: 0.9, y: 0 }
              }
              initial={
                shouldReduceMotion
                  ? { opacity: 1 }
                  : { opacity: 0, scale: 0.95, y: enterY }
              }
              key={item.id}
              layout
              transition={
                shouldReduceMotion
                  ? { duration: 0 }
                  : { ...SPRING_TRANSITION, delay }
              }
            >
              {onItemClick ? (
                <SmoothButton
                  className="h-auto w-full justify-start rounded-lg text-left font-normal"
                  onClick={() => onItemClick(item.id)}
                  type="button"
                  variant="ghost"
                >
                  {item.content}
                </SmoothButton>
              ) : (
                item.content
              )}
            </motion.li>
          );
        })}
      </AnimatePresence>
    </ul>
  );
};

export default AnimatedList;

More like this

Spinner

shadcn/ui·Feedback & loaders

Accordion

SmoothUI·Data display

Marking Menu

Kokonut UI·Overlays

Input

shadcn/ui·Inputs & forms

Dot Pattern

Magic UI·Backgrounds

Scroll Index

Kokonut UI·Text effects

Skeleton

shadcn/ui·Feedback & loaders

Ai Prompt Input

SmoothUI·Inputs & forms

Input

HextaUI·Inputs & forms

Alert

shadcn/ui·Feedback & loaders

Bubble Menu

React Bits·BackgroundsMIT+

Animated List

Magic UI·Data display

Alert

SmoothUI·Feedback & loaders

Ai Message

SmoothUI·Backgrounds

Ai Reasoning

SmoothUI·Media & 3D