{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "animated-list",
  "type": "registry:component",
  "title": "Animated List",
  "description": "Keyboard-friendly list with a staggered entrance, a sliding highlight and scroll fades.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "list",
    "menu",
    "keyboard",
    "select",
    "stagger"
  ],
  "docs": "https://hyperblur.dev/effects/animated-list",
  "files": [
    {
      "path": "registry/hyperblur/animated-list.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/animated-list.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface AnimatedListProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\" | \"onSelect\"> {\n  items: React.ReactNode[];\n  onSelect?: (index: number) => void;\n  initialSelected?: number;\n  showGradients?: boolean;\n  maxHeight?: number;\n}\n\nconst css = `\n@property --hb-al-t { syntax: \"<length>\"; inherits: false; initial-value: 0px; }\n@property --hb-al-b { syntax: \"<length>\"; inherits: false; initial-value: 0px; }\n.hb-al { position: relative; width: 100%; color: #f2f2f5; }\n.hb-al-scroll {\n  --hb-al-t: 0px;\n  --hb-al-b: 0px;\n  max-height: var(--hb-al-max);\n  overflow-y: auto;\n  overscroll-behavior: contain;\n  scrollbar-width: none;\n}\n.hb-al-scroll::-webkit-scrollbar { display: none; }\n.hb-al-scroll[data-gradients=\"true\"] {\n  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 var(--hb-al-t), #000 calc(100% - var(--hb-al-b)), transparent 100%);\n  mask-image: linear-gradient(to bottom, transparent 0, #000 var(--hb-al-t), #000 calc(100% - var(--hb-al-b)), transparent 100%);\n  transition: --hb-al-t .25s ease, --hb-al-b .25s ease;\n}\n.hb-al-scroll[data-top=\"true\"] { --hb-al-t: 28px; }\n.hb-al-scroll[data-bottom=\"true\"] { --hb-al-b: 28px; }\n.hb-al-track {\n  position: relative;\n  display: flex;\n  flex-direction: column;\n  gap: 4px;\n  padding: 4px;\n  outline: none;\n  border-radius: 14px;\n}\n.hb-al-track:focus-visible { box-shadow: 0 0 0 1px rgba(47, 123, 255, .6); }\n.hb-al-hl {\n  position: absolute;\n  top: 0;\n  left: 4px;\n  right: 4px;\n  height: 0;\n  border-radius: 10px;\n  background: rgba(255, 255, 255, .09);\n  opacity: 0;\n  pointer-events: none;\n  transition: transform .28s cubic-bezier(.22, .8, .24, 1), height .28s cubic-bezier(.22, .8, .24, 1), opacity .2s ease;\n}\n.hb-al-item {\n  position: relative;\n  z-index: 1;\n  padding: 10px 14px;\n  border-radius: 10px;\n  font-size: 14px;\n  line-height: 1.4;\n  color: rgba(255, 255, 255, .68);\n  cursor: pointer;\n  user-select: none;\n  transition: color .2s ease;\n  animation: hb-al-in .5s cubic-bezier(.22, .8, .24, 1) both;\n  animation-delay: var(--hb-al-d);\n}\n.hb-al-item[data-active=\"true\"] { color: #fff; }\n.hb-al-item::before {\n  content: \"\";\n  position: absolute;\n  left: 0;\n  top: 22%;\n  bottom: 22%;\n  width: 3px;\n  border-radius: 3px;\n  background: #2f7bff;\n  opacity: 0;\n  transform: scaleY(.4);\n  transition: opacity .2s ease, transform .2s ease;\n}\n.hb-al-item[data-selected=\"true\"]::before { opacity: 1; transform: scaleY(1); }\n@keyframes hb-al-in {\n  from { opacity: 0; transform: translate3d(-14px, 8px, 0); }\n  to { opacity: 1; transform: translate3d(0, 0, 0); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-al-item { animation: none; transition: none; }\n  .hb-al-item::before { transition: none; }\n  .hb-al-hl { transition: none; }\n  .hb-al-scroll[data-gradients=\"true\"] { transition: none; }\n}\n`;\n\nconst FADE = 28;\n\nexport function AnimatedList({\n  items,\n  onSelect,\n  initialSelected = -1,\n  showGradients = true,\n  maxHeight = 320,\n  className = \"\",\n  style,\n  onKeyDown,\n  ...rest\n}: AnimatedListProps) {\n  const uid = React.useId();\n  const scrollRef = React.useRef<HTMLDivElement>(null);\n  const trackRef = React.useRef<HTMLDivElement>(null);\n  const hlRef = React.useRef<HTMLDivElement>(null);\n  const placed = React.useRef(false);\n  const [selected, setSelected] = React.useState(initialSelected);\n  const [hovered, setHovered] = React.useState(-1);\n  const [fade, setFade] = React.useState({ top: false, bottom: false });\n\n  const total = items.length;\n  const sel = selected >= 0 && selected < total ? selected : -1;\n  const hov = hovered >= 0 && hovered < total ? hovered : -1;\n  const active = hov >= 0 ? hov : sel;\n\n  const updateFade = React.useCallback(() => {\n    const el = scrollRef.current;\n    if (!el) return;\n    const top = el.scrollTop > 1;\n    const bottom = el.scrollTop + el.clientHeight < el.scrollHeight - 1;\n    setFade((prev) => (prev.top === top && prev.bottom === bottom ? prev : { top, bottom }));\n  }, []);\n\n  const place = React.useCallback(() => {\n    const hl = hlRef.current;\n    const track = trackRef.current;\n    if (!hl || !track) return;\n    const target = active >= 0 ? track.querySelector<HTMLElement>(`[data-idx=\"${active}\"]`) : null;\n    if (!target) {\n      hl.style.opacity = \"0\";\n      return;\n    }\n    const first = !placed.current;\n    if (first) hl.style.transition = \"none\";\n    hl.style.height = `${target.offsetHeight}px`;\n    hl.style.transform = `translate3d(0, ${target.offsetTop}px, 0)`;\n    hl.style.opacity = \"1\";\n    if (first) {\n      void hl.offsetHeight;\n      hl.style.transition = \"\";\n      placed.current = true;\n    }\n  }, [active]);\n\n  React.useEffect(() => {\n    place();\n  }, [place, total]);\n\n  React.useEffect(() => {\n    const track = trackRef.current;\n    const scroller = scrollRef.current;\n    if (!track || !scroller || typeof ResizeObserver === \"undefined\") return;\n    const ro = new ResizeObserver(() => {\n      place();\n      updateFade();\n    });\n    ro.observe(track);\n    ro.observe(scroller);\n    return () => ro.disconnect();\n  }, [place, updateFade]);\n\n  function reveal(index: number) {\n    const scroller = scrollRef.current;\n    const target = trackRef.current?.querySelector<HTMLElement>(`[data-idx=\"${index}\"]`);\n    if (!scroller || !target) return;\n    const pad = showGradients ? FADE : 0;\n    const top = target.offsetTop - pad;\n    const bottom = target.offsetTop + target.offsetHeight + pad;\n    if (top < scroller.scrollTop) scroller.scrollTop = Math.max(0, top);\n    else if (bottom > scroller.scrollTop + scroller.clientHeight) {\n      scroller.scrollTop = bottom - scroller.clientHeight;\n    }\n  }\n\n  function choose(index: number) {\n    setSelected(index);\n    onSelect?.(index);\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    onKeyDown?.(e);\n    if (e.defaultPrevented || total === 0) return;\n    let next = active;\n    if (e.key === \"ArrowDown\") next = active < 0 ? 0 : Math.min(total - 1, active + 1);\n    else if (e.key === \"ArrowUp\") next = active < 0 ? total - 1 : Math.max(0, active - 1);\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = total - 1;\n    else if (e.key === \"Enter\") {\n      if (sel >= 0) {\n        e.preventDefault();\n        onSelect?.(sel);\n      }\n      return;\n    } else return;\n    e.preventDefault();\n    setHovered(-1);\n    setSelected(next);\n    reveal(next);\n  }\n\n  const vars = {\n    \"--hb-al-max\": `${Math.max(0, maxHeight)}px`,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <div className={`hb-al ${className}`} style={vars} {...rest}>\n      <style href=\"hb-animated-list\" precedence=\"default\">{css}</style>\n      <div\n        ref={scrollRef}\n        className=\"hb-al-scroll\"\n        data-gradients={showGradients}\n        data-top={fade.top}\n        data-bottom={fade.bottom}\n        onScroll={updateFade}\n      >\n        <div\n          ref={trackRef}\n          className=\"hb-al-track\"\n          role=\"listbox\"\n          tabIndex={0}\n          aria-activedescendant={active >= 0 ? `${uid}-${active}` : undefined}\n          onKeyDown={handleKeyDown}\n          onPointerLeave={() => setHovered(-1)}\n        >\n          <div ref={hlRef} className=\"hb-al-hl\" aria-hidden=\"true\" />\n          {items.map((item, i) => (\n            <div\n              key={i}\n              id={`${uid}-${i}`}\n              role=\"option\"\n              aria-selected={sel === i}\n              data-idx={i}\n              data-active={active === i}\n              data-selected={sel === i}\n              className=\"hb-al-item\"\n              style={{ \"--hb-al-d\": `${Math.min(i, 12) * 0.05}s` } as React.CSSProperties}\n              onPointerMove={() => {\n                if (hovered !== i) setHovered(i);\n              }}\n              onClick={() => choose(i)}\n            >\n              {item}\n            </div>\n          ))}\n        </div>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}