styleui
componentanimated-listsource: ok · hit
AnimatedList
An animated list component to showcase your content.
npx shadcn add "https://www.styleui.dev/r/animated-list.json"free
No selection tags yet — empty means no evidence, not lack of support.
Files1 · source cached 10/8/2026, 6:47:24 PM
components/animated-list.tsx
"use client";
import React, {
ComponentPropsWithoutRef,
useEffect,
useMemo,
useState,
} from "react";
import { AnimatePresence, motion, MotionProps } from "motion/react";
import { cn } from "@/lib/utils";
function AnimatedListItem({ children }: { children: React.ReactNode }) {
const animations: MotionProps = {
initial: { scale: 0, opacity: 0 },
animate: { scale: 1, opacity: 1, originY: 0 },
exit: { scale: 0, opacity: 0 },
transition: { type: "spring", stiffness: 350, damping: 40 },
};
return (
<motion.div {...animations} layout className="mx-auto w-full">
{children}
</motion.div>
);
}
AnimatedListItem.displayName = "AnimatedListItem";
export { AnimatedListItem };
export interface AnimatedListProps extends ComponentPropsWithoutRef<"div"> {
children: React.ReactNode;
delay?: number;
reverse?: boolean;
loop?: boolean;
}
export const AnimatedList = React.memo(
({
children,
className,
delay = 1000,
reverse = true,
loop = false,
...props
}: AnimatedListProps) => {
const [index, setIndex] = useState(0);
const childrenArray = useMemo(
() => React.Children.toArray(children),
[children]
);
useEffect(() => {
if (index < childrenArray.length - 1) {
const timeout = setTimeout(() => {
setIndex((prevIndex) => prevIndex + 1);
}, delay);
return () => clearTimeout(timeout);
} else if (loop) {
const timeout = setTimeout(() => {
setIndex(0);
}, 1000);
return () => clearTimeout(timeout);
}
}, [index, delay, childrenArray.length, loop]);
const itemsToShow = useMemo(() => {
const result = childrenArray.slice(0, index + 1);
return reverse ? result.reverse() : result;
}, [index, childrenArray, reverse]);
return (
<div
className={cn(`flex flex-col items-center gap-4`, className)}
{...props}
>
<AnimatePresence>
{itemsToShow.map((item) => (
<AnimatedListItem key={(item as React.ReactElement).key}>
{item}
</AnimatedListItem>
))}
</AnimatePresence>
</div>
);
}
);
AnimatedList.displayName = "AnimatedList";