{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shimmer-button",
  "title": "Shimmer Button",
  "description": "Primary action button whose light sweeps across its surface and rim on hover, focus, press, and whenever the change it commits is updated.",
  "dependencies": [
    "@radix-ui/react-slot",
    "class-variance-authority",
    "motion"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "utils",
    "https://reactmotionkit.com/r/compose-refs.json",
    "https://reactmotionkit.com/r/motion-kit.json",
    "https://reactmotionkit.com/r/motion-presets.json",
    "https://reactmotionkit.com/r/use-should-animate.json"
  ],
  "files": [
    {
      "path": "ui/shimmer-button.tsx",
      "content": "\"use client\"\n\nimport { Slot, Slottable } from \"@radix-ui/react-slot\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport {\n  animate,\n  type AnimationPlaybackControls,\n  motion,\n  useMotionValue,\n  useTransform,\n} from \"motion/react\"\nimport { type ComponentProps, type CSSProperties, useCallback, useEffect, useRef } from \"react\"\n\nimport { useShouldAnimate } from \"@/hooks/use-should-animate\"\nimport { composeRefs } from \"@/lib/compose-refs\"\nimport { durations, easings, type Temperament } from \"@/lib/motion\"\nimport { useMotionKit } from \"@/lib/motion-kit\"\nimport { cn } from \"@/lib/utils\"\n\nconst shimmerButtonVariants = cva(\n  \"group/shimmer relative isolate inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 overflow-hidden font-medium whitespace-nowrap transition-[box-shadow,filter] duration-200 ease-out outline-none select-none focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0\",\n  {\n    variants: {\n      variant: {\n        brand:\n          \"bg-brand text-brand-foreground shadow-[inset_0_1px_0_0_rgb(255_255_255/0.28),inset_0_-1px_0_0_rgb(0_0_0/0.12),0_1px_2px_0_rgb(0_0_0/0.16),0_6px_20px_-6px_color-mix(in_oklch,var(--brand)_65%,transparent)] [--shimmer:rgb(255_255_255/0.75)] hover:shadow-[inset_0_1px_0_0_rgb(255_255_255/0.32),inset_0_-1px_0_0_rgb(0_0_0/0.12),0_1px_2px_0_rgb(0_0_0/0.16),0_10px_32px_-6px_color-mix(in_oklch,var(--brand)_80%,transparent)] hover:brightness-[1.06] dark:[--shimmer:rgb(255_255_255/0.9)]\",\n        neutral:\n          \"bg-primary text-primary-foreground shadow-[inset_0_1px_0_0_rgb(255_255_255/0.14),0_1px_2px_0_rgb(0_0_0/0.16),0_6px_20px_-8px_rgb(0_0_0/0.35)] [--shimmer:color-mix(in_oklch,var(--primary-foreground)_45%,transparent)] hover:brightness-[1.08] dark:hover:brightness-[0.94]\",\n      },\n      size: {\n        sm: \"h-8 rounded-md px-3.5 text-sm [&_svg]:size-3.5\",\n        md: \"h-10 rounded-lg px-5 text-sm [&_svg]:size-4\",\n        lg: \"h-12 rounded-xl px-7 text-base [&_svg]:size-5\",\n      },\n    },\n    defaultVariants: { variant: \"brand\", size: \"md\" },\n  },\n)\n\ntype Variants = VariantProps<typeof shimmerButtonVariants>\n\nexport interface ShimmerButtonProps extends ComponentProps<\"button\"> {\n  /** Color treatment: the brand accent or the theme's primary color. */\n  variant?: Variants[\"variant\"]\n  /** Height, padding and text size. */\n  size?: Variants[\"size\"]\n  /** Render the child element (e.g. a link) instead of a `<button>`, keeping the styles. */\n  asChild?: boolean\n  /**\n   * What sweeps the light: `hover` runs one sweep when the pointer enters,\n   * keyboard focus arrives or a finger presses; `loop` also repeats it slowly\n   * while the button is on screen.\n   */\n  trigger?: \"hover\" | \"loop\"\n  /** Pause between sweeps with `trigger=\"loop\"`, in seconds. */\n  interval?: number\n  /** Character of the press and sweep. Wins over `MotionKitProvider`. */\n  temperament?: Temperament\n  /** Override the shimmer color with any CSS color. */\n  shimmerColor?: string\n  /**\n   * Cue the light from outside. Whenever this value changes after the first render, one\n   * sweep runs across the button, so the person sees that this action now reflects what they\n   * just changed (a plan, a quantity, a selection). With numbers the sweep follows the change:\n   * a larger value sweeps forward, a smaller one sweeps back. Reduced motion lights the rim\n   * for a moment instead. Disabled buttons stay still.\n   */\n  cue?: string | number | boolean\n}\n\nconst isActivationKey = (key: string) => key === \" \" || key === \"Enter\"\n\ntype Direction = 1 | -1\n\nconst cueDirection = (previous: unknown, next: unknown): Direction =>\n  typeof previous === \"number\" && typeof next === \"number\" && next < previous ? -1 : 1\n\n/**\n * Call-to-action button with a band of light that sweeps across its surface\n * and catches the rim when you point at it, focus it or press it. Pressing\n * squashes it down; releasing springs it back. Change `cue` and the light\n * sweeps on its own, pointing the eye at the action your last change affects.\n * Reduced motion keeps a static glow on hover, focus and cue instead.\n */\nexport function ShimmerButton({\n  asChild = false,\n  variant = \"brand\",\n  size = \"md\",\n  trigger = \"hover\",\n  interval = 2.4,\n  temperament,\n  shimmerColor,\n  cue,\n  disabled,\n  className,\n  style,\n  children,\n  onPointerEnter,\n  onPointerDown,\n  onPointerUp,\n  onPointerLeave,\n  onPointerCancel,\n  onFocus,\n  onKeyDown,\n  onKeyUp,\n  ref,\n  ...props\n}: ShimmerButtonProps) {\n  const rootRef = useRef<HTMLButtonElement>(null)\n  const { shouldAnimate } = useShouldAnimate(rootRef)\n  const motionKit = useMotionKit(temperament)\n  const { reduced, values } = motionKit\n  const Comp = asChild ? Slot : \"button\"\n\n  // Surface and rim read one progress value, so the light is a single source.\n  const progress = useMotionValue(0)\n  const surfaceX = useTransform(progress, [0, 1], [\"-100%\", \"270%\"])\n  const rimX = useTransform(progress, [0, 1], [\"-125%\", \"430%\"])\n  const sweepRef = useRef<AnimationPlaybackControls | null>(null)\n  const pressRef = useRef<AnimationPlaybackControls | null>(null)\n  const pressed = useRef(false)\n\n  // A sweep reads best a little slower than the temperament's own beat.\n  const sweepDuration = motionKit.seconds(durations.emphasis + values.duration)\n\n  // One sweep, forward (left to right) or back. Callers decide whether it may interrupt.\n  const runSweep = useCallback(\n    (direction: Direction) => {\n      sweepRef.current?.stop()\n      progress.set(direction === 1 ? 0 : 1)\n      sweepRef.current = animate(progress, direction === 1 ? 1 : 0, {\n        duration: sweepDuration,\n        ease: easings.inOutQuart,\n        onComplete: () => {\n          sweepRef.current = null\n          progress.set(0)\n        },\n      })\n    },\n    [progress, sweepDuration],\n  )\n\n  // Pointer and focus never cut a sweep short.\n  const sweep = () => {\n    if (reduced || disabled || sweepRef.current) return\n    runSweep(1)\n  }\n\n  // Cue: a change elsewhere sweeps the light once. The previous value lives in a ref so a\n  // re-render with the same cue (or a temperament change) never sweeps.\n  const lastCue = useRef(cue)\n  useEffect(() => {\n    const previous = lastCue.current\n    lastCue.current = cue\n    const node = rootRef.current\n    if (Object.is(previous, cue) || disabled || !node) return\n    const direction = cueDirection(previous, cue)\n    // The rim stays lit for one sweep, so the cue also reads with reduced motion.\n    node.dataset.cued = direction === 1 ? \"forward\" : \"back\"\n    const timer = setTimeout(() => {\n      delete node.dataset.cued\n    }, sweepDuration * 1000)\n    // A cue wins over a hover sweep still running: the newest cause gets the light. The loop\n    // already sweeps on its own, so it is left alone.\n    if (!reduced && trigger !== \"loop\") runSweep(direction)\n    return () => {\n      clearTimeout(timer)\n      delete node.dataset.cued\n    }\n  }, [cue, disabled, reduced, trigger, sweepDuration, runSweep])\n\n  useEffect(() => {\n    if (trigger !== \"loop\" || !shouldAnimate || disabled) return\n    sweepRef.current?.stop()\n    progress.set(0)\n    const controls = animate(progress, 1, {\n      duration: sweepDuration,\n      ease: easings.inOutQuart,\n      repeat: Infinity,\n      repeatDelay: motionKit.seconds(interval),\n      delay: motionKit.seconds(durations.emphasis),\n    })\n    sweepRef.current = controls\n    return () => {\n      controls.stop()\n      sweepRef.current = null\n      progress.set(0)\n    }\n  }, [trigger, shouldAnimate, disabled, sweepDuration, interval, motionKit, progress])\n\n  useEffect(\n    () => () => {\n      sweepRef.current?.stop()\n      pressRef.current?.stop()\n    },\n    [],\n  )\n\n  // Charge: sink and squash while held. Action and settle: spring back on release.\n  const charge = () => {\n    const node = rootRef.current\n    if (!node || reduced || pressed.current) return\n    pressed.current = true\n    const { anticipation, squash } = values\n    pressRef.current?.stop()\n    // The charge is quick and eased (the temperament's anticipation); the spring is\n    // saved for the release.\n    pressRef.current = animate(\n      node,\n      { scaleX: 1 + squash / 2, scaleY: 1 - squash },\n      { duration: motionKit.seconds(anticipation), ease: \"easeOut\" },\n    )\n  }\n\n  const release = () => {\n    const node = rootRef.current\n    if (!node || !pressed.current) return\n    pressed.current = false\n    pressRef.current?.stop()\n    pressRef.current = animate(node, { scaleX: 1, scaleY: 1 }, motionKit.springSmall)\n  }\n\n  return (\n    <Comp\n      data-slot=\"shimmer-button\"\n      data-trigger={trigger}\n      disabled={disabled}\n      ref={composeRefs(rootRef, ref)}\n      className={cn(shimmerButtonVariants({ variant, size }), className)}\n      style={shimmerColor ? ({ \"--shimmer\": shimmerColor, ...style } as CSSProperties) : style}\n      onPointerEnter={(event) => {\n        if (event.pointerType === \"mouse\") sweep()\n        onPointerEnter?.(event)\n      }}\n      onPointerDown={(event) => {\n        if (event.pointerType !== \"mouse\") sweep()\n        charge()\n        onPointerDown?.(event)\n      }}\n      onPointerUp={(event) => {\n        release()\n        onPointerUp?.(event)\n      }}\n      onPointerLeave={(event) => {\n        release()\n        onPointerLeave?.(event)\n      }}\n      onPointerCancel={(event) => {\n        release()\n        onPointerCancel?.(event)\n      }}\n      onFocus={(event) => {\n        if (event.currentTarget.matches(\":focus-visible\")) sweep()\n        onFocus?.(event)\n      }}\n      onKeyDown={(event) => {\n        if (isActivationKey(event.key) && !event.repeat) charge()\n        onKeyDown?.(event)\n      }}\n      onKeyUp={(event) => {\n        if (isActivationKey(event.key)) release()\n        onKeyUp?.(event)\n      }}\n      {...props}\n    >\n      {reduced ? (\n        // Reduced motion: no travel, the rim simply lights up on hover and focus.\n        <span\n          aria-hidden\n          data-slot=\"shimmer-rim\"\n          className=\"pointer-events-none absolute inset-0 rounded-[inherit] border border-(--shimmer) opacity-0 transition-opacity duration-200 group-hover/shimmer:opacity-60 group-focus-visible/shimmer:opacity-60 group-data-cued/shimmer:opacity-80\"\n        />\n      ) : (\n        <>\n          <span\n            aria-hidden\n            data-slot=\"shimmer\"\n            className=\"pointer-events-none absolute inset-0 -z-10 overflow-hidden rounded-[inherit]\"\n          >\n            <motion.span\n              className=\"absolute inset-y-0 left-0 w-3/5 bg-linear-to-r from-transparent via-(--shimmer) to-transparent opacity-60 dark:opacity-80\"\n              style={{ x: surfaceX, skewX: -20 }}\n            />\n          </span>\n          <span\n            aria-hidden\n            data-slot=\"shimmer-rim\"\n            className=\"pointer-events-none absolute inset-0 overflow-hidden rounded-[inherit] border border-transparent [mask-image:linear-gradient(#000,#000),linear-gradient(#000,#000)] [mask-composite:exclude] [mask-clip:padding-box,border-box]\"\n          >\n            <motion.span\n              className=\"absolute -inset-y-px left-0 w-2/5 bg-linear-to-r from-transparent via-(--shimmer) to-transparent\"\n              style={{ x: rimX, skewX: -20 }}\n            />\n          </span>\n        </>\n      )}\n      <Slottable>{children}</Slottable>\n    </Comp>\n  )\n}\n\nexport { shimmerButtonVariants }\n",
      "type": "registry:ui"
    }
  ],
  "cssVars": {
    "theme": {
      "color-brand": "var(--brand)",
      "color-brand-foreground": "var(--brand-foreground)"
    },
    "light": {
      "brand": "oklch(0.55 0.2 278)",
      "brand-foreground": "oklch(0.985 0.002 264)"
    },
    "dark": {
      "brand": "oklch(0.7 0.16 278)",
      "brand-foreground": "oklch(0.16 0.02 278)"
    }
  },
  "meta": {
    "tier": "free",
    "collection": "interface",
    "needsImage": false,
    "addedAt": "2026-10-12",
    "tags": [
      "button",
      "cta",
      "shimmer",
      "billing",
      "cue"
    ],
    "triggers": [
      "hover",
      "focus",
      "press",
      "value"
    ],
    "wave": "0",
    "tech": [],
    "presets": [],
    "keyboard": [
      {
        "keys": "Tab",
        "action": "Moves focus to the button and sweeps the light"
      },
      {
        "keys": "Space / Enter",
        "action": "Presses the button (squash, then click)"
      }
    ],
    "reducedMotion": "No sweep and no squash; the rim glows softly on hover and focus, and lights up briefly on every cue.",
    "heavy": false,
    "ai": {
      "summary": "Primary call-to-action button that draws the eye when the value it commits changes",
      "useCases": [
        "Upgrade plan button on a billing page that sweeps when seats change",
        "Publish button in an editor",
        "Rare call to action with an opt-in slow looping sweep"
      ],
      "whenToUse": "Use it for the one action a screen leads to. Pass cue the value the action commits, so the light sweeps when that value changes. One per screen.",
      "whenNotToUse": "Do not use it for secondary actions. For a physical press with loading and success use `ripple-button`.",
      "pairsWith": [
        "number-input",
        "segmented-control",
        "status-badge"
      ],
      "contexts": [
        "pricing",
        "saas-app",
        "landing",
        "dashboard"
      ],
      "keywords": [
        "shimmer",
        "button",
        "cta",
        "call to action",
        "primary",
        "upgrade",
        "billing",
        "sweep",
        "glow",
        "highlight"
      ],
      "triggers": [
        "hover",
        "focus",
        "click",
        "value",
        "ambient"
      ]
    }
  },
  "categories": [
    "buttons"
  ],
  "type": "registry:ui"
}