diff --git a/frontend/src/components/Preview.tsx b/frontend/src/components/Preview.tsx index d2eff16..59f290d 100644 --- a/frontend/src/components/Preview.tsx +++ b/frontend/src/components/Preview.tsx @@ -1,5 +1,6 @@ -import { useEffect, useRef } from "react"; +import { useEffect, useRef, useState } from "react"; import classNames from "classnames"; +import { FaSearch } from "react-icons/fa"; // import useThrottle from "../hooks/useThrottle"; interface Props { @@ -12,6 +13,7 @@ function Preview({ code, device }: Props) { // Temporary disable throttling for the preview not updating when the code changes // useThrottle(code, 200); const iframeRef = useRef(null); + const [backgroundColor, setBackgroundColor] = useState(null); useEffect(() => { const iframe = iframeRef.current; @@ -19,24 +21,64 @@ function Preview({ code, device }: Props) { iframe.contentDocument.open(); iframe.contentDocument.write(throttledCode); iframe.contentDocument.close(); + + setTimeout(() => { + const body = iframe.contentDocument!.body; + if (body) { + const bgColor = window.getComputedStyle(body).backgroundColor; + setBackgroundColor(bgColor); + } + }, 5); } }, [throttledCode]); return (
- + style={{ backgroundColor: `${backgroundColor}` }} + > + {device === "mobile" ? ( +
+ ) : ( +
+
+
+ + + +
+
+
+ + +
+
+ )} + +
); }