Communitygithub.com

YepAPI/skills

可排序列表、看板、文件拖放区域,支持触摸和无障碍访问。

skills 是什么?

该技能提供了一套完整的拖放交互解决方案,基于 `@dnd-kit/core` 和 `@dnd-kit/sortable` 库构建。它支持可排序列表、看板以及文件拖放区域,并默认包含了触摸支持和键盘无障碍访问功能。技能通过 `SortableContext` 和 `useSortable` Hook 实现列表排序,通过多个 `SortableContext` 容器实现看板列的拖拽,并推荐使用 `react-dropzone` 或原生拖放 API 处理文件上传。它还强调了乐观更新模式(先更新 UI 再后台持久化)以及使用 `DragOverlay` 提供拖拽时的视觉反馈。整体上,它适用于需要现代化、高性能拖放交互的桌面和移动端应用,例如任务管理、文件管理或任何需要重新排序的场景。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/drag-and-drop

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

拖放

规则

  • 使用 @dnd-kit/core + @dnd-kit/sortable — 现代化、可无障碍访问、支持触摸的拖放库
  • 可排序列表:包裹在 <SortableContext> 中,每个项目使用 useSortable() 钩子
  • 看板:使用 <DndContext> 和多个 <SortableContext> 容器 — 每列一个容器
  • 文件拖放区域:使用 react-dropzone 或原生 onDragOver/onDrop 配合 e.dataTransfer.files
  • 触摸支持:dnd-kit 原生处理触摸 — 使用 TouchSensor 和 PointerSensor 并设置激活约束
  • 无障碍访问:dnd-kit 提供开箱即用的键盘拖放 — 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.

相关技能