Communitygithub.com

드래그 앤 드롭

dnd-kit을 활용한 정렬 가능한 목록, 칸반 보드, 파일 드롭 존으로, 터치 지원과 접근성을 갖춥니다.

드래그 앤 드롭란 무엇인가요?

이 스킬은 최신 dnd-kit 라이브러리를 기반으로 드래그 앤 드롭(DnD) UI를 구현하는 방법을 제공합니다. 정렬 가능한 목록, 칸반 보드, 파일 드롭 존 등 다양한 패턴을 지원하며, 터치 디바이스와 키보드 접근성을 기본적으로 지원합니다. dnd-kit은 SortableContext, useSortable 훅, DndContext, DragOverlay 등을 제공하여 직관적이고 모던한 DnD 경험을 구축할 수 있습니다. 특히 터치 감지(TouchSensor, PointerSensor)와 키보드 감지(KeyboardSensor)를 활성화 조건과 함께 설정할 수 있어, 모바일 및 접근성 요구사항을 충족합니다. 또한 낙관적 업데이트 패턴과 드래그 오버레이를 통해 사용자 경험을 향상시킵니다. 이 스킬은 HTML5 기본 드래그 API를 직접 사용하지 않고, 대신 dnd-kit의 안정적이고 접근성 높은 인터페이스를 활용할 것을 권장합니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/drag-and-drop

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

드래그 앤 드롭은(는) 무엇을 하나요?

규칙

  • @dnd-kit/core + @dnd-kit/sortable 사용 — 최신형, 접근성 좋고 터치 친화적인 DnD 라이브러리
  • 정렬 가능한 목록: <SortableContext>로 감싸고, 각 항목은 useSortable() 훅 사용
  • 칸반 보드: <DndContext> 안에 여러 개의 <SortableContext> 컨테이너 — 각 칸반 열당 하나
  • 파일 드롭 존: react-dropzone 또는 네이티브 onDragOver/onDrop + e.dataTransfer.files
  • 터치 지원: dnd-kit이 기본적으로 터치를 처리 — TouchSensor와 PointerSensor를 활성화 제약 조건과 함께 사용
  • 접근성: dnd-kit이 키보드 DnD를 기본 제공 — KeyboardSensor + sortableKeyboardCoordinates
  • 낙관적 재정렬: 드롭 시 즉시 상태 업데이트, 백그라운드에서 서버에 저장, 오류 시 롤백
  • 드래그 오버레이: <DragOverlay>를 사용하여 드래그 중인 항목의 부동 미리보기 제공 — 시각적 피드백 향상

패턴

import { DndContext, closestCenter, DragOverlay } from "@dnd-kit/core";
import { SortableContext, verticalListSortingStrategy, useSortable } from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities";

function SortableItem({ id, children }: { id: string; children: React.ReactNode }) {
  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 }: { items: Item[] }) {
  const [activeId, setActiveId] = useState<string | null>(null);
  return (
    <DndContext
      collisionDetection={closestCenter}
      onDragStart={({ active }) => setActiveId(active.id)}
      onDragEnd={handleDragEnd}
    >
      <SortableContext items={items.map((i) => i.id)} strategy={verticalListSortingStrategy}>
        {items.map((item) => (
          <SortableItem key={item.id} id={item.id}>{item.name}</SortableItem>
        ))}
      </SortableContext>
      <DragOverlay>{activeId ? <ItemPreview id={activeId} /> : null}</DragOverlay>
    </DndContext>
  );
}

피해야 할 것

  • HTML5 드래그 API 직접 사용 — 터치/모바일/접근성 지원 불량
  • 키보드 접근성 누락 — 항상 KeyboardSensor 포함할 것
  • 드래그 중 상태 변형 — onDragEnd에서만 업데이트할 것
  • DragOverlay 누락 — 드래그 중 원래 항목이 사라져 시각적 피드백이 없음

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

관련 스킬