{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "micro-swipe-row",
  "type": "registry:component",
  "title": "Swipe Row",
  "description": "A list row that reveals Archive on a swipe right and Delete on a swipe left. It snaps open or closed with momentum, and the arrow keys reveal the same actions.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "list",
    "row",
    "swipe",
    "actions",
    "gesture",
    "mobile"
  ],
  "docs": "https://hyperblur.dev/effects/micro-swipe-row",
  "files": [
    {
      "path": "registry/hyperblur/micro-swipe-row.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/micro-swipe-row.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type MicroSwipeRowReveal = \"none\" | \"archive\" | \"delete\";\n\nexport interface MicroSwipeRowProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\" | \"children\"> {\n  title?: string;\n  subtitle?: string;\n  time?: string;\n  reveal?: MicroSwipeRowReveal;\n  defaultReveal?: MicroSwipeRowReveal;\n  archiveLabel?: string;\n  deleteLabel?: string;\n  accent?: string;\n  danger?: string;\n  idle?: boolean;\n  onRevealChange?: (reveal: MicroSwipeRowReveal) => void;\n  onArchive?: () => void;\n  onDelete?: () => void;\n}\n\nconst ACT = 84;\n\nconst css = `\n.hb-ql4 {\n  display: grid;\n  grid-template-rows: 1fr;\n  width: 100%;\n  box-sizing: border-box;\n  font-family: inherit;\n  transition: grid-template-rows 0.3s cubic-bezier(0.4, 0, 0.2, 1);\n  --hb-ql4-c: #2f7bff;\n  --hb-ql4-r: #ff4d5e;\n}\n.hb-ql4 *, .hb-ql4 *::before, .hb-ql4 *::after { box-sizing: border-box; }\n.hb-ql4[data-gone=\"true\"] { grid-template-rows: 0fr; }\n.hb-ql4-w {\n  position: relative;\n  min-height: 0;\n  overflow: hidden;\n  border: 1px solid #262626;\n  border-radius: 16px;\n  background: #0d0d0d;\n  transition: border-width 0.3s ease, opacity 0.3s ease;\n}\n.hb-ql4[data-gone=\"true\"] .hb-ql4-w { border-width: 0; opacity: 0; }\n.hb-ql4-p {\n  position: absolute;\n  top: 0;\n  bottom: 0;\n  left: 0;\n  right: 0;\n  display: flex;\n  align-items: stretch;\n  opacity: 0;\n}\n.hb-ql4-p[data-side=\"l\"] { background: var(--hb-ql4-c); justify-content: flex-start; }\n.hb-ql4-p[data-side=\"r\"] { background: var(--hb-ql4-r); justify-content: flex-end; }\n.hb-ql4-a {\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  gap: 4px;\n  width: ${ACT}px;\n  margin: 0;\n  padding: 0;\n  font: inherit;\n  font-size: 0.74em;\n  font-weight: 600;\n  color: #fff;\n  background: transparent;\n  border: 0;\n  cursor: pointer;\n}\n.hb-ql4-a svg { width: 20px; height: 20px; }\n.hb-ql4-a:focus-visible { outline: 2px solid #fff; outline-offset: -4px; border-radius: 12px; }\n.hb-ql4-c {\n  position: relative;\n  z-index: 1;\n  display: flex;\n  align-items: center;\n  gap: 12px;\n  padding: 12px 14px;\n  color: #ededed;\n  background: #131313;\n  cursor: grab;\n  touch-action: pan-y;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  will-change: transform;\n}\n.hb-ql4-c:active { cursor: grabbing; }\n.hb-ql4-c:focus-visible { outline: 2px solid var(--hb-ql4-c); outline-offset: -2px; border-radius: 16px; }\n.hb-ql4-v {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 38px;\n  height: 38px;\n  font-size: 0.82em;\n  font-weight: 600;\n  color: #fff;\n  border-radius: 50%;\n}\n.hb-ql4-x { min-width: 0; flex: 1; line-height: 1.3; }\n.hb-ql4-t {\n  margin: 0;\n  overflow: hidden;\n  font-size: 0.92em;\n  font-weight: 600;\n  text-overflow: ellipsis;\n  white-space: nowrap;\n}\n.hb-ql4-s {\n  margin: 2px 0 0;\n  overflow: hidden;\n  font-size: 0.8em;\n  color: #8f8f8f;\n  text-overflow: ellipsis;\n  white-space: nowrap;\n}\n.hb-ql4-m {\n  flex: none;\n  align-self: flex-start;\n  font-size: 0.72em;\n  color: #6f6f6f;\n  font-variant-numeric: tabular-nums;\n}\n.hb-ql4-h {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-ql4, .hb-ql4-w { transition: none; }\n}\n`;\n\nfunction tint(name: string) {\n  let h = 2166136261;\n  for (let i = 0; i < name.length; i++) h = Math.imul(h ^ name.charCodeAt(i), 16777619) >>> 0;\n  return `hsl(${h % 360} 46% 38%)`;\n}\n\nfunction initials(name: string) {\n  return name\n    .split(/\\s+/)\n    .filter(Boolean)\n    .slice(0, 2)\n    .map((w) => w[0]?.toUpperCase() ?? \"\")\n    .join(\"\");\n}\n\nfunction pull(a: number) {\n  return a <= ACT ? a : ACT + 36 * (1 - Math.exp(-(a - ACT) / 36));\n}\n\nexport function MicroSwipeRow({\n  title = \"Maya Okonkwo\",\n  subtitle = \"Re: Lighting specs for the studio build\",\n  time = \"9:41\",\n  reveal,\n  defaultReveal = \"none\",\n  archiveLabel = \"Archive\",\n  deleteLabel = \"Delete\",\n  accent = \"#2f7bff\",\n  danger = \"#ff4d5e\",\n  idle = true,\n  onRevealChange,\n  onArchive,\n  onDelete,\n  className = \"\",\n  style,\n  onPointerEnter,\n  onPointerLeave,\n  ...rest\n}: MicroSwipeRowProps) {\n  const [inner, setInner] = React.useState<MicroSwipeRowReveal>(defaultReveal);\n  const current = reveal ?? inner;\n  const [gone, setGone] = React.useState(false);\n  const [hidden, setHidden] = React.useState(false);\n  const hintId = React.useId();\n  const contentRef = React.useRef<HTMLDivElement>(null);\n  const leftRef = React.useRef<HTMLDivElement>(null);\n  const rightRef = React.useRef<HTMLDivElement>(null);\n  const state = React.useRef({\n    x: 0,\n    v: 0,\n    drag: false,\n    moved: false,\n    startX: 0,\n    baseX: 0,\n    lastX: 0,\n    lastT: 0,\n    vel: 0,\n    hover: false,\n    focus: false,\n    resumeAt: 0,\n    idleStart: -1,\n    cyc: -1,\n    leave: 0,\n    target: 0,\n  });\n  const api = React.useRef({ wake: () => {}, draw: () => {}, reduced: false });\n  const latest = React.useRef({ idle, current, reveal, onRevealChange });\n\n  React.useEffect(() => {\n    latest.current = { idle, current, reveal, onRevealChange };\n    state.current.target = current === \"archive\" ? ACT : current === \"delete\" ? -ACT : 0;\n    api.current.wake();\n  }, [idle, current, reveal, onRevealChange]);\n\n  React.useEffect(() => {\n    const el = contentRef.current;\n    const left = leftRef.current;\n    const right = rightRef.current;\n    if (!el || !left || !right) return;\n    const s = state.current;\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    api.current.reduced = mq.matches;\n    let raf = 0;\n    let last = 0;\n    let visible = true;\n\n    const draw = () => {\n      el.style.transform = `translate3d(${s.x.toFixed(2)}px,0,0)`;\n      left.style.opacity = s.x > 0.5 ? \"1\" : \"0\";\n      right.style.opacity = s.x < -0.5 ? \"1\" : \"0\";\n    };\n\n    const tick = (now: number) => {\n      raf = 0;\n      if (!visible) return;\n      const dt = Math.min(0.05, Math.max(0.001, (now - last) / 1000));\n      last = now;\n      const cfg = latest.current;\n      const w = el.clientWidth || 1;\n      const idleOn =\n        cfg.idle &&\n        !api.current.reduced &&\n        cfg.current === \"none\" &&\n        !s.hover &&\n        !s.focus &&\n        !s.drag &&\n        !s.leave &&\n        now >= s.resumeAt;\n      if (idleOn) {\n        if (s.idleStart < 0) s.idleStart = now;\n        const cyc = Math.floor((now - s.idleStart - 900) / 3600);\n        if (cyc >= 0 && cyc !== s.cyc) {\n          s.cyc = cyc;\n          s.v += cyc % 2 === 0 ? -620 : 620;\n        }\n      } else {\n        s.idleStart = -1;\n        s.cyc = -1;\n      }\n      if (!s.drag) {\n        let rem = dt;\n        while (rem > 0) {\n          const h = Math.min(rem, 1 / 120);\n          if (s.leave) {\n            const t = s.leave * (w + 40);\n            s.v += (150 * (t - s.x) - 24 * s.v) * h;\n          } else {\n            s.v += (300 * (s.target - s.x) - 24 * s.v) * h;\n          }\n          s.x += s.v * h;\n          rem -= h;\n        }\n        if (s.leave && Math.abs(s.x) > w + 4) {\n          draw();\n          setGone(true);\n          return;\n        }\n        if (!s.leave && Math.abs(s.x - s.target) < 0.01 && Math.abs(s.v) < 0.01) {\n          s.x = s.target;\n          s.v = 0;\n        }\n      }\n      draw();\n      raf = requestAnimationFrame(tick);\n    };\n\n    const wake = () => {\n      if (api.current.reduced) {\n        if (!s.drag) s.x = s.leave ? s.leave * (w0() + 40) : s.target;\n        draw();\n        if (s.leave) setGone(true);\n        return;\n      }\n      if (!raf && visible) {\n        last = performance.now();\n        raf = requestAnimationFrame(tick);\n      }\n    };\n\n    const w0 = () => el.clientWidth || 1;\n\n    api.current.wake = wake;\n    api.current.draw = draw;\n    s.x = s.target;\n    draw();\n    wake();\n\n    const io = new IntersectionObserver((entries) => {\n      visible = (entries[entries.length - 1]?.isIntersecting ?? true) || !!s.leave;\n      if (visible) wake();\n      else {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    });\n    io.observe(el.parentElement ?? el);\n    const onMq = () => {\n      api.current.reduced = mq.matches;\n      if (mq.matches) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n      wake();\n    };\n    mq.addEventListener(\"change\", onMq);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      mq.removeEventListener(\"change\", onMq);\n    };\n  }, []);\n\n  React.useEffect(() => {\n    if (!gone) return;\n    const id = window.setTimeout(() => setHidden(true), 340);\n    return () => window.clearTimeout(id);\n  }, [gone]);\n\n  function setReveal(next: MicroSwipeRowReveal) {\n    if (latest.current.reveal === undefined) setInner(next);\n    latest.current.onRevealChange?.(next);\n    const s = state.current;\n    s.target = next === \"archive\" ? ACT : next === \"delete\" ? -ACT : 0;\n    api.current.wake();\n  }\n\n  function act(kind: \"archive\" | \"delete\") {\n    const s = state.current;\n    s.leave = kind === \"archive\" ? 1 : -1;\n    s.drag = false;\n    if (kind === \"archive\") onArchive?.();\n    else onDelete?.();\n    api.current.wake();\n  }\n\n  if (hidden) return <style href=\"hb-micro-swipe-row\" precedence=\"default\">{css}</style>;\n\n  const vars = { \"--hb-ql4-c\": accent, \"--hb-ql4-r\": danger, ...style } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-micro-swipe-row\" precedence=\"default\">{css}</style>\n      <div\n        {...rest}\n        className={`hb-ql4 ${className}`}\n        style={vars}\n        data-gone={gone}\n        onPointerEnter={(e) => {\n          onPointerEnter?.(e);\n          state.current.hover = true;\n        }}\n        onPointerLeave={(e) => {\n          onPointerLeave?.(e);\n          state.current.hover = false;\n          state.current.resumeAt = performance.now() + 1500;\n        }}\n      >\n        <div className=\"hb-ql4-w\">\n          <div ref={leftRef} className=\"hb-ql4-p\" data-side=\"l\" inert={current !== \"archive\"}>\n            <button type=\"button\" className=\"hb-ql4-a\" onClick={() => act(\"archive\")}>\n              <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <rect x=\"3\" y=\"4\" width=\"18\" height=\"5\" rx=\"1.5\" />\n                <path d=\"M5 9v9a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V9\" />\n                <path d=\"M10 13h4\" />\n              </svg>\n              {archiveLabel}\n            </button>\n          </div>\n          <div ref={rightRef} className=\"hb-ql4-p\" data-side=\"r\" inert={current !== \"delete\"}>\n            <button type=\"button\" className=\"hb-ql4-a\" onClick={() => act(\"delete\")}>\n              <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"M4 7h16\" />\n                <path d=\"M9 7V4.5h6V7\" />\n                <path d=\"M6 7l1 12.5a1.5 1.5 0 0 0 1.5 1.5h7a1.5 1.5 0 0 0 1.5-1.5L18 7\" />\n                <path d=\"M10 11v6M14 11v6\" />\n              </svg>\n              {deleteLabel}\n            </button>\n          </div>\n          <div\n            ref={contentRef}\n            className=\"hb-ql4-c\"\n            role=\"group\"\n            tabIndex={0}\n            aria-label={title}\n            aria-describedby={hintId}\n            onFocus={() => {\n              state.current.focus = true;\n            }}\n            onBlur={() => {\n              state.current.focus = false;\n              state.current.resumeAt = performance.now() + 1500;\n            }}\n            onKeyDown={(e) => {\n              if (e.key === \"ArrowRight\") {\n                e.preventDefault();\n                setReveal(current === \"delete\" ? \"none\" : \"archive\");\n              } else if (e.key === \"ArrowLeft\") {\n                e.preventDefault();\n                setReveal(current === \"archive\" ? \"none\" : \"delete\");\n              } else if (e.key === \"Escape\" && current !== \"none\") {\n                e.preventDefault();\n                setReveal(\"none\");\n              }\n            }}\n            onPointerDown={(e) => {\n              if (e.button !== 0 || state.current.leave) return;\n              const s = state.current;\n              e.currentTarget.setPointerCapture(e.pointerId);\n              s.drag = true;\n              s.moved = false;\n              s.startX = e.clientX;\n              s.baseX = s.x;\n              s.lastX = e.clientX;\n              s.lastT = e.timeStamp;\n              s.vel = 0;\n              s.v = 0;\n              api.current.wake();\n            }}\n            onPointerMove={(e) => {\n              const s = state.current;\n              if (!s.drag) return;\n              const dx = e.clientX - s.startX;\n              if (Math.abs(dx) > 4) s.moved = true;\n              const raw = s.baseX + dx;\n              s.x = Math.sign(raw) * pull(Math.abs(raw));\n              const dt = Math.max(1, e.timeStamp - s.lastT);\n              s.vel = Math.max(-3, Math.min(3, s.vel * 0.6 + ((e.clientX - s.lastX) / dt) * 0.4));\n              s.lastX = e.clientX;\n              s.lastT = e.timeStamp;\n              api.current.draw();\n            }}\n            onPointerUp={(e) => {\n              const s = state.current;\n              if (!s.drag) return;\n              if (e.currentTarget.hasPointerCapture(e.pointerId)) e.currentTarget.releasePointerCapture(e.pointerId);\n              s.drag = false;\n              s.resumeAt = performance.now() + 2200;\n              if (!s.moved) {\n                if (current !== \"none\") setReveal(\"none\");\n                return;\n              }\n              s.v = s.vel * 1000;\n              const projected = s.x + s.vel * 180;\n              const next: MicroSwipeRowReveal =\n                projected > ACT * 0.5 ? \"archive\" : projected < -ACT * 0.5 ? \"delete\" : \"none\";\n              setReveal(next);\n            }}\n            onPointerCancel={() => {\n              const s = state.current;\n              s.drag = false;\n              api.current.wake();\n            }}\n          >\n            <span className=\"hb-ql4-v\" style={{ background: tint(title) }} aria-hidden=\"true\">\n              {initials(title)}\n            </span>\n            <div className=\"hb-ql4-x\">\n              <p className=\"hb-ql4-t\">{title}</p>\n              <p className=\"hb-ql4-s\">{subtitle}</p>\n            </div>\n            <span className=\"hb-ql4-m\">{time}</span>\n          </div>\n        </div>\n        <span id={hintId} className=\"hb-ql4-h\">\n          Swipe or use the left and right arrow keys to reveal actions\n        </span>\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}