'use client';
import { forwardRef, HTMLAttributes, useId } from 'react';
export interface GlassCrackProps extends HTMLAttributes {
/** Crack intensity */
intensity?: 'light' | 'medium' | 'heavy';
/** Crack pattern */
pattern?: 'spiderweb' | 'lightning' | 'shattered' | 'random';
/** Crack color */
color?: string;
/** Show glow effect */
glow?: boolean;
/** Number of crack lines */
crackCount?: number;
}
export const GlassCrack = forwardRef(
(
{
intensity = 'medium',
pattern = 'spiderweb',
color = 'rgba(255, 255, 255, 0.5)',
glow = false,
crackCount = 12,
className = '',
...props
},
ref
) => {
const id = useId();
// Generate crack lines
const cracks = Array.from({ length: crackCount }, (_, i) => ({
id: i,
angle: (360 / crackCount) * i + Math.random() * 20 - 10,
length: 30 + Math.random() * 50,
curve: Math.random() * 20 - 10,
branches: Math.random() > 0.7 ? Math.floor(Math.random() * 3) + 1 : 0,
}));
const strokeWidth = intensity === 'heavy' ? 2 : intensity === 'light' ? 0.5 : 1;
const opacity = intensity === 'heavy' ? 1 : intensity === 'light' ? 0.7 : 0.8;
return (
<>
{cracks.map((crack) => (
))}
>
);
}
);
GlassCrack.displayName = 'GlassCrack';
export default GlassCrack;