Shimmer Layer

PreviousNext

Pure CSS to add an animated shimmer effect that activates on hover.

Docs
phucbmcomponent

Preview

Loading preview…
registry/phucbm/blocks/shimmer-layer/shimmer-layer.tsx
export interface ShimmerLayerProps {
    /** Width of each shine stripe in pixels. @default 10 */
    width?: number;
    /** Skew angle of the shine effect in degrees. @default -12 */
    skew?: number;
    /** Duration of the shine animation in milliseconds. @default 650 */
    duration?: number;
    /** Color of the shine effect. @default "#fff" */
    color?: string;
}

export function ShimmerLayer({
                                 width = 10,
                                 skew = -12,
                                 duration = 650,
                                 color = '#fff'
                             }: ShimmerLayerProps) {
    return (
        <>
            <style>{`
                @keyframes shine {
                    0% {
                        right:100%; left:auto; opacity:0;
                    }
                    50% {
                       opacity:0.4;
                    }
                    to {
                       right:-100%; left:auto; opacity:0;
                    }
                }
            `}</style>

            <i className="absolute top-1/2 right-full h-[150%] z-20 pointer-events-none opacity-0 blur-lg
            group-hover/shimmer:[animation:shine_600ms_ease-in-out]
            "
               style={{
                   width: `${width * 4}px`,
                   transform: `translate(-50%,-50%) skewX(${skew}deg)`,
                   background: `repeating-linear-gradient(to right, ${color}, ${color} ${width}px, transparent ${width}px, transparent ${width * 2.5}px)`,
                   animationDuration: `${duration}ms`
               }}
            >
            </i>
        </>
    );
}

Installation

npx shadcn@latest add @phucbm/shimmer-layer

Usage

import { ShimmerLayer } from "@/components/shimmer-layer"
<ShimmerLayer />