NewPlatano

Drag and Drop Tutorial | Beautiful DnD

Beto, June 28, 2024 · 3,911 views

Learn how to create a task manager app with drag and drop functionality using React, Next.js, and TypeScript. It follows a real design system and uses best practices to build a pixel-perfect, responsive UI. The app includes features like creating tasks, dragging tasks between columns, and keyboard shortcuts.

You'll learn how to integrate the Atlassian drag-and-drop library, use the shadcn UI component library with Tailwind CSS for styling, and structure your app for scalability. This lesson is ideal if you want to build a modern React app with a solid design system and smooth drag-and-drop interactions.

What's inside

  • Introduction to the task manager app design and demo
  • Using the Atlassian drag-and-drop library for smooth interactions
  • Why Next.js is recommended for scalable React apps
  • Using shadcn UI and Tailwind CSS for fast, consistent styling
  • Handling missing mobile designs with common sense and fallback layouts
  • Creating the Next.js project and managing Node.js versions
  • Exploring the Figma design and enabling developer mode for pixel-perfect UI
  • Features of the task manager: shortcuts, task creation, drag and drop, and dropdown actions

Introduction to the task manager app design and demo

I start by showing the task manager app designed by a friend who is both a designer and frontend developer. The app has a clean UI with columns representing task statuses and supports drag-and-drop to move tasks between columns. You can create new tasks using a plus button or keyboard shortcuts like Command+K.

The demo highlights smooth drag-and-drop, responsive layout, and dropdown menus for task actions like delete and update. The goal is to build the app as close as possible to the provided Figma design, but you are encouraged to customize colors, sizes, and border radii if you want.

Using the Atlassian drag-and-drop library for smooth interactions

For drag-and-drop, I use the popular Atlassian library, which is maintained by a major software company and trusted by nearly 100,000 developers. This library provides a robust and smooth drag-and-drop experience out of the box.

I emphasize choosing high-quality, maintained libraries to save development time and ensure reliability. This library handles the complexities of drag-and-drop so you can focus on building features.

Next.js is chosen as the framework because it simplifies scaling the app later. If you need to add authentication, database integration, or server-side rendering, Next.js provides built-in support.

I recommend Next.js over plain React projects for real-world apps that may grow in complexity. It also briefly mentions Next.js advantages like routing and API routes that help with backend integration.

Using shadcn UI and Tailwind CSS for fast, consistent styling

The UI components come from the shadcn UI library, which uses Tailwind CSS by default. This lets you build beautiful, consistent components quickly without creating everything from scratch.

Tailwind CSS is used for styling and allows easy customization. I show how using a component library speeds up development while maintaining pixel-perfect design fidelity.

Handling missing mobile designs with common sense and fallback layouts

The Figma design does not include mobile views, which is a common scenario for frontend developers. I advises using common sense to adapt layouts for smaller screens.

For example, if the desktop design has three columns, the mobile version can show just one column stacked vertically. You can also ask the design team for missing states or create your own based on best practices.

Creating the Next.js project and managing Node.js versions

Before coding, I walk through creating a new Next.js project using the official website. It stresses the importance of having Node.js version 18 or later.

It also shows how to use a Node version manager (NVM) to switch between Node versions easily. This setup ensures compatibility and smooth development.

Exploring the Figma design and enabling developer mode for pixel-perfect UI

I open the Figma design and encourages exploring all pages and components. It shows how to enable developer mode in Figma to inspect exact pixel measurements for padding, margin, and layout.

This helps build a pixel-perfect UI that matches the design exactly. I references a previous lesson on using Figma developer mode for detailed design specs.

Features of the task manager: shortcuts, task creation, drag and drop, and dropdown actions

The app supports keyboard shortcuts like Command+K to open a command palette for quick task creation. Tasks can be added with titles, descriptions, and priority settings.

Drag-and-drop lets you move tasks between columns smoothly. Each task card has a dropdown menu with options to delete, update, or mark as favorite. I focus on implementing delete but suggests adding other actions as improvements.

Resources

Premium resourcePro Membership

Let's connect!

Had a win? Get featured on Code with Beto.Share your story