-
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.
Merge branch '1.x' into invalidate-404-pages
- Loading branch information
Showing
14 changed files
with
3,672 additions
and
17,692 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
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
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
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
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
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,56 @@ | ||
import {ElementType, HtmlHTMLAttributes} from "react" | ||
import {ParagraphStanfordFaq} from "@/lib/gql/__generated__/drupal.d" | ||
import {twMerge} from "tailwind-merge" | ||
import formatHtml from "@/lib/format-html" | ||
import Accordion, {AccordionHeaderChoice} from "@/components/patterns/elements/accordion" | ||
import ExpandCollapseAll from "@/components/patterns/elements/expand-collapse-all" | ||
import {getParagraphBehaviors} from "." | ||
|
||
type Props = HtmlHTMLAttributes<HTMLDivElement> & { | ||
paragraph: ParagraphStanfordFaq | ||
} | ||
|
||
const StanfordAccordionParagraph = ({paragraph, ...props}: Props) => { | ||
const behaviors = getParagraphBehaviors(paragraph) | ||
const Heading: ElementType = behaviors.faq_accordions?.heading || "h2" | ||
|
||
const heading = paragraph.suFaqHeadline | ||
|
||
let accordionHeadingLevel: AccordionHeaderChoice = "h2" | ||
if (heading) { | ||
if (Heading === "h2") accordionHeadingLevel = "h3" | ||
if (Heading === "h3") accordionHeadingLevel = "h4" | ||
if (Heading === "h4") accordionHeadingLevel = "h5" | ||
} | ||
|
||
return ( | ||
<div {...props} className={twMerge("cc space-y-20", props.className)}> | ||
<div className="flex flex-col items-center justify-between gap-20 md:flex-row"> | ||
{paragraph.suFaqHeadline && ( | ||
<Heading id={paragraph.id} className="text-center"> | ||
{paragraph.suFaqHeadline} | ||
</Heading> | ||
)} | ||
<ExpandCollapseAll className="ml-auto" /> | ||
</div> | ||
|
||
{paragraph.suFaqDescription && ( | ||
<div className="wysiwyg centered relative mb-20">{formatHtml(paragraph.suFaqDescription.processed)}</div> | ||
)} | ||
|
||
{paragraph.suFaqQuestions?.map(question => ( | ||
<Accordion | ||
className="border-t border-black-40 last:border-b" | ||
buttonProps={{className: "mt-15"}} | ||
key={question.id} | ||
button={question.suAccordionTitle} | ||
headingLevel={accordionHeadingLevel} | ||
> | ||
<div className="wysiwyg centered relative">{formatHtml(question.suAccordionBody.processed)}</div> | ||
</Accordion> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
export default StanfordAccordionParagraph |
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,98 @@ | ||
"use client" | ||
|
||
import {HTMLAttributes, JSX, useId} from "react" | ||
import {useBoolean} from "usehooks-ts" | ||
import {ChevronDownIcon} from "@heroicons/react/20/solid" | ||
import {clsx} from "clsx" | ||
import {twMerge} from "tailwind-merge" | ||
|
||
export type AccordionHeaderChoice = "h2" | "h3" | "h4" | "h5" | ||
|
||
type Props = HTMLAttributes<HTMLElement> & { | ||
/** | ||
* Button clickable element or string. | ||
*/ | ||
button: JSX.Element | string | ||
/** | ||
* Heading level element. | ||
*/ | ||
headingLevel?: AccordionHeaderChoice | ||
/** | ||
* If the accordion should be visible on first render. | ||
*/ | ||
initiallyVisible?: boolean | ||
/** | ||
* Button click event if the component is controlled. | ||
*/ | ||
onClick?: () => void | ||
/** | ||
* Panel visibility state if the component is controlled. | ||
*/ | ||
isVisible?: boolean | ||
/** | ||
* Extra attributes on the button element. | ||
*/ | ||
buttonProps?: HTMLAttributes<HTMLButtonElement> | ||
/** | ||
* Extra attributes on the panel element. | ||
*/ | ||
panelProps?: HTMLAttributes<HTMLDivElement> | ||
} | ||
|
||
const Accordion = ({ | ||
button, | ||
children, | ||
headingLevel = "h2", | ||
onClick, | ||
isVisible, | ||
initiallyVisible = false, | ||
buttonProps, | ||
panelProps, | ||
...props | ||
}: Props) => { | ||
const {value: expanded, toggle: toggleExpanded} = useBoolean(initiallyVisible) | ||
const id = useId() | ||
|
||
const onButtonClick = () => { | ||
if (onClick) { | ||
onClick() | ||
} else { | ||
toggleExpanded() | ||
} | ||
} | ||
|
||
// When the accordion is externally controlled. | ||
const isExpanded = onClick ? isVisible : expanded | ||
const Heading = headingLevel ? headingLevel : "h2" | ||
|
||
return ( | ||
<section aria-labelledby={`${id}-button`} {...props}> | ||
<Heading id={`${id}-button`}> | ||
<button | ||
{...buttonProps} | ||
className={twMerge("flex w-full items-center text-left hocus-visible:underline", buttonProps?.className)} | ||
aria-expanded={isExpanded} | ||
aria-controls={`${id}-panel`} | ||
onClick={onButtonClick} | ||
> | ||
{button} | ||
<ChevronDownIcon | ||
height={30} | ||
className={twMerge("ml-auto shrink-0 duration-150", clsx({"rotate-180": isExpanded}))} | ||
/> | ||
</button> | ||
</Heading> | ||
|
||
<div | ||
{...panelProps} | ||
id={`${id}-panel`} | ||
className={twMerge(isExpanded ? "mb-20 block" : "hidden", panelProps?.className)} | ||
role="region" | ||
aria-labelledby={`${id}-button`} | ||
> | ||
{children} | ||
</div> | ||
</section> | ||
) | ||
} | ||
export default Accordion |
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,44 @@ | ||
"use client" | ||
|
||
import {useBoolean} from "usehooks-ts" | ||
import {HTMLAttributes, useEffect, useRef} from "react" | ||
import {MinusIcon, PlusIcon} from "@heroicons/react/16/solid" | ||
import {twMerge} from "tailwind-merge" | ||
|
||
type Props = HTMLAttributes<HTMLButtonElement> | ||
|
||
const ExpandCollapseAll = ({...props}: Props) => { | ||
const {value: expand, toggle} = useBoolean(true) | ||
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 ( | ||
<button | ||
ref={ref} | ||
onClick={toggle} | ||
{...props} | ||
className={twMerge( | ||
"cta-button group rs-mt-neg1 flex w-fit items-center gap-5 whitespace-nowrap rounded-full border-2 border-digital-red px-26 pb-11 pt-10 text-16 font-semibold leading-display text-digital-red no-underline transition-colors hocus:bg-cardinal-red hocus:text-white hocus:underline md:text-18", | ||
props.className | ||
)} | ||
> | ||
{expand ? "Expand All" : "Collapse All"} | ||
{expand && <PlusIcon width={20} />} | ||
{!expand && <MinusIcon width={20} />} | ||
</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
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
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
Oops, something went wrong.