A lightweight and customizable drag-and-drop component built with React, TypeScript, and @hello-pangea/dnd. This component provides a smooth and intuitive drag-and-drop experience with a modern design.
You can view a live demo of the React DnD Component here.
- Smooth drag-and-drop functionality
- TypeScript support
- Customizable styling with Tailwind CSS
- Responsive design
- Modern and clean UI
- Reusable components
- Built with performance in mind
- React 18.3
- TypeScript
- Tailwind CSS
- @hello-pangea/dnd (Drag and Drop)
- Vite
- Lucide React (Icons)
- Clone the repository:
git clone https://github.com/HoshangDEV/react-dnd-component.git
cd react-dnd-component- Install dependencies:
npm install- Start the development server:
npm run devimport { DndContainer, DndItem, DndRoot, DragHandle } from "./components/dnd";
function App() {
const [items, setItems] = useState([
{ title: "Item 1", description: "Description 1" },
{ title: "Item 2", description: "Description 2" },
]);
const handleDragEnd = (result) => {
// Handle drag end logic
};
return (
<DndRoot onDragEnd={handleDragEnd}>
<DndContainer id="list">
{items.map((item, index) => (
<DndItem key={index} id={String(index)} index={index}>
{(dragHandleProps) => (
// Your item content
)}
</DndItem>
))}
</DndContainer>
</DndRoot>
);
}The component uses Tailwind CSS for styling and can be easily customized by:
- Modifying the Tailwind configuration in
tailwind.config.js - Using the
classNameprop on any component - Using the utility classes provided by Tailwind CSS
The main wrapper component that provides the drag-and-drop context.
A droppable container that holds draggable items.
A draggable item component that can be reordered within its container.
A customizable handle component for dragging items.
npm run dev- Start development servernpm run build- Build for productionnpm run lint- Run ESLintnpm run preview- Preview production build
MIT License - feel free to use this component in your projects!
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
If you find this project helpful, please give it a ⭐️ on GitHub!
For production applications, you can enable type-aware lint rules:
export default tseslint.config({
languageOptions: {
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})For React-specific linting, install and configure eslint-plugin-react:
// eslint.config.js
import react from 'eslint-plugin-react'
export default tseslint.config({
settings: { react: { version: '18.3' } },
plugins: {
react,
},
rules: {
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})