diff --git a/apps/charterafrica/src/components/EmbeddedChart/EmbeddedChart.js b/apps/charterafrica/src/components/EmbeddedChart/EmbeddedChart.js deleted file mode 100644 index 91b392030..000000000 --- a/apps/charterafrica/src/components/EmbeddedChart/EmbeddedChart.js +++ /dev/null @@ -1,38 +0,0 @@ -import { RichTypography, Section } from "@commons-ui/core"; -import { Box } from "@mui/material"; -import React from "react"; - -const EmbeddedChart = React.forwardRef(function EmbeddedChart(props, ref) { - const { backgroundColor, html, subtitle, title, width } = props; - - return ( - -
- - {title} - - - {subtitle} - - {html} -
-
- ); -}); - -export default EmbeddedChart; diff --git a/apps/charterafrica/src/components/EmbeddedChart/index.js b/apps/charterafrica/src/components/EmbeddedChart/index.js deleted file mode 100644 index f99e65e36..000000000 --- a/apps/charterafrica/src/components/EmbeddedChart/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import EmbeddedChart from "./EmbeddedChart"; - -export default EmbeddedChart; diff --git a/apps/charterafrica/src/components/FlourishChart/FlourishChart.js b/apps/charterafrica/src/components/FlourishChart/FlourishChart.js new file mode 100644 index 000000000..e314266b5 --- /dev/null +++ b/apps/charterafrica/src/components/FlourishChart/FlourishChart.js @@ -0,0 +1,61 @@ +/* eslint-env browser */ +import { RichTypography, Section } from "@commons-ui/core"; +import { Box } from "@mui/material"; +import React, { useEffect, useState } from "react"; + +const FlourishChart = React.forwardRef(function FlourishChart(props, ref) { + const { backgroundColor, chartId, subtitle, title } = props; + const [height, setHeight] = useState(0); + + useEffect(() => { + const handleMessageEvent = (event) => { + const { sender, context, ...message } = JSON.parse(event.data) || {}; + if (sender === "Flourish" && context === "iframe.resize") { + setHeight(Math.ceil(message.height)); + } + }; + window.addEventListener("message", handleMessageEvent); + return () => { + document.removeEventListener("message", handleMessageEvent); + }; + }); + + if (!chartId?.length) { + return null; + } + return ( + +
+ + {title} + + + {subtitle} + +