{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "flip-button",
  "title": "Flip Button",
  "description": "A button whose fill sweeps in, label flips letter by letter, and primary variant leans toward the cursor.",
  "dependencies": [
    "motion"
  ],
  "files": [
    {
      "path": "src/registry/easeout/flip-button.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { useMotionValueEvent, useReducedMotion, useSpring } from \"motion/react\"\n\n/*\n  Flip button by easeout (easeoutstudio.com). Free to use, MIT.\n  Install: npx shadcn@latest add @easeout/flip-button\n  On hover/focus a fill sweeps in from the left, the label flips letter by letter (12ms apart), and the primary\n  variant leans toward the cursor on a spring (±6px). Touch devices get the press feedback only.\n*/\n\nexport type FlipButtonProps = {\n  children: string\n  variant?: \"primary\" | \"ghost\"\n  arrow?: boolean\n  href?: string\n  /** Shows the hover state without a pointer, e.g. to demo it. */\n  active?: boolean\n  className?: string\n} & Omit<React.ComponentPropsWithoutRef<\"button\">, \"children\">\n\nconst clamp = (v: number, a: number, b: number) => (v < a ? a : v > b ? b : v)\n\nexport function FlipButton({ children, variant = \"primary\", arrow = variant === \"primary\", href, active = false, className, ...rest }: FlipButtonProps) {\n  const ref = React.useRef<HTMLElement>(null)\n  const reduce = useReducedMotion()\n  const x = useSpring(0, { stiffness: 400, damping: 40 })\n  const y = useSpring(0, { stiffness: 400, damping: 40 })\n  useMotionValueEvent(x, \"change\", (v) => ref.current?.style.setProperty(\"--fb-x\", `${v}px`))\n  useMotionValueEvent(y, \"change\", (v) => ref.current?.style.setProperty(\"--fb-y\", `${v}px`))\n  const magnet = variant === \"primary\" && !reduce\n\n  const onPointerMove = (e: React.PointerEvent<HTMLElement>) => {\n    if (!magnet || e.pointerType !== \"mouse\") return\n    const r = e.currentTarget.getBoundingClientRect()\n    x.set(clamp((e.clientX - r.left - r.width / 2) * 0.2, -6, 6))\n    y.set(clamp((e.clientY - r.top - r.height / 2) * 0.3, -4, 4))\n  }\n  const onPointerLeave = () => {\n    x.set(0)\n    y.set(0)\n  }\n\n  const chars = children.replace(/\\s+/g, \" \").trim().split(\"\")\n  const flip =\n    \"[transition:transform_300ms_cubic-bezier(.23,1,.32,1)_calc(20ms+var(--i)*12ms),opacity_200ms_ease_calc(20ms+var(--i)*12ms)] [backface-visibility:hidden] [transform-origin:50%_50%_-6px]\"\n  const cls = [\n    \"group/fb relative isolate inline-flex h-11 cursor-pointer items-center gap-2 overflow-hidden whitespace-nowrap rounded-full border border-solid px-5 text-[14px] font-medium tracking-[-0.01em] no-underline\",\n    \"[transform:translate(var(--fb-x,0px),var(--fb-y,0px))] active:[transform:translate(var(--fb-x,0px),var(--fb-y,0px))_scale(.97)] [transition:transform_140ms_cubic-bezier(.23,1,.32,1),border-color_300ms]\",\n    \"before:absolute before:inset-0 before:-z-10 before:origin-right before:scale-x-0 before:rounded-[inherit] before:bg-[var(--fb-fill)] before:transition-transform before:duration-300 before:ease-[cubic-bezier(.23,1,.32,1)] before:content-['']\",\n    \"focus-visible:before:origin-left focus-visible:before:scale-x-100 data-[active]:before:origin-left data-[active]:before:scale-x-100 [@media(hover:hover)]:hover:before:origin-left [@media(hover:hover)]:hover:before:scale-x-100\",\n    \"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-foreground\",\n    variant === \"primary\"\n      ? \"border-transparent bg-primary text-primary-foreground [--fb-fill:var(--color-foreground)] [--fb-text:var(--color-background)]\"\n      : \"border-foreground bg-transparent text-foreground [--fb-fill:var(--color-foreground)] [--fb-text:var(--color-background)]\",\n    className,\n  ]\n    .filter(Boolean)\n    .join(\" \")\n\n  const label = (\n    <>\n      <span aria-hidden=\"true\" className=\"inline-flex whitespace-pre [perspective:400px]\">\n        {chars.map((c, i) => (\n          <span key={i} className=\"relative inline-block overflow-hidden leading-[1.25]\" style={{ \"--i\": i } as React.CSSProperties}>\n            <span className={`block ${flip} motion-safe:group-focus-visible/fb:[transform:translateY(-100%)_rotateX(90deg)] motion-safe:group-focus-visible/fb:opacity-0 motion-safe:group-data-[active]/fb:[transform:translateY(-100%)_rotateX(90deg)] motion-safe:group-data-[active]/fb:opacity-0 [@media(hover:hover)]:motion-safe:group-hover/fb:[transform:translateY(-100%)_rotateX(90deg)] [@media(hover:hover)]:motion-safe:group-hover/fb:opacity-0`}>\n              {c}\n            </span>\n            <span className={`absolute inset-0 block text-[var(--fb-text)] opacity-0 [transform:translateY(100%)_rotateX(-90deg)] ${flip} motion-safe:group-focus-visible/fb:[transform:none] motion-safe:group-focus-visible/fb:opacity-100 motion-safe:group-data-[active]/fb:[transform:none] motion-safe:group-data-[active]/fb:opacity-100 [@media(hover:hover)]:motion-safe:group-hover/fb:[transform:none] [@media(hover:hover)]:motion-safe:group-hover/fb:opacity-100`}>\n              {c}\n            </span>\n          </span>\n        ))}\n      </span>\n      <span className=\"sr-only\">{children}</span>\n      {arrow && (\n        <span aria-hidden=\"true\" className=\"transition-[transform,color] duration-200 group-focus-visible/fb:translate-x-[3px] group-focus-visible/fb:text-[var(--fb-text)] group-data-[active]/fb:translate-x-[3px] group-data-[active]/fb:text-[var(--fb-text)] [@media(hover:hover)]:group-hover/fb:translate-x-[3px] [@media(hover:hover)]:group-hover/fb:text-[var(--fb-text)]\">\n          →\n        </span>\n      )}\n    </>\n  )\n\n  if (href)\n    return (\n      <a ref={ref as React.Ref<HTMLAnchorElement>} href={href} data-active={active || undefined} className={cls} onPointerMove={onPointerMove} onPointerLeave={onPointerLeave}>\n        {label}\n      </a>\n    )\n  return (\n    <button ref={ref as React.Ref<HTMLButtonElement>} type=\"button\" data-active={active || undefined} className={cls} onPointerMove={onPointerMove} onPointerLeave={onPointerLeave} {...rest}>\n      {label}\n    </button>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Import it with `import { FlipButton } from \"@/components/flip-button\"`. Live demo, props and a usage example: https://www.easeoutstudio.com/lab/flip-button",
  "type": "registry:component"
}