Installation
Add the component
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/shimmer-button.jsonFirst component? Set up your project first
Frameworks
The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.
"use client";
import * as React from "react";
import { motion, type HTMLMotionProps } from "motion/react";
import { cn } from "@/lib/utils";
import { pressSpring, useReduceMotion, useTempoTransition } from "./motion";
export type ShimmerButtonProps = HTMLMotionProps<"button"> & {
shimmerColor?: string;
shimmerDuration?: number;
shimmerDelay?: number;
shimmer?: boolean;
tapScale?: number;
};
const BASE =
"relative inline-flex h-10 items-center justify-center overflow-hidden rounded-lg bg-primary px-4 text-[13px] font-medium text-primary-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50";
export function ShimmerButton({
shimmerColor = "color-mix(in oklab, var(--primary-foreground) 55%, transparent)",
shimmerDuration = 900,
shimmerDelay = 60,
shimmer = true,
tapScale = 0.97,
className,
children,
onPointerEnter,
onClick,
...props
}: ShimmerButtonProps) {
const reduce = useReduceMotion();
const spring = useTempoTransition(pressSpring);
const [run, setRun] = React.useState(0);
const timer = React.useRef<number | undefined>(undefined);
React.useEffect(() => {
return () => {
if (timer.current !== undefined) window.clearTimeout(timer.current);
};
}, []);
const play = React.useCallback(
(delay = shimmerDelay) => {
if (!shimmer || reduce) return;
if (timer.current !== undefined) window.clearTimeout(timer.current);
timer.current = window.setTimeout(() => {
setRun((value) => value + 1);
}, delay);
},
[reduce, shimmer, shimmerDelay],
);
const overlay =
shimmer && run > 0 ? (
<motion.span
key={run}
aria-hidden="true"
data-slot="shimmer-button-beam"
initial={{ x: "-180%", skewX: -14, opacity: 0 }}
animate={{ x: "260%", skewX: -14, opacity: [0, 1, 1, 0] }}
transition={{
duration: shimmerDuration / 1000,
ease: [0.33, 0, 0.2, 1],
times: [0, 0.16, 0.72, 1],
}}
className="pointer-events-none absolute inset-y-0 left-0 z-0 w-[52%]"
style={{
background: `linear-gradient(105deg, transparent 0%, ${shimmerColor} 50%, transparent 100%)`,
}}
/>
) : null;
return (
<motion.button
data-slot="shimmer-button"
whileTap={reduce ? undefined : { scale: tapScale }}
transition={spring}
onPointerEnter={(event) => {
onPointerEnter?.(event);
if (event.pointerType !== "touch") play();
}}
onClick={(event) => {
onClick?.(event);
play(0);
}}
className={cn(BASE, className)}
{...props}
>
{overlay}
<span className="relative z-10 inline-flex items-center gap-2">
{children as React.ReactNode}
</span>
</motion.button>
);
}Install
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/shimmer-button.jsonDependencies
motion lucide-reactThe registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.
Usage
Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.
import { ShimmerButton } from "@/components/prequelui/shimmer-button";
export default function Demo() {
return (
<ShimmerButton onClick={() => console.log("created")}>
Create workspace
</ShimmerButton>
);
}import { ShimmerButton } from "@/components/prequelui/shimmer-button";
export function Variant() {
return (
<ShimmerButton tempo={1.2}>
…
</ShimmerButton>
);
}Animation
A narrow band of light crosses the button once per hover. It does not loop: the pass is a single answer to the pointer, then the surface returns to rest. A click replays a shorter pass from the same edge.
- Beam travel: 900 ms, from -180% to 260%, with a 14° skew.
- Opacity follows 0 → 1 → 1 → 0 at 0 / 16 / 72 / 100 % of the pass.
- Hover waits 60 ms before firing so a fast pass does not flicker.
- Press spring: 550 / 30 to a 0.97 scale.
- Reduced motion removes the beam and the press scale.
API Reference
Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.