I am trying to open multiple Accordion if possible. Currently using react-bootstrap library.
Following is my implementation :
<Accordion>
{data.rows.map((item, index) => {
return (
<Card
style={{
border: "none",
marginTop: "1em",
borderBottom: "1px solid #f1f1f1",
}}
>
<Card.Header
style={{ background: "transparent", padding: "0.75em 0" }}
>
<Row>
<Col lg="10" sm xs="9" style={{ alignSelf: "center" }}>
<p
className="cardtitle"
style={{ fontWeight: "600" }}
>
{item.title}
</p>
</Col>
<Col style={{ textAlign: "right" }} xs sm>
{" "}
<ContextAwareToggle eventKey={index}>
+
</ContextAwareToggle>
</Col>
</Row>
</Card.Header>
<Accordion.Collapse eventKey={index}>
<Card.Body>
<p className="cardcontent">{item.content}</p>
</Card.Body>
</Accordion.Collapse>
</Card>
);
})}{" "}
</Accordion>
...
function ContextAwareToggle({ children, eventKey, callback }) {
const currentEventKey = useContext(Fifth);
const decoratedOnClick = useAccordionToggle(
eventKey,
() => callback && callback(eventKey)
);
const isCurrentEventKey = currentEventKey === eventKey;
console.log(currentEventKey);
return (
<button
type="button"
className="accordianButton"
// style={{ backgroundColor: isCurrentEventKey ? "pink" : "lavender" }}
style={{
backgroundColor: "transparent",
fontSize: "1.8em",
fonWeight: "700",
border: "transparent",
color: "green",
}}
onClick={decoratedOnClick}
>
{isCurrentEventKey ? "-" : "+"}
</button>
);
}
Following is the link where I got my reference of code: https://react-bootstrap.github.io/components/accordion/
Also, if not accordion then please suggest any other component. Been trying to create a FAQ template in my project.
Thanks