Created
May 18, 2020 17:33
-
-
Save singh-shweta/813b9577c9a1f27f947c0c10451599b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Suspense, useState } from "react"; | |
import { | |
Card, | |
Button, | |
CardTitle, | |
CardText, | |
CardSubtitle, | |
CardBody, | |
Row, | |
Col, | |
UncontrolledCollapse, | |
} from "reactstrap"; | |
import { useInView } from "react-intersection-observer"; | |
import CardContentLoader from "./CardContentLoader"; | |
/** Used lazy load to load this module when renders */ | |
const SampleChart = React.lazy(() => import("./chart")); | |
const CardWithGraph = (props) => { | |
const { title, Subtitle, id } = props.data; | |
const [showGraph, setshowGraph] = useState(false); | |
return ( | |
<div key={`card-${id}-div`}> | |
<Card className="mt-3"> | |
<CardBody> | |
<CardTitle> | |
{title} | |
<Button | |
color="primary" | |
id={`toggler-${id}`} | |
style={{ marginBottom: "1rem" }} | |
onClick={() => setshowGraph(true)} | |
> | |
Toggle | |
</Button> | |
</CardTitle> | |
<UncontrolledCollapse toggler={`toggler-${id}`}> | |
<CardSubtitle>{Subtitle}</CardSubtitle> | |
<Row> | |
<Col sm={8} className="mx-auto"> | |
{showGraph && ( | |
<Suspense fallback={<div>Loading charts...</div>}> | |
<SampleChart id={id} /> | |
</Suspense> | |
)} | |
</Col> | |
</Row> | |
<CardText>Testing performance of chart 1</CardText> | |
</UncontrolledCollapse> | |
</CardBody> | |
</Card> | |
</div> | |
); | |
}; | |
export default CardWithGraph; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment