{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "list-reorder",
  "title": "List reorder",
  "description": "Drag-to-reorder list with a grip handle, a lifted shadow on the dragged row, neighbours that spring into place, and Alt+Arrow keyboard moves announced to screen readers.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/lists/list-reorder.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Reorder, useDragControls, useReducedMotion } from \"motion/react\"\nimport { GripVertical } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { GooduiTokens, spring } from \"@/lib/goodui-motion\"\n\nexport type ListReorderRenderState = { index: number; dragging: boolean }\n\nexport type ListReorderLabels = {\n  handle: (label: string, position: number, count: number) => string\n  moved: (label: string, position: number, count: number) => string\n  dropped: (label: string, position: number, count: number) => string\n}\nconst DEFAULT_LABELS: ListReorderLabels = {\n  handle: (label, position, count) => `Reorder ${label}, position ${position} of ${count}. Use the arrow keys to move.`,\n  moved: (label, position, count) => `${label} moved to position ${position} of ${count}.`,\n  dropped: (label, position, count) => `${label} dropped at position ${position} of ${count}.`,\n}\n\nexport type ListReorderProps<T> = Omit<React.ComponentProps<\"div\">, \"children\" | \"onChange\"> & {\n  /** Items in their current order (controlled). */\n  items: T[]\n  /** Called with the whole list in its new order after a drag step or keyboard move; store it back into `items`. */\n  onReorder: (items: T[]) => void\n  /** Stable unique key of an item. Also the default for `getLabel`. */\n  getKey: (item: T) => string\n  /** Plain-text name of an item, used for the handle label and screen reader announcements. */\n  getLabel?: (item: T) => string\n  /** Content of a row. `state.index` is the current position, `state.dragging` is true while that row is held. */\n  renderItem: (item: T, state: ListReorderRenderState) => React.ReactNode\n  /** Where the grip sits. \"none\" makes the whole row draggable. */\n  handle?: \"start\" | \"end\" | \"none\"\n  /** Accessible name of the list. */\n  label?: string\n  /** Classes added to every row (<li>). */\n  itemClassName?: string\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<ListReorderLabels>\n}\n\ntype ItemProps<T> = {\n  item: T\n  index: number\n  label: string\n  handleLabel: string\n  handle: \"start\" | \"end\" | \"none\"\n  reduce: boolean\n  className?: string\n  onMove: (from: number, delta: number) => void\n  onDropped: (label: string, index: number) => void\n  renderItem: ListReorderProps<T>[\"renderItem\"]\n}\n\nfunction ReorderRow<T>({ item, index, label, handleLabel, handle, reduce, className, onMove, onDropped, renderItem }: ItemProps<T>) {\n  const controls = useDragControls()\n  const [dragging, setDragging] = React.useState(false)\n  const hintId = React.useId()\n  const rowFocusable = handle === \"none\"\n\n  const move = (e: React.KeyboardEvent, requireAlt: boolean) => {\n    if (e.key !== \"ArrowUp\" && e.key !== \"ArrowDown\") return\n    // With handle=\"none\" the row itself is the keyboard handle: plain arrows move it while the row has focus.\n    const onRow = rowFocusable && e.target === e.currentTarget\n    if (requireAlt && !e.altKey && !onRow) return\n    e.preventDefault()\n    e.stopPropagation()\n    onMove(index, e.key === \"ArrowUp\" ? -1 : 1)\n  }\n\n  const grip = (\n    <button\n      type=\"button\"\n      aria-label={handleLabel}\n      onPointerDown={(e) => {\n        e.preventDefault()\n        controls.start(e)\n      }}\n      onKeyDown={(e) => move(e, false)}\n      className={cn(\n        \"pc-press flex size-8 shrink-0 cursor-grab touch-none items-center justify-center rounded-md text-muted-foreground transition-colors outline-none hover:bg-muted hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50 active:cursor-grabbing\",\n        dragging && \"cursor-grabbing bg-muted text-foreground\",\n      )}\n    >\n      <GripVertical className=\"size-4\" />\n    </button>\n  )\n\n  return (\n    <Reorder.Item\n      as=\"li\"\n      value={item}\n      dragListener={handle === \"none\"}\n      dragControls={controls}\n      onDragStart={() => setDragging(true)}\n      onDragEnd={() => {\n        setDragging(false)\n        onDropped(label, index)\n      }}\n      onKeyDown={(e) => move(e, true)}\n      tabIndex={rowFocusable ? 0 : undefined}\n      aria-describedby={rowFocusable ? hintId : undefined}\n      whileDrag={reduce ? undefined : { scale: 1.025 }}\n      transition={reduce ? { duration: 0 } : spring.snap}\n      data-dragging={dragging || undefined}\n      className={cn(\n        \"relative flex items-center gap-2 rounded-xl border bg-card px-2 py-2 text-card-foreground shadow-xs transition-[box-shadow,border-color] duration-200 select-none\",\n        \"data-dragging:border-primary/40 data-dragging:shadow-[var(--pc-e3)] data-dragging:shadow-black/10 dark:data-dragging:shadow-black/40\",\n        handle === \"none\" && \"cursor-grab touch-none px-3 outline-none focus-visible:ring-3 focus-visible:ring-ring/50 active:cursor-grabbing\",\n        className,\n      )}\n    >\n      {handle === \"start\" && grip}\n      <div className=\"min-w-0 flex-1\">{renderItem(item, { index, dragging })}</div>\n      {handle === \"end\" && grip}\n      {rowFocusable && (\n        <span id={hintId} className=\"sr-only\">\n          {handleLabel}\n        </span>\n      )}\n    </Reorder.Item>\n  )\n}\n\n/**\n * Drag-to-reorder list with a grip handle, a lifted row while dragging and Alt+Arrow keyboard moves.\n * With handle=\"none\" each row is focusable and moves with the arrow keys (Alt+Arrow from inside the row).\n */\nexport function ListReorder<T>({\n  items,\n  onReorder,\n  getKey,\n  getLabel = getKey,\n  renderItem,\n  handle = \"start\",\n  label = \"Reorderable list\",\n  itemClassName,\n  labels,\n  className,\n  ...props\n}: ListReorderProps<T>) {\n  const l = useLabels(\"list-reorder\", DEFAULT_LABELS, labels)\n  const reduce = useReducedMotion() ?? false\n  const [announcement, setAnnouncement] = React.useState(\"\")\n\n  const onMove = (from: number, delta: number) => {\n    const to = from + delta\n    if (to < 0 || to >= items.length) return\n    const next = [...items]\n    const moved = next.splice(from, 1)[0]!\n    next.splice(to, 0, moved)\n    onReorder(next)\n    setAnnouncement(l.moved(getLabel(moved), to + 1, items.length))\n  }\n\n  return (\n    <div className={cn(\"w-full\", className)} {...props}>\n      <GooduiTokens />\n      <Reorder.Group as=\"ul\" axis=\"y\" values={items} onReorder={onReorder} aria-label={label} className=\"flex flex-col gap-2\">\n        {items.map((item, index) => (\n          <ReorderRow\n            key={getKey(item)}\n            item={item}\n            index={index}\n            label={getLabel(item)}\n            handleLabel={l.handle(getLabel(item), index + 1, items.length)}\n            handle={handle}\n            reduce={reduce}\n            className={itemClassName}\n            onMove={onMove}\n            onDropped={(name, i) => setAnnouncement(l.dropped(name, i + 1, items.length))}\n            renderItem={renderItem}\n          />\n        ))}\n      </Reorder.Group>\n      <p aria-live=\"assertive\" className=\"sr-only\">\n        {announcement}\n      </p>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/list-reorder.tsx"
    }
  ],
  "categories": [
    "components",
    "lists"
  ],
  "type": "registry:component"
}