{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rolodex",
  "title": "Rolodex",
  "author": "VenusUI",
  "description": "A rotary card file that tumbles through contacts by scroll, drag, keys or letter tabs.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/default/ui/rolodex.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ChevronDown, ChevronUp, Mail, Phone } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface RolodexCard {\n  name: string\n  role?: string\n  phone?: string\n  email?: string\n  note?: string\n}\n\ninterface RolodexProps extends Omit<React.ComponentProps<\"div\">, \"onChange\"> {\n  cards: RolodexCard[]\n  defaultIndex?: number\n  onCardChange?: (card: RolodexCard, index: number) => void\n}\n\nconst AHEAD = 4\nconst BEHIND = 2\nconst DRAG_STEP = 34\nconst mod = (value: number, by: number) => ((value % by) + by) % by\n\n/**\n * A rotary card file. Scroll, drag, press the arrow keys or jump with the\n * letter tabs, and the cards tumble over the drum.\n */\nfunction Rolodex({ cards, defaultIndex = 0, onCardChange, className, ...props }: RolodexProps) {\n  const [position, setPosition] = React.useState(defaultIndex)\n  const drum = React.useRef<HTMLDivElement>(null)\n  const drag = React.useRef<{ y: number; base: number } | null>(null)\n  const count = cards.length\n  const index = mod(position, count)\n  const card = cards[index]\n  const letters = [...new Set(cards.map((item) => item.name[0].toUpperCase()))]\n\n  const stateRef = React.useRef({ count, onCardChange, cards })\n  React.useEffect(() => {\n    stateRef.current = { count, onCardChange, cards }\n  })\n\n  const goTo = React.useCallback((next: number) => {\n    const { count, onCardChange, cards } = stateRef.current\n    setPosition(next)\n    onCardChange?.(cards[mod(next, count)], mod(next, count))\n  }, [])\n\n  const positionRef = React.useRef(position)\n  React.useEffect(() => {\n    positionRef.current = position\n  }, [position])\n\n  React.useEffect(() => {\n    const element = drum.current\n    if (!element) return\n    let pending = 0\n    const onWheel = (event: WheelEvent) => {\n      event.preventDefault()\n      pending += event.deltaY\n      if (Math.abs(pending) < 40) return\n      goTo(positionRef.current + Math.sign(pending))\n      pending = 0\n    }\n    element.addEventListener(\"wheel\", onWheel, { passive: false })\n    return () => element.removeEventListener(\"wheel\", onWheel)\n  }, [goTo])\n\n  return (\n    <div data-slot=\"rolodex\" className={cn(\"flex w-full max-w-md items-center gap-2\", className)} {...props}>\n      <div role=\"group\" aria-label=\"Jump to letter\" className=\"flex max-h-72 shrink-0 flex-col flex-wrap gap-0.5\">\n        {letters.map((letter) => {\n          const active = card.name[0].toUpperCase() === letter\n          return (\n            <button\n              key={letter}\n              type=\"button\"\n              aria-pressed={active}\n              aria-label={`Jump to ${letter}`}\n              onClick={() => {\n                const target = cards.findIndex((item) => item.name[0].toUpperCase() === letter)\n                goTo(position + (mod(target - index + Math.floor(count / 2), count) - Math.floor(count / 2)))\n              }}\n              className={cn(\"grid size-6 place-items-center rounded-[4px] font-mono text-[11px] font-medium outline-none transition-colors focus-visible:ring-3 focus-visible:ring-ring/50\", active ? \"bg-foreground text-background\" : \"text-muted-foreground hover:bg-muted\")}\n            >\n              {letter}\n            </button>\n          )\n        })}\n      </div>\n\n      <div className=\"min-w-0 flex-1\">\n        <div\n          ref={drum}\n          role=\"group\"\n          tabIndex={0}\n          aria-roledescription=\"card file\"\n          aria-label=\"Contacts. Use the up and down arrow keys to turn the cards.\"\n          onKeyDown={(event) => {\n            const step = event.key === \"ArrowDown\" ? 1 : event.key === \"ArrowUp\" ? -1 : 0\n            if (!step) return\n            event.preventDefault()\n            goTo(position + step)\n          }}\n          onPointerDown={(event) => {\n            if ((event.target as HTMLElement).closest(\"a\")) return\n            event.currentTarget.setPointerCapture(event.pointerId)\n            drag.current = { y: event.clientY, base: position }\n          }}\n          onPointerMove={(event) => {\n            if (!drag.current) return\n            const next = drag.current.base + Math.round((drag.current.y - event.clientY) / DRAG_STEP)\n            if (next !== position) goTo(next)\n          }}\n          onPointerUp={() => {\n            drag.current = null\n          }}\n          onPointerCancel={() => {\n            drag.current = null\n          }}\n          className=\"relative h-72 cursor-grab touch-none overflow-hidden rounded-xl bg-muted outline-none select-none active:cursor-grabbing focus-visible:ring-3 focus-visible:ring-ring/50\"\n        >\n          {cards.map((item, i) => {\n            const offset = mod(i - position + Math.floor(count / 2), count) - Math.floor(count / 2)\n            if (offset > AHEAD || offset < -BEHIND) return null\n            const active = offset === 0\n            const fallen = offset < 0\n            return (\n              <article\n                key={`${item.name}-${i}`}\n                aria-hidden={!active}\n                style={{\n                  zIndex: fallen ? 20 : 10 - offset,\n                  opacity: fallen ? 0 : 1 - offset * 0.1,\n                  transform: fallen ? \"perspective(900px) rotateX(-96deg)\" : `perspective(900px) translateY(${-offset * 20}px) scale(${1 - offset * 0.04}) rotateX(${offset * 5}deg)`,\n                }}\n                className={cn(\n                  \"absolute inset-x-5 bottom-9 flex h-40 origin-bottom flex-col rounded-md bg-[#fdfaf1] p-4 text-neutral-800 shadow-[0_-1px_4px_rgb(0_0_0/0.22)] ring-1 ring-black/10 transition-[transform,opacity] duration-300 ease-out motion-reduce:transition-none\",\n                  !active && \"pointer-events-none\"\n                )}\n              >\n                <h3 className=\"truncate border-b border-red-300 pb-1 font-serif text-lg font-semibold\">{item.name}</h3>\n                {item.role ? <p className=\"mt-1 truncate text-xs text-neutral-600\">{item.role}</p> : null}\n                <div className=\"mt-auto space-y-0.5 text-xs\">\n                  {item.phone ? (\n                    <a href={`tel:${item.phone.replace(/[^+\\d]/g, \"\")}`} tabIndex={active ? 0 : -1} className=\"flex items-center gap-1.5 truncate underline-offset-2 hover:underline\">\n                      <Phone aria-hidden=\"true\" className=\"size-3 shrink-0\" />\n                      {item.phone}\n                    </a>\n                  ) : null}\n                  {item.email ? (\n                    <a href={`mailto:${item.email}`} tabIndex={active ? 0 : -1} className=\"flex items-center gap-1.5 truncate underline-offset-2 hover:underline\">\n                      <Mail aria-hidden=\"true\" className=\"size-3 shrink-0\" />\n                      {item.email}\n                    </a>\n                  ) : null}\n                  {item.note ? <p className=\"truncate text-neutral-600 italic\">{item.note}</p> : null}\n                </div>\n              </article>\n            )\n          })}\n          <span aria-hidden=\"true\" className=\"absolute inset-x-2 bottom-7 z-30 h-2 rounded-full bg-linear-to-b from-neutral-300 via-neutral-500 to-neutral-700 shadow-sm\" />\n          <span aria-hidden=\"true\" className=\"absolute bottom-2 left-1/2 z-30 h-5 w-24 -translate-x-1/2 rounded-t-md bg-linear-to-b from-neutral-600 to-neutral-800\" />\n        </div>\n        <div className=\"mt-2 flex items-center justify-between\">\n          <button type=\"button\" aria-label=\"Previous card\" onClick={() => goTo(position - 1)} className=\"grid size-8 place-items-center rounded-md text-muted-foreground outline-none hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50\">\n            <ChevronUp aria-hidden=\"true\" className=\"size-4\" />\n          </button>\n          <p aria-live=\"polite\" className=\"truncate text-xs text-muted-foreground\">\n            {card.name}, {index + 1} of {count}\n          </p>\n          <button type=\"button\" aria-label=\"Next card\" onClick={() => goTo(position + 1)} className=\"grid size-8 place-items-center rounded-md text-muted-foreground outline-none hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50\">\n            <ChevronDown aria-hidden=\"true\" className=\"size-4\" />\n          </button>\n        </div>\n      </div>\n    </div>\n  )\n}\n\nexport { Rolodex }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "interactive",
    "data-display"
  ],
  "type": "registry:ui"
}