Animated List
magicui/animated-listFreeComponent
A list that animates each item in sequence with a delay. Used to showcase notifications or events on your landing page.
Live preview
live · rendered by the registry
Rendered by magicui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://magicui.design/r/animated-list.jsonSource
1"use client"23import React, {4 useEffect,5 useMemo,6 useState,7 type ComponentPropsWithoutRef,8} from "react"9import { AnimatePresence, motion, type MotionProps } from "motion/react"1011import { cn } from "@/lib/utils"1213export function AnimatedListItem({ children }: { children: React.ReactNode }) {14 const animations: MotionProps = {15 initial: { scale: 0, opacity: 0 },16 animate: { scale: 1, opacity: 1, originY: 0 },17 exit: { scale: 0, opacity: 0 },18 transition: { type: "spring", stiffness: 350, damping: 40 },19 }2021 return (22 <motion.div {...animations} layout className="mx-auto w-full">23 {children}24 </motion.div>25 )26}2728export interface AnimatedListProps extends ComponentPropsWithoutRef<"div"> {29 children: React.ReactNode30 delay?: number31}3233export const AnimatedList = React.memo(34 ({ children, className, delay = 1000, ...props }: AnimatedListProps) => {35 const [index, setIndex] = useState(0)36 const childrenArray = useMemo(37 () => React.Children.toArray(children),38 [children]39 )4041 useEffect(() => {42 let timeout: ReturnType<typeof setTimeout> | null = null4344 if (index < childrenArray.length - 1) {45 timeout = setTimeout(() => {46 setIndex((prevIndex) => (prevIndex + 1) % childrenArray.length)47 }, delay)48 }4950 return () => {51 if (timeout !== null) {52 clearTimeout(timeout)53 }54 }55 }, [index, delay, childrenArray.length])5657 const itemsToShow = useMemo(() => {58 const result = childrenArray.slice(0, index + 1).reverse()59 return result60 }, [index, childrenArray])6162 return (63 <div64 className={cn(`flex flex-col items-center gap-4`, className)}65 {...props}66 >67 <AnimatePresence>68 {itemsToShow.map((item) => (69 <AnimatedListItem key={(item as React.ReactElement).key}>70 {item}71 </AnimatedListItem>72 ))}73 </AnimatePresence>74 </div>75 )76 }77)7879AnimatedList.displayName = "AnimatedList"
What it pulls in
npm packages
Files it writes
More from magicui
All 247 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Androidandroid | magicui | Components | Free | no deps | |
| Animated Beamanimated-beam | magicui | Components | Free | 1 dep | |
| Animated Circular Progress Baranimated-circular-progress-bar | magicui | Components | Free | no deps | |
| Animated Gradient Textanimated-gradient-text | magicui | Components | Free | no deps | |
| Animated Grid Patternanimated-grid-pattern | magicui | Components | Free | 1 dep | |
| Animated Shiny Textanimated-shiny-text | magicui | Components | Free | no deps | |
| Theme Toggleranimated-theme-toggler | magicui | Components | Free | 1 dep | |
| Aurora Textaurora-text | magicui | Components | Free | no deps |
