diff --git a/src/App.tsx b/src/App.tsx index fc153e2..98e8102 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,3 +1,4 @@ +import { useEffect, useRef } from 'react'; import StickyNav from './components/layout/StickyNav'; import SectionContainer from './components/layout/SectionContainer'; import Footer from './components/layout/Footer'; @@ -11,9 +12,33 @@ const params = new URLSearchParams(window.location.search); const isEmbed = params.has('embed'); const country = params.get('country') || 'us'; +function usePostHeightToParent(rootRef: React.RefObject) { + useEffect(() => { + if (!isEmbed) return; + + const postHeight = () => { + if (rootRef.current) { + window.parent.postMessage( + { type: 'policyengine-model-height', height: rootRef.current.scrollHeight }, + '*', + ); + } + }; + + const observer = new ResizeObserver(postHeight); + if (rootRef.current) observer.observe(rootRef.current); + postHeight(); + + return () => observer.disconnect(); + }, [rootRef]); +} + export default function App() { + const rootRef = useRef(null); + usePostHeightToParent(rootRef); + return ( -
+
{!isEmbed && }