From 092dc7fc49246580023a8b97101d51845c81bf04 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Fri, 31 Mar 2023 11:17:55 +0700
Subject: iframe content

---
 src/lib/iframe/components/IframeContent.jsx | 30 +++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 src/lib/iframe/components/IframeContent.jsx

(limited to 'src/lib/iframe/components/IframeContent.jsx')

diff --git a/src/lib/iframe/components/IframeContent.jsx b/src/lib/iframe/components/IframeContent.jsx
new file mode 100644
index 00000000..52f2a26e
--- /dev/null
+++ b/src/lib/iframe/components/IframeContent.jsx
@@ -0,0 +1,30 @@
+import { useEffect, useRef, useState } from 'react'
+
+const IframeContent = ({ url }) => {
+  const [iframeLoaded, setIframeLoaded] = useState(false)
+  const [iframe, setIframe] = useState(null)
+  const iframeRef = useRef(null)
+
+  useEffect(() => {
+    if (iframeLoaded) {
+      setIframe({
+        height: document.querySelector('main').offsetHeight
+      })
+    }
+  }, [iframeLoaded])
+
+  return (
+    <div className='mx-auto container h-full'>
+      <iframe
+        ref={iframeRef}
+        src={url}
+        width='100%'
+        seamless
+        style={{ height: iframe?.height || 0 }}
+        onLoad={() => setIframeLoaded(true)}
+      />
+    </div>
+  )
+}
+
+export default IframeContent
-- 
cgit v1.2.3

