"use client"; import React, { useEffect, useState } from "react"; import { cn } from "../../lib/utils"; // Grid Background Component export interface GridBackgroundProps extends React.HTMLProps { gridSize?: number; gridColor?: string; darkGridColor?: string; showFade?: boolean; fadeIntensity?: number; children?: React.ReactNode; } export const GridBackground = ({ className, children, gridSize = 20, gridColor = "#e4e4e7", darkGridColor = "#262626", showFade = true, fadeIntensity = 20, ...props }: GridBackgroundProps) => { const [currentGridColor, setCurrentGridColor] = useState(gridColor); useEffect(() => { const prefersDarkMode = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches; const isDarkModeActive = document.documentElement.classList.contains("dark") || prefersDarkMode; setCurrentGridColor(isDarkModeActive ? darkGridColor : gridColor); const observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { if (mutation.attributeName === "class") { const updatedIsDarkModeActive = document.documentElement.classList.contains("dark"); setCurrentGridColor( updatedIsDarkModeActive ? darkGridColor : gridColor ); } }); }); observer.observe(document.documentElement, { attributes: true }); return function () { return observer.disconnect(); }; }, [gridColor, darkGridColor]); return (
{showFade && (
)}
{children}
); }; // Dot Background Component export interface DotBackgroundProps extends React.HTMLProps { dotSize?: number; dotColor?: string; darkDotColor?: string; spacing?: number; showFade?: boolean; fadeIntensity?: number; children?: React.ReactNode; } export const DotBackground = ({ className, children, dotSize = 1, dotColor = "#000", darkDotColor = "#fff", spacing = 20, showFade = true, fadeIntensity = 20, ...props }: DotBackgroundProps) => { const [currentDotColor, setCurrentDotColor] = useState(dotColor); useEffect(() => { const prefersDarkMode = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches; const isDarkModeActive = document.documentElement.classList.contains("dark") || prefersDarkMode; setCurrentDotColor(isDarkModeActive ? darkDotColor : dotColor); const observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { if (mutation.attributeName === "class") { const updatedIsDarkModeActive = document.documentElement.classList.contains("dark"); setCurrentDotColor(updatedIsDarkModeActive ? darkDotColor : dotColor); } }); }); observer.observe(document.documentElement, { attributes: true }); return function () { return observer.disconnect(); }; }, [dotColor, darkDotColor]); return (
{showFade && (
)}
{children}
); }; export default { GridBackground, DotBackground };