$npx -y skills add ancoleman/ai-design-components --skill implementing-drag-dropImplements drag-and-drop and sortable interfaces with React/TypeScript including kanban boards, sortable lists, file uploads, and reorderable grids. Use when building interactive UIs requiring direct manipulation, spatial organization, or touch-friendly reordering.
| 1 | # Drag-and-Drop & Sortable Interfaces |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | This skill helps implement drag-and-drop interactions and sortable interfaces using modern React/TypeScript libraries. It covers accessibility-first approaches, touch support, and performance optimization for creating intuitive direct manipulation UIs. |
| 6 | |
| 7 | ## When to Use |
| 8 | |
| 9 | Invoke this skill when: |
| 10 | - Building Trello-style kanban boards with draggable cards between columns |
| 11 | - Creating sortable lists with drag handles for priority ordering |
| 12 | - Implementing file upload zones with visual drag-and-drop feedback |
| 13 | - Building reorderable grids for dashboard widgets or galleries |
| 14 | - Creating visual builders with node-based interfaces |
| 15 | - Implementing any UI requiring spatial reorganization through direct manipulation |
| 16 | |
| 17 | ## Core Patterns |
| 18 | |
| 19 | ### Sortable Lists |
| 20 | Reference `references/dnd-patterns.md` for: |
| 21 | - Vertical lists with drag handles |
| 22 | - Horizontal lists for tab/carousel reordering |
| 23 | - Grid layouts with 2D dragging |
| 24 | - Auto-scrolling near edges |
| 25 | |
| 26 | ### Kanban Boards |
| 27 | Reference `references/kanban-implementation.md` for: |
| 28 | - Multi-column boards with cards |
| 29 | - WIP limits and swimlanes |
| 30 | - Card preview on hover |
| 31 | - Column management (add/remove/collapse) |
| 32 | |
| 33 | ### File Upload Zones |
| 34 | Reference `references/file-dropzone.md` for: |
| 35 | - Visual feedback states |
| 36 | - File type validation |
| 37 | - Multi-file handling |
| 38 | - Progress indicators |
| 39 | |
| 40 | ### Accessibility |
| 41 | Reference `references/accessibility-dnd.md` for: |
| 42 | - Keyboard navigation patterns |
| 43 | - Screen reader announcements |
| 44 | - Alternative UI approaches |
| 45 | - ARIA attributes |
| 46 | |
| 47 | ## Library Selection |
| 48 | |
| 49 | ### Primary: dnd-kit |
| 50 | Modern, accessible, and performant drag-and-drop for React. |
| 51 | |
| 52 | Reference `references/library-guide.md` for: |
| 53 | - Library comparison (dnd-kit vs alternatives) |
| 54 | - Installation and setup |
| 55 | - Core concepts and API |
| 56 | - Migration from react-beautiful-dnd |
| 57 | |
| 58 | ### Key Features |
| 59 | - Built-in accessibility support |
| 60 | - Touch, mouse, and keyboard input |
| 61 | - Zero dependencies (~10KB core) |
| 62 | - Highly customizable |
| 63 | - TypeScript native |
| 64 | |
| 65 | ## Implementation Workflow |
| 66 | |
| 67 | ### Step 1: Analyze Requirements |
| 68 | Determine the drag-and-drop pattern needed: |
| 69 | - Simple list reordering → Sortable list pattern |
| 70 | - Multi-container movement → Kanban pattern |
| 71 | - File handling → Dropzone pattern |
| 72 | - Complex interactions → Visual builder pattern |
| 73 | |
| 74 | ### Step 2: Set Up Library |
| 75 | Install required packages: |
| 76 | ```bash |
| 77 | npm install @dnd-kit/core @dnd-kit/sortable @dnd-kit/utilities |
| 78 | ``` |
| 79 | |
| 80 | ### Step 3: Implement Core Functionality |
| 81 | Use examples as starting points: |
| 82 | - `examples/sortable-list.tsx` for basic lists |
| 83 | - `examples/kanban-board.tsx` for multi-column boards |
| 84 | - `examples/file-dropzone.tsx` for file uploads |
| 85 | - `examples/grid-reorder.tsx` for grid layouts |
| 86 | |
| 87 | ### Step 4: Add Accessibility |
| 88 | Reference `references/accessibility-dnd.md` to: |
| 89 | - Implement keyboard navigation |
| 90 | - Add screen reader announcements |
| 91 | - Provide alternative controls |
| 92 | - Test with assistive technologies |
| 93 | |
| 94 | Run `scripts/validate_accessibility.js` to check implementation. |
| 95 | |
| 96 | ### Step 5: Optimize Performance |
| 97 | For lists with >100 items: |
| 98 | - Reference `references/performance-optimization.md` |
| 99 | - Implement virtual scrolling |
| 100 | - Use `scripts/calculate_drop_position.js` for efficient calculations |
| 101 | |
| 102 | ### Step 6: Style with Design Tokens |
| 103 | Apply theming using the design-tokens skill: |
| 104 | - Reference design token variables |
| 105 | - Implement drag states (hovering, dragging, dropping) |
| 106 | - Add visual feedback and animations |
| 107 | |
| 108 | ## Mobile & Touch Support |
| 109 | |
| 110 | Reference `references/touch-support.md` for: |
| 111 | - Long press to initiate drag |
| 112 | - Preventing scroll during drag |
| 113 | - Touch-friendly hit areas (44px minimum) |
| 114 | - Gesture conflict resolution |
| 115 | |
| 116 | ## State Management |
| 117 | |
| 118 | Reference `references/state-management.md` for: |
| 119 | - Managing drag state in React |
| 120 | - Optimistic updates |
| 121 | - Undo/redo functionality |
| 122 | - Persisting order changes |
| 123 | |
| 124 | ## Scripts |
| 125 | |
| 126 | ### Calculate Drop Position |
| 127 | Run `scripts/calculate_drop_position.js` to: |
| 128 | - Determine valid drop zones |
| 129 | - Calculate insertion indices |
| 130 | - Handle edge cases |
| 131 | |
| 132 | ### Generate Configuration |
| 133 | Run `scripts/generate_dnd_config.js` to: |
| 134 | - Create dnd-kit configuration |
| 135 | - Set up sensors and modifiers |
| 136 | - Configure animations |
| 137 | |
| 138 | ### Validate Accessibility |
| 139 | Run `scripts/validate_accessibility.js` to: |
| 140 | - Check keyboard navigation |
| 141 | - Verify ARIA attributes |
| 142 | - Test screen reader compatibility |
| 143 | |
| 144 | ## Examples |
| 145 | |
| 146 | Each example includes complete TypeScript code with accessibility: |
| 147 | |
| 148 | ### Sortable List |
| 149 | `examples/sortable-list.tsx` |
| 150 | - Vertical list with drag handles |
| 151 | - Keyboard navigation (Space/Enter to grab, arrows to move) |
| 152 | - Screen reader announcements |
| 153 | |
| 154 | ### Kanban Board |
| 155 | `examples/kanban-board.tsx` |
| 156 | - Multiple columns with draggable cards |
| 157 | - Card movement between columns |
| 158 | - Column management features |
| 159 | - WIP limits |
| 160 | |
| 161 | ### File Dropzone |
| 162 | `examples/file-dropzone.tsx` |
| 163 | - Drag files to uploa |