'use client'; import { forwardRef, HTMLAttributes } from 'react'; 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; } const sizeClasses = { small: 'w-10 h-10', medium: 'w-15 h-15', large: 'w-20 h-20', random: '', }; const intensityColors = { light: 'rgba(101, 67, 33, 0.05)', medium: 'rgba(101, 67, 33, 0.12)', dark: 'rgba(101, 67, 33, 0.2)', }; const animationPulse = 'animate-stain-pulse'; 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; const stainColor = intensityColors[intensity]; // 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 */}
{/* Paper texture overlay */}
")`, }} /> {/* 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;