'use client'; import { forwardRef, HTMLAttributes } from 'react'; import styles from './coffee-stain.module.css'; export interface CoffeeStainProps extends HTMLAttributes { /** Size of stain */ size?: 'small' | 'medium' | 'large' | 'random'; /** Intensity of stain (opacity/color strength) */ intensity?: 'light' | 'medium' | 'dark'; /** Stain variant */ variant?: 'classic' | 'ring' | 'splash' | 'drip' | 'random'; /** Rotation angle */ rotation?: number; /** Position: absolute positioning coordinates */ position?: { top?: string; right?: string; bottom?: string; left?: string; }; /** Number of drips (for drip variant) */ dripCount?: number; /** Enable animation (slow fading/movement) */ animated?: boolean; } export const CoffeeStain = forwardRef( ( { size = 'medium', intensity = 'medium', variant = 'classic', rotation = 0, position, dripCount = 3, animated = false, className, style, ...props }, ref ) => { // Generate random values for 'random' variants const randomSize = Math.random() * 60 + 40; // 40-100px const randomRotation = Math.random() * 360; const finalSize = size === 'random' ? randomSize : undefined; const finalRotation = variant === 'random' ? randomRotation : rotation; const finalVariant = variant === 'random' ? ['classic', 'ring', 'splash', 'drip'][Math.floor(Math.random() * 4)] : variant; // Generate drips const drips = Array.from({ length: dripCount }, (_, i) => ({ id: i, angle: (360 / dripCount) * i + Math.random() * 30 - 15, length: Math.random() * 20 + 10, delay: Math.random() * 2, })); return (
{/* Main stain body */}
{/* Outer ring (for ring variant) */} {finalVariant === 'ring' &&
} {/* Splash marks (for splash variant) */} {finalVariant === 'splash' && (
{Array.from({ length: 8 }, (_, i) => (
))}
)} {/* Drips (for drip variant) */} {finalVariant === 'drip' && (
{drips.map((drip) => (
))}
)}
); } ); CoffeeStain.displayName = 'CoffeeStain'; export default CoffeeStain;