Please use Desktop to view and interact with components
Components300msspring
Draggable List
Reorderable list with drag and drop spring physics
listdragreordersortable
Useto navigate between components
Preview
- First item
- Second item
- Third item
- Fourth item
Code
TypeScript + React
'use client'
import { useState } from 'react'
import { Reorder } from 'framer-motion'
import { GripVertical } from 'lucide-react'
const initialItems = [
{ id: 1, text: 'First item' },
{ id: 2, text: 'Second item' },
{ id: 3, text: 'Third item' },
{ id: 4, text: 'Fourth item' },
]
export function DraggableList() {
const [items, setItems] = useState(initialItems)
return (
<Reorder.Group
axis="y"
values={items}
onReorder={setItems}
className="w-full max-w-md space-y-2"
>
{items.map((item) => (
<Reorder.Item
key={item.id}
value={item}
className="flex cursor-grab items-center gap-3 rounded-lg border bg-[var(--card-bg)] p-4 active:cursor-grabbing"
whileDrag={{ scale: 1.05, boxShadow: '0 10px 30px rgba(0,0,0,0.2)' }}
>
<GripVertical className="h-5 w-5 text-[var(--foreground)]/40" />
<span className="text-sm">{item.text}</span>
</Reorder.Item>
))}
</Reorder.Group>
)
}
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