Shine Border

Shine border is an animated background border effect.


Usage

Code

import { cnBase } from "tailwind-variants";
type Color = string | string[];
export interface ShineBorderProps {
borderRadius?: number;
borderWidth?: number;
duration?: number;
color?: Color;
className?: string;
children: React.ReactNode;
}
export const ShineBorder: React.FC<ShineBorderProps> = ({
borderRadius = 8,
borderWidth = 2,
duration = 14,
color = "#000000",
className,
children,
}) => {
return (
<div
style={
{
"--border-radius": `${borderRadius}px`,
} as React.CSSProperties
}
className={cnBase(
"relative grid w-fit place-items-center rounded-[--border-radius] bg-white p-3 text-black dark:bg-black dark:text-white",
className,
)}
>
<div
style={
{
"--border-width": `${borderWidth}px`,
"--border-radius": `${borderRadius}px`,
"--shine-pulse-duration": `${duration}s`,
"--mask-linear-gradient": `linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)`,
"--background-radial-gradient": `radial-gradient(transparent,transparent, ${color instanceof Array ? color.join(",") : color},transparent,transparent)`,
} as React.CSSProperties
}
className={`before:bg-shine-size before:absolute before:inset-0 before:aspect-square before:size-full before:rounded-[--border-radius] before:p-[--border-width] before:will-change-[background-position] before:content-[""] before:![-webkit-mask-composite:xor] before:![mask-composite:exclude] before:[background-image:--background-radial-gradient] before:[background-size:300%_300%] before:[mask:--mask-linear-gradient] motion-safe:before:animate-[shine-pulse_var(--shine-pulse-duration)_infinite_linear]`}
></div>
{children}
</div>
);
}

Update tailwind.config.js

Add the following animations to your tailwind.config.js file.

/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {
keyframes: {
"shine-pulse": {
"0%": {
"background-position": "0% 0%",
},
"50%": {
"background-position": "100% 100%",
},
to: {
"background-position": "0% 0%",
},
},
},
},
},
};

Shine Border Button

Props

AttributeTypeDescriptionDefault
classNamestringThe class name to be applied to the component.
durationnumberDefines the animation duration to be applied on the shining border in seconds.14
colorstringDefines the color of the border.#FFFFFF
borderRadiusnumberDefines the radius of the border.8px
borderWidthnumberDefines the width of the border.1px
childrenReactNodeContains react node elements.{}