{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "eased-hold-core",
  "title": "Hold Core primitive",
  "description": "Hold-to-confirm: a time-true linear fill while the pointer, Space or Enter is held, a quick no-overshoot drain when let go early, and a button that reveals its label on brand as the hold runs. Shared by Approval Card and PR Review.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://eased.dev/r/eased-tokens.json",
    "https://eased.dev/r/eased-text-swap.json"
  ],
  "files": [
    {
      "path": "src/registry/eased/_primitives/hold-core/hold-core.tsx",
      "content": "\"use client\";\n\nimport { animate, motion, useMotionValue, useTransform, type AnimationPlaybackControls, type MotionValue } from \"motion/react\";\nimport { useCallback, useEffect, useRef, useState, type ButtonHTMLAttributes } from \"react\";\nimport { TextSwap } from \"../text-swap/text-swap\";\n\nexport type Hold = {\n  /** 0 → 1 while held; drains back to 0 when let go early. */\n  progress: MotionValue<number>;\n  /** True between the hold starting and it completing or being let go. */\n  holding: boolean;\n  start: () => void;\n  cancel: () => void;\n};\n\n/**\n * Hold-to-confirm timing. `start` fills `progress` linearly over the remaining share of\n * `holdMs`, so it reads as a clock and resuming a half-drained hold takes half the time;\n * `cancel` drains it on a short no-overshoot spring. `onDone` fires once the fill lands.\n */\nexport function useHold(holdMs: number, onDone: () => void, disabled: boolean): Hold {\n  const progress = useMotionValue(0);\n  const anim = useRef<AnimationPlaybackControls | null>(null);\n  const done = useRef(onDone);\n  useEffect(() => {\n    done.current = onDone;\n  });\n  const [holding, setHolding] = useState(false);\n\n  const start = useCallback(() => {\n    if (disabled || anim.current) return;\n    setHolding(true);\n    // Time-true fill: the remaining share of the hold, linearly, so it reads as a clock.\n    anim.current = animate(progress, 1, {\n      duration: (holdMs / 1000) * (1 - progress.get()),\n      ease: \"linear\",\n      onComplete: () => {\n        anim.current = null;\n        setHolding(false);\n        done.current();\n      },\n    });\n  }, [disabled, holdMs, progress]);\n\n  const cancel = useCallback(() => {\n    if (!anim.current) return;\n    anim.current.stop();\n    anim.current = null;\n    setHolding(false);\n    // Let go early and it drains back quickly on the smooth spring, never overshooting.\n    animate(progress, 0, { type: \"spring\", visualDuration: 0.3, bounce: 0 });\n  }, [progress]);\n\n  return { progress, holding, start, cancel };\n}\n\nexport type HoldButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, \"children\"> & {\n  hold: Hold;\n  label: string;\n};\n\n/**\n * A 32px button that runs `hold` on pointer, Space or Enter: the same check + label on brand\n * is revealed left to right as the hold runs. Pass the resting surface, cursor and press\n * classes in `className`; the fill, size and handlers are fixed.\n */\nexport function HoldButton({ hold, label, className = \"\", ...props }: HoldButtonProps) {\n  const clip = useTransform(hold.progress, (p) => `inset(0 ${(1 - p) * 100}% 0 0)`);\n  const content = (tone: string) => (\n    <span className={`inline-flex items-center gap-1.5 ${tone}`}>\n      <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.5} strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden className=\"size-4 shrink-0\">\n        <path d=\"M3.5 8.5l3 3 6-7\" />\n      </svg>\n      <TextSwap>{label}</TextSwap>\n    </span>\n  );\n  return (\n    <button\n      type=\"button\"\n      {...props}\n      data-holding={hold.holding || undefined}\n      onPointerDown={(e) => {\n        if (e.button !== 0) return;\n        e.currentTarget.setPointerCapture(e.pointerId);\n        hold.start();\n      }}\n      onPointerUp={hold.cancel}\n      onPointerCancel={hold.cancel}\n      onLostPointerCapture={hold.cancel}\n      onKeyDown={(e) => {\n        if ((e.key === \" \" || e.key === \"Enter\") && !e.repeat) {\n          e.preventDefault();\n          hold.start();\n        }\n      }}\n      onKeyUp={(e) => {\n        if (e.key === \" \" || e.key === \"Enter\") hold.cancel();\n      }}\n      onClick={(e) => e.preventDefault()}\n      onContextMenu={(e) => e.preventDefault()}\n      className={`relative inline-flex h-control-sm shrink-0 touch-none items-center justify-center overflow-hidden rounded-control-sm px-3 text-ui-sm font-medium select-none ${className}`}\n    >\n      {content(\"text-text\")}\n      {/* The fill: the same label on brand, revealed left to right as the hold runs. */}\n      <motion.span aria-hidden className=\"absolute inset-0 flex items-center justify-center bg-brand inset-shadow-highlight\" style={{ clipPath: clip }}>\n        {content(\"text-text-on-brand\")}\n      </motion.span>\n    </button>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/eased/_primitives/hold-core/hold-core.tsx"
    }
  ],
  "type": "registry:ui"
}