Files
2026-06-16 13:04:11 +03:00

63 lines
2.0 KiB
TypeScript

'use client';
import React from "react";
import { cn } from "@/components/common/Navbar"; // reuse cn
export interface ShimmerButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
shimmerColor?: string;
shimmerSize?: string;
borderRadius?: string;
shimmerDuration?: string;
background?: string;
className?: string;
children?: React.ReactNode;
}
export const ShimmerButton = React.forwardRef<HTMLButtonElement, ShimmerButtonProps>(
(
{
shimmerColor = "#ffffff",
shimmerSize = "0.05em",
shimmerDuration = "3s",
borderRadius = "100px",
background = "rgba(0, 0, 0, 1)",
className,
children,
...props
},
ref,
) => {
return (
<button
style={
{
"--spread": "90deg",
"--shimmer-color": shimmerColor,
"--radius": borderRadius,
"--speed": shimmerDuration,
"--cut": shimmerSize,
"--bg": background,
} as React.CSSProperties
}
className={cn(
"group relative z-0 flex cursor-pointer items-center justify-center overflow-hidden whitespace-nowrap border border-white/10 px-6 py-3 text-white [background:var(--bg)] [border-radius:var(--radius)] dark:text-black transform-gpu transition-transform duration-300 ease-in-out active:translate-y-px",
className,
)}
ref={ref}
{...props}
>
<div className="absolute inset-0 overflow-visible [container-type:size]">
<div className="absolute inset-0 h-[100cqh] animate-[shimmer_var(--speed)_infinite_linear] bg-[length:200%_100%] bg-[linear-gradient(var(--spread),transparent_0%,var(--shimmer-color)_50%,transparent_100%)] [aspect-ratio:1/1]" />
</div>
<div className="absolute inset-[var(--cut)] bg-[var(--bg)] [border-radius:var(--radius)]" />
<span className="relative z-10 flex w-full items-center justify-center gap-2">
{children}
</span>
</button>
);
},
);
ShimmerButton.displayName = "ShimmerButton";