Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

✨ feat: add animated list component

Dillion Verma36f77ebed2d7
diff --git a/content/components/animated-list.mdx b/content/components/animated-list.mdx
new file mode 100644
index 00000000..4894360c
--- /dev/null
+++ b/content/components/animated-list.mdx
@@ -0,0 +1,56 @@
+---
+title: Animated List
+date: 2023-12-12
+summary: An animated scrolling list effect
+author: dillionverma
+published: true
+video: https://cdn.magicui.design/animated-list.mp4
+---
+
+<ComponentPreview name="animated-list-demo" />
+
+<Steps>
+
+<Step>
+
+## Prerequisites
+
+```bash
+npm install -D tailwindcss clsx tailwind-merge framer-motion
+```
+
+Copy and paste the following code into your project.
+
+```typescript
+// lib/utils.ts
+import clsx, { ClassValue } from "clsx";
+import { twMerge } from "tailwind-merge";
+
+export function cn(...inputs: ClassValue[]) {
+ return twMerge(clsx(inputs));
+}
+```
+
+</Step>
+
+<Step>
+
+## Installation
+
+Copy and paste the following code into your project.
+
+```text
+components/magicui/animated-list.tsx
+```
+
+<ComponentSource name="animated-list" />
+
+</Step>
+
+</Steps>
+
+## Props
+
+| Prop | Type | Description | Default |
+| --------- | ------ | -------------------------------- | ------- |
+| className | string | The class name for the component | "" |
diff --git a/registry/components/example/animated-list-demo.tsx b/registry/components/example/animated-list-demo.tsx
new file mode 100644
index 00000000..7ac73c3e
--- /dev/null
+++ b/registry/components/example/animated-list-demo.tsx
@@ -0,0 +1,113 @@
+"use client";
+
+import { cn } from "@/lib/utils";
+import { AnimatedList } from "@/registry/components/magicui/animated-list";
+
+interface Item {
+ name: string;
+ description: string;
+ icon: string;
+ color: string;
+}
+
+const notifications = [
+ {
+ name: "New task added",
+ description: "Magic UI · 15m ago",
+ icon: "📝",
+ color: "#1E86FF",
+ },
+ {
+ name: "New message",
+ description: "Magic UI · 10m ago",
+ icon: "💬",
+ color: "#FF3D71",
+ },
+ {
+ name: "User signed up",
+ description: "Magic UI · 5m ago",
+ icon: "👤",
+ color: "#FFB800",
+ },
+ {
+ name: "Payment received",
+ description: "Magic UI · 2m ago",
+ icon: "💸",
+ color: "#00C9A7",
+ },
+ {
+ name: "New task added",
+ description: "Magic UI · 15m ago",
+ icon: "📝",
+ color: "#1E86FF",
+ },
+ {
+ name: "New message",
+ description: "Magic UI · 10m ago",
+ icon: "💬",
+ color: "#FF3D71",
+ },
+ {
+ name: "User signed up",
+ description: "Magic UI · 5m ago",
+ icon: "👤",
+ color: "#FFB800",
+ },
+ {
+ name: "Payment received",
+ description: "Magic UI · 2m ago",
+ icon: "💸",
+ color: "#00C9A7",
+ },
+];
+
+const AnimatedListItem = ({ name, description, icon, color }: Item) => {
+ return (
+ <figure
+ className={cn(
+ "relative mx-auto w-full max-w-[400px] transform cursor-pointer overflow-hidden rounded-2xl p-4",
+ // animation styles
+ "transition-all duration-200 ease-in-out hover:scale-[103%]",
+ // light styles
+ "bg-white [box-shadow:0_0_0_1px_rgba(0,0,0,.03),0_2px_4px_rgba(0,0,0,.05),0_12px_24px_rgba(0,0,0,.05)]",
+ // dark styles
+ "transform-gpu dark:bg-transparent dark:backdrop-blur-md dark:[border:1px_solid_rgba(255,255,255,.1)] dark:[box-shadow:0_-20px_80px_-20px_#ffffff1f_inset]",
+ )}
+ >
+ <div className="flex flex-row items-center gap-4">
+ <div
+ className="font-lg flex min-h-[3rem] min-w-[3rem] items-center justify-center rounded-2xl"
+ style={{
+ backgroundColor: color,
+ }}
+ >
+ {icon}
+ </div>
+ <div className="flex flex-col gap-1">
+ <figcaption className="text-lg font-medium dark:text-white">
+ {name}
+ </figcaption>
+ <p className="text-sm font-normal dark:text-white/60">
+ {description}
+ </p>
+ </div>
+ </div>
+ </figure>
+ );
+};
+
+export default function AnimatedListDemo() {
+ return (
+ <div className="relative flex max-h-[500px] min-h-[500px] w-full flex-col overflow-hidden rounded-lg border bg-background p-6 shadow-lg">
+ {/* <span className="pointer-events-none hidden whitespace-pre-wrap bg-gradient-to-b from-black to-gray-300/80 bg-clip-text text-center font-semibold leading-none text-transparent dark:from-white dark:to-slate-900/10 sm:block sm:text-7xl">
+ Animated List
+ </span> */}
+
+ <AnimatedList>
+ {notifications.map((item, idx) => (
+ <AnimatedListItem {...item} key={idx}></AnimatedListItem>
+ ))}
+ </AnimatedList>
+ </div>
+ );
+}
diff --git a/registry/components/magicui/animated-list.tsx b/registry/components/magicui/animated-list.tsx
new file mode 100644
index 00000000..2bcae50d
--- /dev/null
+++ b/registry/components/magicui/animated-list.tsx
@@ -0,0 +1,83 @@
+"use client";
+
+import { cn } from "@/lib/utils";
+import {
+ AnimatePresence,
+ MotionProps,
+ motion,
+ useIsPresent,
+} from "framer-motion";
+import React, { useEffect, useRef, useState } from "react";
+
+export function AnimatedList({
+ className,
+ children,
+}: {
+ className?: string;
+ children: React.ReactNode;
+}) {
+ const [items, setItems] = useState<React.ReactNode[]>([]);
+ const childQueue = useRef(React.Children.toArray(children));
+ const intervalRef = useRef<NodeJS.Timeout | null>(null);
+
+ useEffect(() => {
+ // Update the queue when the children prop changes
+ childQueue.current = React.Children.toArray(children);
+
+ // Start or restart the interval to add children every 1 second
+ clearInterval(intervalRef.current!); // Clear any existing interval
+ intervalRef.current = setInterval(() => {
+ setItems((prevItems) => {
+ if (childQueue.current.length > 0) {
+ // Dequeue the next child and add it to the list of items
+ const nextChild = childQueue.current.shift();
+ return [nextChild, ...prevItems];
+ } else {
+ // When no children are left in the queue, clear the interval
+ clearInterval(intervalRef.current!);
+ }
+ return prevItems;
+ });
+ }, 1300);
+
+ // Cleanup the interval on component unmount
+ return () => {
+ if (intervalRef.current) {
+ clearInterval(intervalRef.current);
+ }
+ };
+ }, [children]); // Depend on children, so it restarts when children change
+
+ return (
+ <div className={cn("flex flex-col items-center gap-4", className)}>
+ <AnimatePresence>
+ {items.map((item, index) => (
+ <AnimatedListItem key={item.key || index}>{item}</AnimatedListItem>
+ ))}
+ </AnimatePresence>
+ </div>
+ );
+}
+
+AnimatedList.displayName = "AnimatedList";
+
+export function AnimatedListItem({ children }: { children: React.ReactNode }) {
+ const isPresent = useIsPresent();
+ const animations: MotionProps = {
+ style: {
+ position: isPresent ? "static" : "absolute",
+ width: "100%",
+ margin: "0 auto",
+ },
+ 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>
+ {children}
+ </motion.div>
+ );
+}
diff --git a/registry/index.tsx b/registry/index.tsx
index 03630bfc..0f8cb17a 100644
--- a/registry/index.tsx
+++ b/registry/index.tsx
@@ -87,6 +87,11 @@ const ui: Registry = {
type: "components:ui",
files: ["registry/components/magicui/retro-grid.tsx"],
},
+ "animated-list": {
+ name: "animated-list",
+ type: "components:ui",
+ files: ["registry/components/magicui/animated-list.tsx"],
+ },
};
const example: Registry = {
@@ -299,6 +304,14 @@ const example: Registry = {
() => import("@/registry/components/example/retro-grid-demo"),
),
},
+ "animated-list-demo": {
+ name: "animated-list-demo",
+ type: "components:example",
+ files: ["registry/components/example/animated-list-demo.tsx"],
+ component: React.lazy(
+ () => import("@/registry/components/example/animated-list-demo"),
+ ),
+ },
};
export const registry: Registry = {