Skip to content

Commit

Permalink
feat: ✨ added gradient color update on color change
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbrusegard committed Jul 28, 2023
1 parent 9397ad2 commit 6977ae9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/components/heroImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import heroDraw from '../../public/photos/hero/draw.png';
import Image from 'next/image';
import webGLFluidSimulation from 'webgl-fluid-simulation';
import { motion, Variants } from 'framer-motion';
import { useEffect } from 'react';

const HeroImage = () => {
const drawVariants = {
Expand Down Expand Up @@ -39,6 +40,25 @@ const HeroImage = () => {
);
};

useEffect(() => {
const updateGradientColors = () => {
const linearGradient = document.getElementById('gradient');
if (linearGradient) {
linearGradient.querySelector('stop[offset="0%"]')?.setAttribute('stopColor', colors.accentColor);
linearGradient.querySelector('stop[offset="100%"]')?.setAttribute('stopColor', colors.primaryColor);
}
};

const handleColorsUpdated = () => {
updateGradientColors();
};

window.addEventListener('colorsUpdated', handleColorsUpdated);
return () => {
window.removeEventListener('colorsUpdated', handleColorsUpdated);
};
}, []);

return (
<div className='relative left-0 h-full w-full overflow-hidden md:left-[100px] md:w-[calc(100%-100px)] xl:left-[200px] xl:w-[calc(100%-200px)] landscape-md:left-[400px] landscape-md:w-[calc(100%-400px)]'>
<motion.svg
Expand Down

0 comments on commit 6977ae9

Please sign in to comment.