Skip to content

Commit

Permalink
fix: svg animation on system theme
Browse files Browse the repository at this point in the history
  • Loading branch information
envil a.k.a pow committed Feb 19, 2024
1 parent 378d887 commit c5d57c0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions components/landing-svg/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { useTheme } from "next-themes";
import { SVGProps, useEffect } from "react";

const LandingSvg = (props: SVGProps<SVGSVGElement>) => {
const { theme } = useTheme();
const { theme, systemTheme } = useTheme();
const currentTheme = theme === "system" ? systemTheme : theme;

useEffect(() => {
const paths = document.querySelectorAll<SVGPathElement>("#landing-svg path");
Expand All @@ -16,13 +17,13 @@ const LandingSvg = (props: SVGProps<SVGSVGElement>) => {
const delay = Math.random() * 50000;

setTimeout(() => {
path.style.animation = `landing-svg-anim-${theme} 5s ease-in-out infinite`;
path.style.animation = `landing-svg-anim-${currentTheme} 5s ease-in-out infinite`;
path.style.strokeDashoffset = length;
}, delay);
}

paths.forEach((path) => animatePath(path));
}, [theme]);
}, [currentTheme]);

return (
<svg viewBox="0 0 750 750" fill="none" xmlns="http://www.w3.org/2000/svg" {...props}>
Expand Down

0 comments on commit c5d57c0

Please sign in to comment.