Skip to content

A flexible, lightweight React drag-and-drop kit for building sortable lists, grids, and boards with ease.

License

Notifications You must be signed in to change notification settings

Yourstruggle11/react-dragdrop-kit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

react-dragdrop-kit

A flexible and lightweight drag-and-drop toolkit for React. Build sortable lists, grids, and Kanban boards with a simple, fully-controlled API and customizable previews. Powered by Atlassian's pragmatic drag-and-drop under the hood.

npm downloads license


โœจ Features

Drag & Drop Lists

  • ๐Ÿ” Sortable lists (vertical / horizontal)
  • ๐ŸŽฏ Controlled: you own the array, update on onReorder
  • ๐Ÿงฉ Custom render per item (cards, compact, detailedโ€ฆ anything)
  • ๐Ÿงฒ Drop indicator + optional custom drag preview

๐Ÿ†• Kanban Boards (v1.2.0+)

  • ๐Ÿ“‹ Full-featured Kanban board with column and card management
  • ๐Ÿ”„ Cross-column dragging - Move cards between columns seamlessly
  • ๐ŸŽจ Headless architecture - Complete styling control
  • โ™ฟ Accessible - Screen reader announcements and keyboard support
  • ๐Ÿ“ฑ Touch-friendly - Works on mobile devices
  • ๐ŸŽฏ TypeScript-first - Full type safety

General

  • ๐Ÿงช TypeScript types included
  • โšก Tiny bundles (~5KB main, ~9KB Kanban)
  • ๐ŸŽจ Framework agnostic styling - Works with Tailwind, MUI, Chakra, etc.
  • ๐Ÿ“š Comprehensive documentation

๐Ÿ“ฆ Install

npm i react-dragdrop-kit
# or
yarn add react-dragdrop-kit
# or
pnpm add react-dragdrop-kit

๐Ÿš€ Quick Start

Sortable List

import { useState } from "react";
import { DragDropList } from "react-dragdrop-kit";

function App() {
  const [items, setItems] = useState([
    { id: "1", position: 0, title: "Learn React" },
    { id: "2", position: 1, title: "Build awesome app" },
    { id: "3", position: 2, title: "Deploy to production" },
  ]);

  return (
    <DragDropList
      items={items}
      onReorder={(next) => setItems(next.map((it, i) => ({ ...it, position: i })))}
      renderItem={(item) => (
        <div style={{ padding: 12, border: "1px solid #e5e7eb", borderRadius: 8 }}>
          {item.title}
        </div>
      )}
      showDropIndicator
      gap={8}
    />
  );
}

Kanban Board

import { useState } from 'react';
import {
  KanbanBoard,
  applyDragResult,
  AnnouncerProvider,
} from 'react-dragdrop-kit/kanban';

function App() {
  const [state, setState] = useState({
    columns: [
      { id: 'todo', title: 'To Do', cardIds: ['task-1', 'task-2'] },
      { id: 'done', title: 'Done', cardIds: [] },
    ],
    cards: {
      'task-1': { id: 'task-1', title: 'Design landing page' },
      'task-2': { id: 'task-2', title: 'Implement auth' },
    },
  });

  const handleDragEnd = (result) => {
    if (!result.destination) return;
    setState(applyDragResult(state, result));
  };

  return (
    <AnnouncerProvider>
      <KanbanBoard
        state={state}
        onDragEnd={handleDragEnd}
        renderColumn={(col) => <div style={{ padding: 16 }}>{col.title}</div>}
        renderCard={(card) => (
          <div style={{ padding: 12, background: '#fff', borderRadius: 8 }}>
            {card.title}
          </div>
        )}
      />
    </AnnouncerProvider>
  );
}

๐ŸŽจ Styled Examples

With Tailwind CSS

import { DragDropList } from "react-dragdrop-kit";

export default function TailwindExample() {
  const [items, setItems] = useState([
    { id: "1", position: 0, name: "Dashboard", icon: "๐Ÿ“Š" },
    { id: "2", position: 1, name: "Projects",  icon: "๐Ÿ“" },
    { id: "3", position: 2, name: "Team",      icon: "๐Ÿ‘ฅ" },
  ]);

  return (
    <DragDropList
      items={items}
      onReorder={(next) => setItems(next.map((it, i) => ({ ...it, position: i })))}
      containerClassName="bg-gray-50 rounded-xl p-6 space-y-2"
      itemClassName="bg-white rounded-lg shadow-sm hover:shadow-lg transition-all duration-200 cursor-move"
      showDropIndicator
      dropIndicatorClassName="bg-blue-500"
      renderItem={(item) => (
        <div className="flex items-center p-4 space-x-3">
          <span className="text-2xl">{item.icon}</span>
          <span className="font-medium text-gray-700">{item.name}</span>
        </div>
      )}
    />
  );
}

๐Ÿ“š API Reference

DragDropList Component

Prop Type Default Description
items Array<DraggableItem & T> โ€” Items to render. Must include { id: string; position: number }.
onReorder (next: T[], updates: OrderUpdate[]) => void โ€” Called after drop. next is the new array; updates has id + newPosition.
renderItem (item: T) => React.ReactNode โ€” Custom renderer for each item.
direction "vertical" | "horizontal" "vertical" Drag axis + layout.
gap number 0 Gap (px) between items.
disabled boolean false Disable dragging.
showDropIndicator boolean false Show a drop indicator while dragging.
dropIndicatorPosition "top" | "bottom" "bottom" Position of drop indicator relative to target item.
dropIndicatorClassName string โ€” CSS class applied to the drop indicator element.
dragPreviewStyle React.CSSProperties โ€” Inline styles for custom drag preview.
containerClassName string โ€” Class applied to the container.
itemClassName string โ€” Class applied to each item wrapper.

Kanban Components

See the Kanban Documentation for complete API reference, including:

  • KanbanBoard - High-level component
  • KanbanColumnView - Headless column component
  • KanbanCardView - Headless card component
  • AnnouncerProvider - Accessibility provider
  • Helper utilities and types

๐Ÿ—‚๏ธ Kanban Board Features

Core Functionality

  • โœ… Drag cards within and between columns
  • โœ… Reorder columns by dragging headers
  • โœ… Empty column support - Drop into columns with no cards
  • โœ… Cancel drag - Drop outside board to cancel
  • โœ… Normalized state - Efficient data structure

Accessibility (a11y)

  • โ™ฟ Screen reader support with live announcements
  • ๐ŸŽน Keyboard navigation (infrastructure ready)
  • ๐Ÿท๏ธ Proper ARIA attributes
  • ๐Ÿ“ข Context-aware messages

Developer Experience

  • ๐Ÿ“˜ Full TypeScript support
  • ๐ŸŽจ Headless architecture - Style with any framework
  • ๐Ÿ”ง Helper utilities - applyDragResult, reorder functions
  • ๐Ÿ“– Migration guide from react-beautiful-dnd

Customization

The Kanban board is completely headless, giving you full control:

  • Custom card designs
  • Custom column headers
  • Theme support
  • Animation styles
  • Responsive layouts

๐Ÿ“‚ Examples

This repo includes comprehensive examples:

Drag & Drop Lists

Kanban Boards

๐Ÿ‘‰ Explore the examples/ folder for the complete code.

๐ŸŽฎ Live Demo: Check out our interactive demo app with full Kanban showcase!


๐Ÿง  Advanced Usage

TypeScript

import type { DraggableItem, OrderUpdate, KanbanBoardState, DropResult } from 'react-dragdrop-kit';
import type { KanbanCard, KanbanColumn } from 'react-dragdrop-kit/kanban';

// Extend with custom fields
interface TodoItem extends DraggableItem {
  title: string;
  completed: boolean;
}

interface ProjectCard extends KanbanCard {
  priority: 'low' | 'medium' | 'high';
  assignee: string;
  tags: string[];
}

React Strict Mode (React 19)

In dev, React Strict Mode double-mounts to surface side effects. If you see duplicate onReorder calls in development, ensure your event listeners clean up correctly and keep callback identities stable with useCallback. Production builds call once.


๐Ÿ“Š Bundle Size

Module Size (Minified)
react-dragdrop-kit (Main) ~5KB
react-dragdrop-kit/kanban ~9KB

Tree-shakeable exports mean you only pay for what you use!


๐Ÿ”„ Migration Guides

From react-beautiful-dnd

See our comprehensive Kanban migration guide for step-by-step instructions on migrating from react-beautiful-dnd.

Key differences:

  • Normalized state structure
  • No auto-generated IDs
  • Render props instead of children
  • Better TypeScript support

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


๐Ÿ“ License

MIT ยฉ Yourstruggle11


๐Ÿ™ Credits

Built with:


๐Ÿ“– Documentation


๐Ÿ’ฌ Support


Made with โค๏ธ by Yourstruggle11 for the React community

About

A flexible, lightweight React drag-and-drop kit for building sortable lists, grids, and boards with ease.

Resources

License

Stars

Watchers

Forks

Packages

No packages published