forked from mrwyndham/fastpocket
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
"use client";
|
|
|
|
import colors, { hexToRgb } from "@/utils/colors";
|
|
import { useTheme } from "next-themes";
|
|
import React, { ReactNode, useEffect, useMemo, useState } from "react";
|
|
|
|
const Background = ({ children }: { children: ReactNode }) => {
|
|
const { theme } = useTheme();
|
|
const [mounted, setMounted] = useState(false);
|
|
|
|
// useEffect only runs on the client, so now we can safely show the UI
|
|
useEffect(() => {
|
|
setMounted(true);
|
|
}, []);
|
|
|
|
if (!mounted) {
|
|
return (
|
|
<div className="h-full relative w-full bg-center bg-no-repeat bg-cover bg-fixed min-h-screen flex flex-col animation-pulse"></div>
|
|
);
|
|
}
|
|
|
|
console.log("theme", theme);
|
|
const backgroundColor = hexToRgb(colors[theme!]["base-100"]);
|
|
|
|
return (
|
|
<div
|
|
className="h-full relative w-full bg-center bg-no-repeat bg-cover bg-fixed min-h-screen flex flex-col"
|
|
style={{
|
|
backgroundImage: `linear-gradient(rgba(${backgroundColor?.r}, ${backgroundColor?.g}, ${backgroundColor?.b}, 0.7), rgba(135, 80, 156, 0.05)), url(/images/hero.jpg)`,
|
|
}}
|
|
>
|
|
{children}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Background;
|