import { motion } from "framer-motion"; import React, { useEffect, useRef } from "react"; export interface AnimatedGradientBackgroundProps { /** * Initial size of the radial gradient, defining the starting width. * @default 125 */ startingGap?: number; /** * Enables or disables the breathing animation effect. * @default true */ Breathing?: boolean; /** * Array of colors to use in the radial gradient. * Each color corresponds to a stop percentage in `gradientStops`. * @default ["#0A0A0A", "#2979FF", "#FF80AB", "#FF6D00", "#FFD600", "#00E676", "#3D5AFE"] */ gradientColors?: string[]; /** * Array of percentage stops corresponding to each color in `gradientColors`. * The values should range between 0 and 100. * @default [35, 50, 60, 70, 80, 90, 100] */ gradientStops?: number[]; /** * Speed of the breathing animation. * Lower values result in slower animation. * @default 0.02 */ animationSpeed?: number; /** * Maximum range for the breathing animation in percentage points. * Determines how much the gradient "breathes" by expanding and contracting. * @default 5 */ breathingRange?: number; /** * Additional inline styles for the gradient container. * @default {} */ containerStyle?: React.CSSProperties; /** * Additional class names for the gradient container. * @default "" */ containerClassName?: string; /** * Additional top offset for the gradient container form the top to have a more flexible control over the gradient. * @default 0 */ topOffset?: number; } export const AnimatedGradientBackground: React.FC = ({ startingGap = 110, Breathing = true, gradientColors = [ "#08090E", "#1E1B4B", "#312E81", "#2563EB", "#7C3AED", "#EC4899", "#08090E" ], gradientStops = [25, 45, 60, 75, 88, 95, 100], animationSpeed = 0.04, breathingRange = 12, containerStyle = {}, topOffset = 0, containerClassName = "", }) => { const containerRef = useRef(null); useEffect(() => { let animationFrame: number; let width = startingGap; let direction = 1; let angle = 0; const animateGradient = () => { if (width >= startingGap + breathingRange) direction = -1; if (width <= startingGap - breathingRange) direction = 1; if (Breathing) { width += direction * animationSpeed; angle = (angle + 0.15) % 360; } const gradientStopsString = gradientStops .map((stop, index) => `${gradientColors[index]} ${stop}%`) .join(", "); const gradient = `radial-gradient(${width}% ${width + topOffset}% at ${50 + Math.sin(angle * 0.02) * 15}% ${25 + Math.cos(angle * 0.02) * 10}%, ${gradientStopsString})`; if (containerRef.current) { containerRef.current.style.background = gradient; } animationFrame = requestAnimationFrame(animateGradient); }; animationFrame = requestAnimationFrame(animateGradient); return () => cancelAnimationFrame(animationFrame); }, [startingGap, Breathing, gradientColors, gradientStops, animationSpeed, breathingRange, topOffset]); return (
{/* Multi-frequency breathing radial core */}
{/* Floating Animated Color Orbs */}
); }; export default AnimatedGradientBackground;