Installs: 0
Used in: 1 repos
Updated: 2d ago
$
npx ai-builder add skill retex73/dnd-patternsInstalls to .claude/skills/dnd-patterns/
# DND Patterns Skill
## Purpose
Drag and drop implementation using DND Kit for reordering tune versions.
## Basic Setup
```javascript
import { DndContext, closestCenter } from '@dnd-kit/core';
import { SortableContext, verticalListSortingStrategy, useSortable } from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
function SortableItem({ id, children }) {
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id });
const style = {
transform: CSS.Transform.toString(transform),
transition
};
return (
<div ref={setNodeRef} style={style} {...attributes} {...listeners}>
{children}
</div>
);
}
function SortableList({ items, onReorder }) {
const handleDragEnd = (event) => {
const { active, over } = event;
if (active.id !== over.id) {
const oldIndex = items.findIndex(i => i.id === active.id);
const newIndex = items.findIndex(i => i.id === over.id);
onReorder(oldIndex, newIndex);
}
};
return (
<DndContext collisionDetection={closestCenter} onDragEnd={handleDragEnd}>
<SortableContext items={items} strategy={verticalListSortingStrategy}>
{items.map(item => (
<SortableItem key={item.id} id={item.id}>
{item.content}
</SortableItem>
))}
</SortableContext>
</DndContext>
);
}
```
## Best Practices
✅ Use unique IDs for items
✅ Provide visual feedback during drag
✅ Persist reordering to database
❌ Don't forget collision detection
❌ Don't mutate state directly
Quick Install
$
npx ai-builder add skill retex73/dnd-patternsDetails
- Type
- skill
- Author
- retex73
- Slug
- retex73/dnd-patterns
- Created
- 6d ago