Please use Desktop to view and interact with components
Components300msspring
Animated Pagination
Pagination with smooth page transition indicator
paginationpagesnavigation
Useto navigate between components
Preview
Code
TypeScript + React
'use client'
import { useState } from 'react'
import { motion } from 'framer-motion'
import { ChevronLeft, ChevronRight } from 'lucide-react'
export function AnimatedPagination() {
const [currentPage, setCurrentPage] = useState(1)
const totalPages = 5
return (
<div className="flex items-center gap-2">
<motion.button
onClick={() => setCurrentPage(Math.max(1, currentPage - 1))}
disabled={currentPage === 1}
className="flex h-9 w-9 items-center justify-center rounded-lg border disabled:opacity-50"
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
>
<ChevronLeft className="h-4 w-4" />
</motion.button>
{Array.from({ length: totalPages }, (_, i) => i + 1).map((page) => (
<motion.button
key={page}
onClick={() => setCurrentPage(page)}
className="relative h-9 w-9 rounded-lg text-sm font-medium"
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
style={{
color: currentPage === page ? 'white' : 'var(--foreground)',
}}
>
{currentPage === page && (
<motion.div
layoutId="pagination-indicator"
className="absolute inset-0 rounded-lg bg-accent"
transition={{ type: 'spring', stiffness: 380, damping: 30 }}
/>
)}
<span className="relative z-10">{page}</span>
</motion.button>
))}
<motion.button
onClick={() => setCurrentPage(Math.min(totalPages, currentPage + 1))}
disabled={currentPage === totalPages}
className="flex h-9 w-9 items-center justify-center rounded-lg border disabled:opacity-50"
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
>
<ChevronRight className="h-4 w-4" />
</motion.button>
</div>
)
}
How to Use
- 1Install Framer Motion:
npm install framer-motion - 2Copy the code from above
- 3Paste it into your project and customize as needed
- 4Colors are customizable via Tailwind CSS classes. The default theme uses dark mode colors defined in your globals.css file