{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "send-button",
  "title": "Send Button",
  "description": "A send button whose label boards an origami plane that banks away on a fading contrail, then drops home once it's Delivered.",
  "dependencies": [
    "motion"
  ],
  "files": [
    {
      "path": "src/registry/easeout/send-button.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, animate, motion, useReducedMotion } from \"motion/react\"\n\n/*\n  Send button by easeout (easeoutstudio.com). Free to use, MIT.\n  Install: npx shadcn@latest add @easeout/send-button\n  The plane carries your words. Press it and the label's letters are reeled into the origami plane, nearest first.\n  The plane takes off with them, banking through its turns (its wings narrow as it rolls) and leaving a contrail\n  that fades behind it. While it's away \"Sending\" shimmers and a hairline ring fills around its empty slot; when\n  `onSend` resolves the slot fills, a check draws in and the label reads \"Delivered\". Then the plane drops back into\n  its slot from above and the words roll back in. Reduced motion: the labels change, nothing flies.\n*/\n\nexport type SendButtonProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"onClick\" | \"children\"> & {\n  /** Runs on click. The button stays on \"Sending\" until its promise settles (or for `minFlight` ms, whichever is longer). */\n  onSend?: () => unknown | Promise<unknown>\n  labels?: { idle?: string; sending?: string; sent?: string; failed?: string }\n  /** Shortest time on \"Sending\", so the flight always finishes. */\n  minFlight?: number\n  /** How long \"Delivered\" stays before the plane comes back. 0 keeps it. */\n  resetAfter?: number\n  ref?: React.Ref<HTMLButtonElement>\n}\n\ntype Phase = \"idle\" | \"boarding\" | \"sending\" | \"sent\" | \"failed\"\nconst EASE = [0.16, 1, 0.3, 1] as const\nconst BOARD = 0.42 // s for the letters to reach the plane\nconst FLY = 1.35\n// from the slot: a climbing S, banking left then right, then away up and to the right (y is up-negative)\nconst ROUTE = \"M0 0C14 -6 22 -24 10 -44C-2 -64 -34 -66 -30 -92C-26 -116 18 -118 52 -110C92 -100 120 -128 170 -170\"\n\n/* An origami plane seen from above, nose to the right: two wing halves and the keel, each its own fold of light. */\nexport function OrigamiPlane({ className, style }: { className?: string; style?: React.CSSProperties }) {\n  return (\n    <svg viewBox=\"0 0 24 24\" className={className} style={style} aria-hidden=\"true\">\n      <path d=\"M22.5 12 1.5 3.2 6.4 12Z\" fill=\"currentColor\" />\n      <path d=\"M22.5 12 6.4 12 1.5 20.8Z\" fill=\"currentColor\" fillOpacity=\".62\" />\n      <path d=\"M22.5 12 6.4 12 10.2 16.4Z\" fill=\"currentColor\" fillOpacity=\".34\" />\n    </svg>\n  )\n}\n\nexport function SendButton({\n  onSend,\n  labels,\n  minFlight = 1500,\n  resetAfter = 2200,\n  className,\n  disabled,\n  ref,\n  ...rest\n}: SendButtonProps) {\n  const reduce = useReducedMotion()\n  const [phase, setPhase] = React.useState<Phase>(\"idle\")\n  const [flight, setFlight] = React.useState(0) // bumps per launch, so the flight layer remounts\n  const [home, setHome] = React.useState(true) // the plane is in its slot\n  const [back, setBack] = React.useState(false) // it has just flown home: drop in from above instead of fading\n  const text = {\n    idle: labels?.idle ?? \"Send\",\n    sending: labels?.sending ?? \"Sending\",\n    sent: labels?.sent ?? \"Delivered\",\n    failed: labels?.failed ?? \"Try again\",\n  }\n  const words = React.useRef<HTMLSpanElement>(null)\n  const slot = React.useRef<HTMLSpanElement>(null)\n\n  // the button's width follows its label, measured from hidden copies so it never jumps\n  const sizer = React.useRef<HTMLSpanElement>(null)\n  const [widths, setWidths] = React.useState<number[] | null>(null)\n  React.useLayoutEffect(() => {\n    const el = sizer.current\n    if (!el) return\n    const m = () => setWidths([...el.children].map((c) => Math.ceil((c as HTMLElement).getBoundingClientRect().width)))\n    m()\n    document.fonts?.ready.then(m)\n  }, [text.idle, text.sending, text.sent, text.failed])\n  const wi = phase === \"idle\" || phase === \"boarding\" ? 0 : phase === \"sending\" ? 1 : phase === \"sent\" ? 2 : 3\n\n  const timer = React.useRef(0)\n  React.useEffect(() => () => clearTimeout(timer.current), [])\n\n  // the letters fly into the plane, the one nearest it first\n  const board = () => {\n    const box = words.current\n    const s = slot.current\n    if (!box || !s) return\n    const to = s.getBoundingClientRect()\n    const cx = to.left + to.width / 2\n    const cy = to.top + to.height / 2\n    const letters = [...box.querySelectorAll<HTMLElement>(\"[data-l]\")].reverse()\n    letters.forEach((el, i) => {\n      const r = el.getBoundingClientRect()\n      const dx = cx - (r.left + r.width / 2)\n      const dy = cy - (r.top + r.height / 2)\n      animate(\n        el,\n        { x: [0, dx], y: [0, dy - 6, dy], scale: [1, 0.25], opacity: [1, 1, 0] },\n        { duration: BOARD - 0.08, delay: i * (0.08 / Math.max(1, letters.length - 1)), ease: [0.55, 0, 0.75, 0.2] },\n      )\n    })\n  }\n\n  const send = async () => {\n    if (phase !== \"idle\" && phase !== \"sent\" && phase !== \"failed\") return\n    if (disabled) return\n    clearTimeout(timer.current)\n    let ok = true\n    const work = Promise.resolve()\n      .then(() => onSend?.())\n      .catch(() => (ok = false))\n    if (!reduce && phase === \"idle\") {\n      setPhase(\"boarding\")\n      board()\n      await new Promise((r) => setTimeout(r, BOARD * 1000))\n      setHome(false)\n      setBack(false)\n      setFlight((n) => n + 1)\n    }\n    setPhase(\"sending\")\n    await Promise.all([work, new Promise((r) => setTimeout(r, reduce ? 300 : minFlight))])\n    setPhase(ok ? \"sent\" : \"failed\")\n    if (!ok) return\n    if (resetAfter > 0)\n      timer.current = window.setTimeout(() => {\n        setBack(true)\n        setHome(true)\n        setPhase(\"idle\")\n      }, resetAfter)\n  }\n\n  const away = !home && !reduce\n  return (\n    <span className=\"relative inline-flex\">\n      <motion.button\n        ref={ref}\n        type=\"button\"\n        {...(rest as React.ComponentProps<typeof motion.button>)}\n        disabled={disabled}\n        aria-disabled={phase === \"boarding\" || phase === \"sending\" || undefined}\n        aria-label={phase === \"idle\" || phase === \"boarding\" ? text.idle : text[phase]}\n        onClick={send}\n        animate={widths ? { width: widths[wi] + 70 } : undefined}\n        transition={{ width: { type: \"spring\", stiffness: 380, damping: 34 } }}\n        whileTap={phase === \"idle\" ? { scale: 0.97 } : undefined}\n        className={[\n          \"group/send relative inline-flex h-12 items-center justify-start overflow-visible rounded-full bg-foreground pr-12 pl-5 text-[15px] font-medium tracking-[-0.01em] text-background outline-none select-none\",\n          \"shadow-[inset_0_1px_0_rgb(255_255_255/.14),inset_0_-1px_0_rgb(0_0_0/.25)] focus-visible:ring-2 focus-visible:ring-foreground/40 focus-visible:ring-offset-2 disabled:opacity-50\",\n          phase === \"boarding\" || phase === \"sending\" ? \"cursor-progress\" : \"cursor-pointer\",\n          className,\n        ]\n          .filter(Boolean)\n          .join(\" \")}\n      >\n        {/* the label: the words that board the plane, then the flight's status in their place */}\n        <span className=\"relative inline-flex h-full shrink-0 items-center whitespace-pre\">\n          <AnimatePresence mode=\"popLayout\" initial={false}>\n            {phase === \"idle\" || phase === \"boarding\" ? (\n              <motion.span key=\"idle\" ref={words} className=\"inline-flex\" exit={{ opacity: 0, transition: { duration: 0 } }}>\n                {text.idle.split(\"\").map((ch, i) => (\n                  <motion.span\n                    key={i}\n                    data-l=\"\"\n                    className=\"inline-block\"\n                    initial={back ? { y: 10, opacity: 0, filter: \"blur(4px)\" } : false}\n                    animate={{ y: 0, opacity: 1, filter: \"blur(0px)\" }}\n                    transition={{ duration: 0.4, ease: EASE, delay: back ? 0.25 + i * 0.03 : 0 }}\n                  >\n                    {ch}\n                  </motion.span>\n                ))}\n              </motion.span>\n            ) : phase === \"sending\" ? (\n              <motion.span\n                key=\"sending\"\n                className=\"bg-[linear-gradient(100deg,currentColor_40%,var(--color-background)_50%,currentColor_60%)] bg-[length:250%_100%] bg-clip-text text-background/55 [-webkit-text-fill-color:transparent]\"\n                initial={{ opacity: 0, y: 8 }}\n                animate={{ opacity: 1, y: 0, backgroundPositionX: [\"100%\", \"-150%\"] }}\n                exit={{ opacity: 0, y: -8 }}\n                transition={{ duration: 0.3, ease: EASE, backgroundPositionX: { duration: 1.6, ease: \"linear\", repeat: Infinity } }}\n              >\n                {text.sending}\n              </motion.span>\n            ) : (\n              <motion.span\n                key={phase}\n                initial={{ opacity: 0, y: 8, filter: \"blur(4px)\" }}\n                animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n                exit={{ opacity: 0, y: -8 }}\n                transition={{ duration: 0.35, ease: EASE }}\n              >\n                {text[phase]}\n              </motion.span>\n            )}\n          </AnimatePresence>\n        </span>\n\n        {/* the slot: a recess the plane sits in; a ring fills round it while the plane is away, then it fills solid */}\n        <span ref={slot} className=\"absolute top-1/2 right-1.5 grid size-9 -translate-y-1/2 place-items-center\">\n          <motion.span\n            className=\"absolute inset-0 rounded-full\"\n            initial={false}\n            animate={{ backgroundColor: phase === \"sent\" ? \"var(--color-background)\" : \"rgb(128 128 128 / .2)\", scale: phase === \"sent\" ? [0.8, 1.08, 1] : 1 }}\n            transition={{ duration: 0.45, ease: EASE }}\n          />\n          <svg viewBox=\"0 0 36 36\" className=\"absolute inset-0 -rotate-90\" aria-hidden=\"true\">\n            <motion.circle\n              cx=\"18\"\n              cy=\"18\"\n              r=\"16.5\"\n              fill=\"none\"\n              stroke=\"currentColor\"\n              strokeOpacity=\".55\"\n              strokeWidth=\"1.25\"\n              strokeLinecap=\"round\"\n              initial={false}\n              animate={{ pathLength: phase === \"sending\" ? 0.92 : phase === \"sent\" ? 1 : 0, opacity: phase === \"sending\" ? 1 : 0 }}\n              transition={{ pathLength: { duration: phase === \"sending\" ? minFlight / 1000 : 0.3, ease: [0.3, 0, 0.2, 1] }, opacity: { duration: 0.3 } }}\n            />\n          </svg>\n          <AnimatePresence mode=\"popLayout\" initial={false}>\n            {phase === \"sent\" ? (\n              <motion.svg\n                key=\"ok\"\n                viewBox=\"0 0 24 24\"\n                className=\"relative size-[17px] text-foreground\"\n                fill=\"none\"\n                stroke=\"currentColor\"\n                strokeWidth=\"2.6\"\n                strokeLinecap=\"round\"\n                strokeLinejoin=\"round\"\n                initial={{ opacity: 0 }}\n                animate={{ opacity: 1 }}\n                exit={{ opacity: 0 }}\n              >\n                <motion.path d=\"M5 12.5l4.5 4.5L19 7.5\" initial={{ pathLength: 0 }} animate={{ pathLength: 1 }} transition={{ duration: 0.4, ease: EASE, delay: 0.12 }} />\n              </motion.svg>\n            ) : !away ? (\n              <motion.span\n                key={back ? \"back\" : \"plane\"}\n                className=\"relative block\"\n                // flown home, it drops in from above and settles; otherwise it's simply there\n                initial={back ? { y: -30, x: -6, rotate: 35, opacity: 0, scale: 0.8 } : false}\n                animate={{ y: 0, x: 0, rotate: phase === \"boarding\" ? -18 : 0, opacity: 1, scale: phase === \"boarding\" ? 1.12 : 1 }}\n                exit={{ opacity: 0, transition: { duration: 0 } }}\n                transition={{ type: \"spring\", stiffness: 420, damping: 22 }}\n              >\n                <OrigamiPlane className=\"size-[19px] transition-transform duration-300 ease-[cubic-bezier(.16,1,.3,1)] group-hover/send:-translate-y-[1.5px] group-hover/send:-rotate-[14deg]\" />\n              </motion.span>\n            ) : null}\n          </AnimatePresence>\n        </span>\n      </motion.button>\n      {/* the flight, outside the button so it can leave it */}\n      {flight > 0 && <Flight key={flight} />}\n      {/* every label's width, for the button's width */}\n      <span ref={sizer} aria-hidden=\"true\" className=\"pointer-events-none invisible absolute top-0 left-0 flex text-[15px] font-medium tracking-[-0.01em] whitespace-pre\">\n        <span>{text.idle}</span>\n        <span>{text.sending}</span>\n        <span>{text.sent}</span>\n        <span>{text.failed}</span>\n      </span>\n      <span className=\"sr-only\" aria-live=\"polite\">\n        {phase === \"sending\" ? text.sending : phase === \"sent\" ? text.sent : phase === \"failed\" ? text.failed : \"\"}\n      </span>\n    </span>\n  )\n}\n\n/* One progress value drives the plane and its contrail: position and heading from the path, a roll from how fast the\n   heading turns (the wings narrow as it banks), and a trail drawn up to the plane whose tail wears away behind it. */\nfunction Flight() {\n  const track = React.useRef<SVGPathElement>(null)\n  const reveal = React.useRef<SVGPathElement>(null)\n  const jet = React.useRef<HTMLSpanElement>(null)\n  const [gone, setGone] = React.useState(false)\n  const id = React.useId().replace(/[^a-zA-Z0-9]/g, \"\")\n\n  React.useEffect(() => {\n    const p = track.current\n    const m = reveal.current\n    const j = jet.current\n    if (!p || !m || !j) return\n    const total = p.getTotalLength()\n    let lastDeg = NaN\n    let bank = 0\n    const place = (v: number) => {\n      const L = v * total\n      const at = p.getPointAtLength(L)\n      const a = p.getPointAtLength(Math.min(total, L + 1))\n      const b = p.getPointAtLength(Math.max(0, L - 1))\n      const deg = (Math.atan2(a.y - b.y, a.x - b.x) * 180) / Math.PI\n      let turn = Number.isNaN(lastDeg) ? 0 : deg - lastDeg\n      if (turn > 180) turn -= 360\n      if (turn < -180) turn += 360\n      lastDeg = deg\n      bank += (Math.max(-1, Math.min(1, turn / 6)) - bank) * 0.25\n      const roll = 1 - Math.abs(bank) * 0.55\n      const sc = v < 0.1 ? 0.9 + v * 2 : v > 0.75 ? 1.1 - (v - 0.75) * 1.2 : 1.1\n      j.style.transform = `translate(${at.x.toFixed(1)}px,${at.y.toFixed(1)}px) translate(-50%,-50%) rotate(${deg.toFixed(1)}deg) scale(${sc.toFixed(3)},${(sc * roll).toFixed(3)})`\n      j.style.opacity = v > 0.8 ? String(Math.max(0, 1 - (v - 0.8) / 0.2)) : \"1\"\n      const tail = Math.max(0, L - total * 0.55)\n      m.setAttribute(\"stroke-dasharray\", `0 ${tail.toFixed(1)} ${(L - tail).toFixed(1)} ${total.toFixed(1)}`)\n    }\n    place(0)\n    const run = animate(0, 1, { duration: FLY, ease: [0.45, 0, 0.2, 1], onUpdate: place, onComplete: () => setGone(true) })\n    return () => run.stop()\n  }, [])\n\n  return (\n    // anchored on the slot's centre (right edge of the button, middle)\n    <span aria-hidden=\"true\" className=\"pointer-events-none absolute top-1/2 right-6 z-10 size-0 overflow-visible\">\n      <motion.svg className=\"absolute overflow-visible text-foreground\" width=\"1\" height=\"1\" animate={{ opacity: gone ? 0 : 1 }} transition={{ duration: 0.45 }}>\n        <defs>\n          <linearGradient id={`g${id}`} gradientUnits=\"userSpaceOnUse\" x1=\"0\" y1=\"0\" x2=\"170\" y2=\"-170\">\n            <stop offset=\"0\" stopColor=\"currentColor\" stopOpacity=\"0\" />\n            <stop offset=\".35\" stopColor=\"currentColor\" stopOpacity=\".35\" />\n            <stop offset=\"1\" stopColor=\"currentColor\" stopOpacity=\".55\" />\n          </linearGradient>\n          <mask id={`m${id}`} maskUnits=\"userSpaceOnUse\" x=\"-240\" y=\"-240\" width=\"480\" height=\"480\">\n            <path ref={reveal} d={ROUTE} fill=\"none\" stroke=\"#fff\" strokeWidth=\"10\" strokeLinecap=\"round\" strokeDasharray=\"0 1000\" />\n          </mask>\n        </defs>\n        <path ref={track} d={ROUTE} fill=\"none\" stroke=\"none\" />\n        <path d={ROUTE} fill=\"none\" stroke={`url(#g${id})`} strokeWidth=\"1.75\" strokeLinecap=\"round\" mask={`url(#m${id})`} />\n      </motion.svg>\n      <span ref={jet} className=\"absolute top-0 left-0 text-foreground will-change-transform\">\n        <OrigamiPlane className=\"size-5\" />\n      </span>\n    </span>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Import it with `import { SendButton } from \"@/components/send-button\"`. Live demo, props and a usage example: https://www.easeoutstudio.com/lab/send-button",
  "type": "registry:component"
}
