{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"shimmer-button","type":"registry:block","title":"Shimmer button","description":"A button with a light sweep across the surface on entrance, hover and focus, plus a ripple that starts where you click.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/prequel/shimmer-button/shimmer-button.tsx","type":"registry:component","content":"\"use client\";\n\nimport {\n  useEffect,\n  useRef,\n  useState,\n  type MouseEvent as ReactMouseEvent,\n  type ReactNode,\n} from \"react\";\nimport { useReducedMotion } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\n/* The sweep runs once on entrance and again on hover or keyboard focus.\n   The ripple is driven entirely by CSS and removes itself on animationend,\n   so no timers are left behind. */\nconst SHIMMER_CSS = `\n.prequel-shimmer-band {\n  position: absolute;\n  top: -12%;\n  left: -20%;\n  height: 124%;\n  width: 46%;\n  background: linear-gradient(\n    100deg,\n    transparent 0%,\n    color-mix(in oklab, currentColor 24%, transparent) 50%,\n    transparent 100%\n  );\n  transform: translateX(-180%) skewX(-18deg);\n  opacity: 0;\n  pointer-events: none;\n}\n.prequel-shimmer-group:hover .prequel-shimmer-band,\n.prequel-shimmer-group:focus-visible .prequel-shimmer-band,\n.prequel-shimmer-band[data-auto=\"true\"] {\n  opacity: 1;\n  animation: prequel-shimmer-sweep 900ms cubic-bezier(0.22, 1, 0.36, 1);\n}\n@keyframes prequel-shimmer-sweep {\n  from { transform: translateX(-180%) skewX(-18deg); }\n  to { transform: translateX(320%) skewX(-18deg); }\n}\n.prequel-shimmer-ripple {\n  position: absolute;\n  border-radius: 9999px;\n  background: currentColor;\n  opacity: 0;\n  pointer-events: none;\n  animation: prequel-shimmer-ripple 620ms cubic-bezier(0.22, 1, 0.36, 1) forwards;\n}\n@keyframes prequel-shimmer-ripple {\n  from { transform: scale(0); opacity: 0.28; }\n  to { transform: scale(2.2); opacity: 0; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .prequel-shimmer-band,\n  .prequel-shimmer-group:hover .prequel-shimmer-band,\n  .prequel-shimmer-group:focus-visible .prequel-shimmer-band,\n  .prequel-shimmer-band[data-auto=\"true\"] {\n    animation: none;\n    opacity: 0;\n  }\n  .prequel-shimmer-ripple {\n    animation: none;\n    opacity: 0;\n  }\n}\n`;\n\n/* ------------------------------------------------------------------ */\n/* types                                                               */\n/* ------------------------------------------------------------------ */\n\nexport type ShimmerButtonProps = {\n  className?: string;\n  /** Visible label. Defaults to \"Deploy to production\". */\n  children?: ReactNode;\n  /** Visual style. Defaults to \"solid\". */\n  variant?: \"solid\" | \"outline\";\n  /** Height and padding. Defaults to \"md\". */\n  size?: \"sm\" | \"md\" | \"lg\";\n  /** Renders a link instead of a button when set. */\n  href?: string;\n  /** Click handler for both the button and the link. */\n  onClick?: () => void;\n  /** Native button type. Defaults to \"button\". */\n  type?: \"button\" | \"submit\" | \"reset\";\n  /** Disables the button. Links keep their href. */\n  disabled?: boolean;\n  /** Accessible name when the visible label is not enough. */\n  ariaLabel?: string;\n  /** Show a ripple from the pointer or the centre of the button. Defaults to true. */\n  ripple?: boolean;\n};\n\ntype Ripple = {\n  id: number;\n  x: number;\n  y: number;\n  size: number;\n};\n\nconst VARIANTS = {\n  solid: \"bg-primary text-primary-foreground hover:bg-primary/90\",\n  outline: \"border border-border bg-card text-foreground hover:bg-muted\",\n} as const;\n\nconst SIZES = {\n  sm: \"h-8 px-3 text-[12.5px]\",\n  md: \"h-10 px-4 text-[13.5px]\",\n  lg: \"h-12 px-6 text-[15px]\",\n} as const;\n\n/* ------------------------------------------------------------------ */\n/* block                                                               */\n/* ------------------------------------------------------------------ */\n\nexport function ShimmerButton({\n  className,\n  children = \"Deploy to production\",\n  variant = \"solid\",\n  size = \"md\",\n  href,\n  onClick,\n  type = \"button\",\n  disabled = false,\n  ariaLabel,\n  ripple = true,\n}: ShimmerButtonProps) {\n  const reduce = Boolean(useReducedMotion());\n  const [autoSweep, setAutoSweep] = useState(false);\n  const [ripples, setRipples] = useState<Ripple[]>([]);\n  const nextRipple = useRef(0);\n\n  useEffect(() => {\n    if (reduce) return;\n    const timer = window.setTimeout(() => setAutoSweep(true), 520);\n    return () => window.clearTimeout(timer);\n  }, [reduce]);\n\n  const handleClick = (event: ReactMouseEvent<HTMLElement>) => {\n    onClick?.();\n    if (reduce || !ripple) return;\n\n    const rect = event.currentTarget.getBoundingClientRect();\n    const keyboard = event.detail === 0;\n    const size = Math.max(rect.width, rect.height) * 1.8;\n    const id = nextRipple.current++;\n\n    setRipples((current) => [\n      ...current.slice(-2),\n      {\n        id,\n        x: keyboard ? rect.width / 2 : event.clientX - rect.left,\n        y: keyboard ? rect.height / 2 : event.clientY - rect.top,\n        size,\n      },\n    ]);\n  };\n\n  const removeRipple = (id: number) => {\n    setRipples((current) => current.filter((item) => item.id !== id));\n  };\n\n  const classes = cn(\n    \"prequel-shimmer-group relative inline-flex select-none items-center justify-center overflow-hidden rounded-lg font-medium\",\n    \"transition-[background-color,transform] duration-200 active:translate-y-px motion-reduce:transition-none motion-reduce:active:translate-y-0\",\n    \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n    \"disabled:pointer-events-none disabled:opacity-50\",\n    VARIANTS[variant],\n    SIZES[size],\n    className\n  );\n\n  const inner = (\n    <>\n      <span\n        aria-hidden=\"true\"\n        className=\"prequel-shimmer-band\"\n        data-auto={autoSweep ? \"true\" : \"false\"}\n        onAnimationEnd={() => setAutoSweep(false)}\n      />\n      {ripples.map((item) => (\n        <span\n          key={item.id}\n          aria-hidden=\"true\"\n          className=\"prequel-shimmer-ripple\"\n          style={{\n            left: item.x - item.size / 2,\n            top: item.y - item.size / 2,\n            width: item.size,\n            height: item.size,\n          }}\n          onAnimationEnd={() => removeRipple(item.id)}\n        />\n      ))}\n      <span className=\"relative z-10 inline-flex items-center gap-2\">{children}</span>\n    </>\n  );\n\n  /* The default demo copy has no handler; point it at a real page rather\n     than leaving a button that does nothing. */\n  const link = href ?? (onClick ? undefined : \"/docs/installation\");\n\n  if (link) {\n    return (\n      <>\n        <style>{SHIMMER_CSS}</style>\n        <a\n          href={link}\n          onClick={handleClick}\n          aria-label={ariaLabel}\n          aria-disabled={disabled || undefined}\n          className={classes}\n        >\n          {inner}\n        </a>\n      </>\n    );\n  }\n\n  return (\n    <>\n      <style>{SHIMMER_CSS}</style>\n      <button\n        type={type}\n        onClick={handleClick}\n        disabled={disabled}\n        aria-label={ariaLabel}\n        className={classes}\n      >\n        {inner}\n      </button>\n    </>\n  );\n}\n\n/* Two actions side by side, handy for previews. */\nexport function ShimmerButtonDemo() {\n  return (\n    <div className=\"flex flex-wrap items-center gap-3\">\n      <ShimmerButton>Deploy to production</ShimmerButton>\n      <ShimmerButton variant=\"outline\" size=\"md\">\n        View the release\n      </ShimmerButton>\n    </div>\n  );\n}\n\nexport default ShimmerButton;\n"}]}