-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor toggle text so it can be used outside of Storyblok (eg. in m…
…ethodology page) (#86)
- Loading branch information
Showing
9 changed files
with
90 additions
and
60 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"use client"; | ||
// ToggleText needs to be a client component - it's interactive | ||
|
||
import { useState } from "react"; | ||
import { Col, Collapse, Container, Row } from "react-bootstrap"; | ||
import { FaCircleChevronRight } from "react-icons/fa6"; | ||
|
||
const ToggleText = ({ | ||
id, | ||
title, | ||
content, | ||
textShownInitially = false, | ||
chevronSize = "fs-2", | ||
}: { | ||
id: string; | ||
title: React.ReactNode; | ||
content: React.ReactNode; | ||
textShownInitially?: boolean; | ||
chevronSize?: string; | ||
}) => { | ||
const [visible, setVisible] = useState(textShownInitially); | ||
|
||
return ( | ||
<Container className="my-4"> | ||
<Row> | ||
<Col xs="auto" className="g-0"> | ||
<FaCircleChevronRight | ||
onClick={() => setVisible(!visible)} | ||
aria-controls={`collapse-${id}`} | ||
aria-expanded={visible} | ||
className={chevronSize} | ||
style={{ | ||
transition: "transform 0.3s ease 0s", | ||
transform: `rotate(${visible ? 90 : 0}deg)`, | ||
cursor: "pointer", | ||
}} | ||
/> | ||
</Col> | ||
<Col> | ||
<Row | ||
onClick={() => setVisible(!visible)} | ||
aria-controls={`collapse-${id}`} | ||
aria-expanded={visible} | ||
style={{ cursor: "pointer" }} | ||
> | ||
{title} | ||
</Row> | ||
<Row> | ||
<Collapse in={visible}> | ||
<div id={`collapse-${id}`}>{content}</div> | ||
</Collapse> | ||
</Row> | ||
</Col> | ||
</Row> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default ToggleText; |
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
components/storybloks/page_content/StoryblokToggleText.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use client"; | ||
// ToggleText needs to be a client component - it's interactive | ||
|
||
import { ToggleTextStoryblok } from "@/storyblok/types/storyblok-types"; | ||
import { storyblokEditable } from "@storyblok/react/rsc"; | ||
import { render } from "storyblok-rich-text-react-renderer"; | ||
import ToggleText from "@/components/ToggleText"; | ||
|
||
const StoryblokToggleText = ({ blok }: { blok: ToggleTextStoryblok }) => { | ||
return ( | ||
<div {...storyblokEditable(blok)} className="my-4"> | ||
<ToggleText | ||
id={blok._uid} | ||
title={<h2>{blok.title}</h2>} | ||
content={render(blok.text)} | ||
textShownInitially={blok.text_shown_initially} | ||
chevronSize="fs-2" | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default StoryblokToggleText; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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