Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsMay 26, 2026·2 min de lectura

Swapy — Framework-Agnostic Drag-to-Swap Layout Library

A lightweight JavaScript library that converts any layout into a drag-to-swap interface with just a few lines of code, working with React, Vue, Svelte, or vanilla JS.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Swapy Overview
Comando de instalación directa
npx -y tokrepo@latest install f1d33958-58db-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

Introduction

Swapy is a small JavaScript library that adds drag-to-swap functionality to any HTML layout. Rather than implementing complex drag-and-drop from scratch, Swapy lets you mark slots and items with data attributes and get a working swappable grid or layout in minutes. It works with any framework or no framework at all.

What Swapy Does

  • Converts static layouts into interactive drag-to-swap interfaces
  • Works with any frontend framework: React, Vue, Svelte, or vanilla JS
  • Handles all pointer events, animations, and collision detection internally
  • Provides callbacks for swap events to sync with application state
  • Supports dynamic slot and item addition and removal

Architecture Overview

Swapy identifies slots and items through HTML data attributes, then attaches pointer event listeners to manage the drag interaction. When a user drags an item over another slot, Swapy calculates the swap using bounding-box collision detection and animates the transition with CSS transforms. The library is framework-agnostic because it operates on the DOM directly.

Self-Hosting & Configuration

  • Install via npm, pnpm, or yarn
  • Add data-swapy-slot and data-swapy-item attributes to your HTML
  • Call createSwapy() on the container element
  • Customize animation duration and easing through options
  • Listen for swap events to persist layout changes

Key Features

  • Minimal API: two data attributes and one function call to get started
  • Framework-agnostic — works with React, Vue, Svelte, and plain HTML
  • Smooth CSS-based swap animations with configurable easing
  • Lightweight with no dependencies
  • Supports both grid and freeform layouts

Comparison with Similar Tools

  • dnd-kit — React-specific; Swapy works with any framework
  • SortableJS — reordering lists; Swapy focuses on slot-based swapping
  • react-beautiful-dnd — React only and archived; Swapy is active and universal
  • Framer Motion layout — animation library; Swapy is purpose-built for swap interactions

FAQ

Q: Does it work with React? A: Yes, Swapy works with React, Vue, Svelte, Angular, and vanilla JavaScript.

Q: Can I persist the layout after swaps? A: Yes, the onSwap callback provides the current layout data which you can save to localStorage or a database.

Q: Does it support touch devices? A: Yes, Swapy handles both mouse and touch pointer events natively.

Q: How large is the bundle? A: Swapy is lightweight with no external dependencies, keeping the bundle small.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados