fma-ds

Sortable

A reorderable list, row or grid (layout: vertical, horizontal, grid).

Data displayoriginalMITChangelogRegistry JSON

Overview

Give it the items as value (or defaultValue) with onChange, and one SortableItem per item whose id matches getKey(item) (defaults to item.id) — as static children or a render function.

  • Pointer: items drag from anywhere; a line marks the drop position.
  • `SortableItemHandle`: required on every item — the visible grip and its keyboard / screen-reader drag button. Enter starts, arrows pick the drop position, Enter drops; arrows reach it in a vertical list, Tab in a row or grid.
  • `isDisabled`: pins an item in place.
  • `selectionMode`: lets several selected items move together.
  • `renderDragPreview`: replaces the browser's drag snapshot.
  • Events: onChange also gets the moved keys and the drop target; onDragStart/onDragEnd follow react-aria.

Installation

  1. 1

    Register the @fma-ds namespace in components.json (once)

    components.json
    {  "registries": {    "@fma-ds": "https://ds.fmartinsandre.dev.br/r/{name}.json"  }}
  2. 2

    Add the item

    pnpm dlx shadcn@latest add @fma-ds/sortable

    Files land in components/fma-ds/sortable.tsx; npm and registry dependencies are installed along with them.

Dependencies

npm
cn@^0.5.0lucide-react@^1.61.0react-aria-components@^1.22.1
Registry
None