-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
628 additions
and
32 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
34 changes: 34 additions & 0 deletions
34
src/components/paragraphs/stanford-faq/expand-collapse-all.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,34 @@ | ||
"use client" | ||
|
||
import Button from "@components/elements/button" | ||
import {useBoolean} from "usehooks-ts" | ||
import {HTMLAttributes, useEffect, useRef} from "react" | ||
|
||
type Props = HTMLAttributes<HTMLButtonElement> | ||
|
||
const ExpandCollapseAll = ({...props}: Props) => { | ||
const {value: expand, toggle} = useBoolean(false) | ||
const ref = useRef<HTMLButtonElement>(null) | ||
|
||
useEffect(() => { | ||
const buttons = ref.current?.parentElement?.parentElement?.getElementsByTagName("button") || [] | ||
for (let i = 0; i < buttons.length; i++) { | ||
if (!expand && buttons[i].getAttribute("aria-expanded") === "false") { | ||
buttons[i].click() | ||
} | ||
|
||
if (expand && buttons[i].getAttribute("aria-expanded") === "true") { | ||
buttons[i].click() | ||
} | ||
} | ||
}, [expand]) | ||
|
||
return ( | ||
// @ts-expect-error ref object type issue. | ||
<Button ref={ref} buttonElem onClick={toggle} {...props}> | ||
{expand ? "Expand All" : "Collapse All"} | ||
</Button> | ||
) | ||
} | ||
|
||
export default ExpandCollapseAll |
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,40 @@ | ||
import {HtmlHTMLAttributes} from "react" | ||
import {ParagraphStanfordFaq} from "@lib/gql/__generated__/drupal.d" | ||
import {H2} from "@components/elements/headers" | ||
import Wysiwyg from "@components/elements/wysiwyg" | ||
import Accordion from "@components/elements/accordion" | ||
import twMerge from "@lib/utils/twMergeConfig" | ||
import ExpandCollapseAll from "@components/paragraphs/stanford-faq/expand-collapse-all" | ||
|
||
type Props = HtmlHTMLAttributes<HTMLDivElement> & { | ||
paragraph: ParagraphStanfordFaq | ||
} | ||
|
||
const FaqParagraph = ({paragraph, ...props}: Props) => { | ||
return ( | ||
<div {...props} className={twMerge("mx-auto max-w-1200 space-y-20", props.className)}> | ||
<div className="flex items-center justify-between gap-20"> | ||
{paragraph.suFaqHeadline && <H2>{paragraph.suFaqHeadline}</H2>} | ||
|
||
<ExpandCollapseAll className="ml-auto" /> | ||
</div> | ||
<Wysiwyg html={paragraph.suFaqDescription?.processed} /> | ||
|
||
<div> | ||
{paragraph.suFaqQuestions?.map(question => ( | ||
<Accordion | ||
className="border-t border-black-40 last:border-b" | ||
buttonProps={{className: "mt-6"}} | ||
key={question.id} | ||
button={question.suAccordionTitle} | ||
headingLevel={paragraph.suFaqHeadline ? "h3" : "h2"} | ||
> | ||
<Wysiwyg html={question.suAccordionBody.processed} /> | ||
</Accordion> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default FaqParagraph |
Oops, something went wrong.