{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sortable-list",
  "title": "Sortable List",
  "description": "A list people can put in their own order: drag a row by its handle and the others slide out of the way, or use the keyboard (Space to lift, arrows to move, Space to drop, Escape to undo), with live position numbers and optional remove buttons.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/sortable-list/sortable-list.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, Reorder, useDragControls, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface SortableItem {\n  id: string;\n  title: string;\n  /** Muted text on the right, e.g. a time or a count. */\n  meta?: string;\n}\n\nexport interface SortableListProps {\n  items?: SortableItem[];\n  /** Controlled order. */\n  value?: SortableItem[];\n  onValueChange?: (items: SortableItem[]) => void;\n  /** Show 1, 2, 3 ... in front of each row (they update as rows move). */\n  showNumbers?: boolean;\n  /** A remove button on each row. */\n  removable?: boolean;\n  label?: string;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.5)\", faint: \"rgba(245,244,241,0.28)\", row: \"#131313\", rowLift: \"#1B1B1B\", border: \"rgba(255,255,255,0.09)\", borderLift: \"rgba(255,255,255,0.24)\", focus: \"rgba(245,244,241,0.85)\", shadow: \"0 18px 40px rgba(0,0,0,0.55)\", hover: \"rgba(255,255,255,0.07)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.5)\", faint: \"rgba(10,10,10,0.28)\", row: \"#FFFFFF\", rowLift: \"#FFFFFF\", border: \"rgba(10,10,10,0.1)\", borderLift: \"rgba(10,10,10,0.26)\", focus: \"rgba(10,10,10,0.85)\", shadow: \"0 18px 40px rgba(10,10,10,0.16)\", hover: \"rgba(10,10,10,0.05)\" },\n};\n\nconst DEFAULT_ITEMS: SortableItem[] = [\n  { id: \"intro\", title: \"Welcome and intros\", meta: \"5 min\" },\n  { id: \"metrics\", title: \"Last week's numbers\", meta: \"10 min\" },\n  { id: \"launch\", title: \"Launch checklist\", meta: \"15 min\" },\n  { id: \"hiring\", title: \"Hiring update\", meta: \"5 min\" },\n  { id: \"qa\", title: \"Open questions\", meta: \"10 min\" },\n];\n\nfunction Row({ item, index, count, p, reduce, showNumbers, removable, grabbed, helpId, onKey, onRemove }: {\n  item: SortableItem;\n  index: number;\n  count: number;\n  p: (typeof PALETTES)[\"dark\"];\n  reduce: boolean;\n  showNumbers: boolean;\n  removable: boolean;\n  grabbed: boolean;\n  helpId: string;\n  onKey: (e: React.KeyboardEvent) => void;\n  onRemove: () => void;\n}) {\n  const controls = useDragControls();\n  const [dragging, setDragging] = React.useState(false);\n  const lifted = dragging || grabbed;\n  return (\n    <Reorder.Item\n      value={item}\n      dragListener={false}\n      dragControls={controls}\n      onDragStart={() => setDragging(true)}\n      onDragEnd={() => setDragging(false)}\n      initial={{ opacity: 0, height: 0 }}\n      animate={{ opacity: 1, height: \"auto\", scale: lifted && !reduce ? 1.02 : 1 }}\n      exit={{ opacity: 0, height: 0, transition: { duration: reduce ? 0 : 0.2 } }}\n      transition={{ type: \"spring\", stiffness: 500, damping: 38 }}\n      data-handle={item.id}\n      className=\"relative list-none\"\n      style={{ zIndex: lifted ? 2 : 1 }}\n    >\n      <div\n        className=\"flex items-center\"\n        style={{ gap: 10, padding: \"0 8px 0 4px\", height: 52, marginBottom: 6, borderRadius: 14, background: lifted ? p.rowLift : p.row, border: `1px solid ${lifted ? p.borderLift : p.border}`, boxShadow: lifted ? p.shadow : \"none\", transition: \"background 0.15s ease, border-color 0.15s ease, box-shadow 0.2s ease\" }}\n      >\n        <button\n          type=\"button\"\n          aria-label={`Reorder ${item.title}, position ${index + 1} of ${count}`}\n          aria-pressed={grabbed}\n          aria-describedby={helpId}\n          onPointerDown={(e) => {\n            e.preventDefault();\n            controls.start(e);\n          }}\n          onKeyDown={onKey}\n          className=\"flex shrink-0 cursor-grab touch-none items-center justify-center rounded-lg border-none bg-transparent outline-none focus-visible:ring-2 active:cursor-grabbing\"\n          style={{ width: 32, height: 40, color: lifted ? p.text : p.faint, [\"--tw-ring-color\" as string]: p.focus }}\n        >\n          <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" aria-hidden=\"true\" fill=\"currentColor\">\n            {[6, 12, 18].map((y) => [9, 15].map((x) => <circle key={`${x}-${y}`} cx={x} cy={y} r=\"1.7\" />))}\n          </svg>\n        </button>\n        {showNumbers && (\n          <span className=\"w-5 shrink-0 text-[13px] font-semibold tabular-nums\" style={{ color: p.muted }}>\n            <AnimatePresence mode=\"popLayout\" initial={false}>\n              <motion.span key={index} className=\"inline-block\" initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: -6 }} transition={{ duration: reduce ? 0 : 0.16 }}>\n                {index + 1}\n              </motion.span>\n            </AnimatePresence>\n          </span>\n        )}\n        <span className=\"min-w-0 flex-1 truncate text-[14.5px] font-medium select-none\" style={{ color: p.text }}>\n          {item.title}\n        </span>\n        {item.meta && (\n          <span className=\"shrink-0 text-[12.5px] tabular-nums select-none\" style={{ color: p.muted }}>\n            {item.meta}\n          </span>\n        )}\n        {removable && (\n          <button\n            type=\"button\"\n            aria-label={`Remove ${item.title}`}\n            onClick={onRemove}\n            className=\"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border-none bg-transparent outline-none focus-visible:ring-2\"\n            style={{ width: 30, height: 30, color: p.faint, [\"--tw-ring-color\" as string]: p.focus }}\n            onMouseEnter={(e) => {\n              e.currentTarget.style.background = p.hover;\n              e.currentTarget.style.color = p.text;\n            }}\n            onMouseLeave={(e) => {\n              e.currentTarget.style.background = \"transparent\";\n              e.currentTarget.style.color = p.faint;\n            }}\n          >\n            <svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n              <path d=\"m6.5 6.5 11 11M17.5 6.5l-11 11\" />\n            </svg>\n          </button>\n        )}\n      </div>\n    </Reorder.Item>\n  );\n}\n\nexport function SortableList({ items = DEFAULT_ITEMS, value, onValueChange, showNumbers = true, removable = false, label = \"Agenda\", theme = \"dark\", className }: SortableListProps) {\n  const p = PALETTES[theme];\n  const reduce = Boolean(useReducedMotion());\n  const [internal, setInternal] = React.useState(items);\n  const list = value ?? internal;\n  const [grabbedId, setGrabbedId] = React.useState<string | null>(null);\n  const [announce, setAnnounce] = React.useState(\"\");\n  const before = React.useRef<SortableItem[] | null>(null);\n  const rootRef = React.useRef<HTMLUListElement>(null);\n  const helpId = `${React.useId()}-help`;\n\n  const commit = (next: SortableItem[]) => {\n    if (value === undefined) setInternal(next);\n    onValueChange?.(next);\n  };\n\n  const refocus = (id: string) => requestAnimationFrame(() => rootRef.current?.querySelector<HTMLButtonElement>(`[data-handle=\"${id}\"] button`)?.focus());\n\n  const toggleGrab = (item: SortableItem, index: number) => {\n    if (grabbedId === item.id) {\n      setGrabbedId(null);\n      before.current = null;\n      setAnnounce(`${item.title} dropped at position ${index + 1} of ${list.length}.`);\n    } else {\n      setGrabbedId(item.id);\n      before.current = list;\n      setAnnounce(`${item.title} lifted. Use the up and down arrows to move it, Space to drop, Escape to cancel.`);\n    }\n  };\n\n  const onKey = (item: SortableItem, index: number) => (e: React.KeyboardEvent) => {\n    if (e.key === \" \" || e.key === \"Enter\") {\n      e.preventDefault();\n      toggleGrab(item, index);\n    } else if (grabbedId === item.id && (e.key === \"ArrowUp\" || e.key === \"ArrowDown\")) {\n      e.preventDefault();\n      const to = index + (e.key === \"ArrowUp\" ? -1 : 1);\n      if (to < 0 || to >= list.length) return;\n      const next = [...list];\n      next.splice(index, 1);\n      next.splice(to, 0, item);\n      commit(next);\n      setAnnounce(`${item.title}, position ${to + 1} of ${list.length}.`);\n      refocus(item.id);\n    } else if (grabbedId === item.id && e.key === \"Escape\") {\n      e.preventDefault();\n      if (before.current) commit(before.current);\n      setGrabbedId(null);\n      setAnnounce(`Move cancelled. ${item.title} is back where it was.`);\n      refocus(item.id);\n    }\n  };\n\n  return (\n    <div className={cn(\"flex w-full flex-col\", className)} style={{ fontFamily: \"Inter, sans-serif\" }}>\n      <span id={helpId} className=\"sr-only\">\n        Press Space to lift a row, arrow keys to move it, Space again to drop it.\n      </span>\n      <span className=\"sr-only\" aria-live=\"assertive\">\n        {announce}\n      </span>\n      <Reorder.Group ref={rootRef} axis=\"y\" values={list} onReorder={commit} aria-label={label} className=\"m-0 flex flex-col p-0\">\n        <AnimatePresence initial={false}>\n          {list.map((item, i) => (\n            <Row\n              key={item.id}\n              item={item}\n              index={i}\n              count={list.length}\n              p={p}\n              reduce={reduce}\n              showNumbers={showNumbers}\n              removable={removable}\n              grabbed={grabbedId === item.id}\n              helpId={helpId}\n              onKey={onKey(item, i)}\n              onRemove={() => commit(list.filter((x) => x.id !== item.id))}\n            />\n          ))}\n        </AnimatePresence>\n      </Reorder.Group>\n    </div>\n  );\n}\n\nexport default SortableList;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}