File size: 1,277 Bytes
e73ce34 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import { PAGE_GRADIENTS } from "../../config/gradients";
import type { GradientPageKey } from "../../config/gradients";
import { useAppContext } from "../../context/AppContext";
import { useMediaQuery } from "../../hooks/useMediaQuery";
interface GradientMeshProps {
/** The page key determining which gradient palette to use. */
page: GradientPageKey;
}
/**
* Reusable gradient mesh background component.
*
* Renders an absolutely-positioned div with the per-page gradient mesh
* background. Uses the app's dark mode context and a media query to
* select the appropriate gradient variant (light/dark, desktop/mobile).
*
* Place this as a child of a relatively-positioned container.
*/
export function GradientMesh({ page }: GradientMeshProps) {
const { isDarkMode } = useAppContext();
const isMobile = useMediaQuery("(max-width: 767px)");
const gradients = PAGE_GRADIENTS[page];
let background: string;
if (isMobile) {
background = isDarkMode ? gradients.mobileDark : gradients.mobileLight;
} else {
background = isDarkMode ? gradients.dark : gradients.light;
}
return (
<div className="absolute inset-0 -z-20 overflow-hidden" aria-hidden="true">
<div className="absolute inset-0" style={{ background }} />
</div>
);
}
|