177 lines
5.0 KiB
TypeScript
177 lines
5.0 KiB
TypeScript
import React, { ReactNode, ComponentType } from "react";
|
|
import styles from "./OrganizedContent.module.css";
|
|
|
|
export interface LinkProps {
|
|
children: string | ReactNode | (string | ReactNode)[];
|
|
url: string;
|
|
}
|
|
|
|
type Link = ComponentType<LinkProps>;
|
|
|
|
interface Heading {
|
|
name: string;
|
|
url: string;
|
|
content: ReactNode;
|
|
}
|
|
|
|
interface Props {
|
|
headings: Heading[];
|
|
currentIndex: number;
|
|
link: Link;
|
|
children: ReactNode;
|
|
}
|
|
|
|
interface ChildProps {
|
|
headings: Heading[];
|
|
currentIndex: number;
|
|
link: Link;
|
|
}
|
|
|
|
export const OrganizedContent: React.FC<Props> = ({
|
|
headings,
|
|
currentIndex,
|
|
children,
|
|
link: Link,
|
|
}) => {
|
|
const isReadAll = headings[currentIndex].name === "Read All";
|
|
const isMobile = false;
|
|
const readAllContent = headings
|
|
.filter((heading: { name: string }) => heading.name !== "Read All")
|
|
.map((heading) => (
|
|
<div key={heading.url}>
|
|
<h2 className={styles.contentHeading}>{heading.name}</h2>
|
|
{heading.content}
|
|
</div>
|
|
));
|
|
|
|
if (isMobile) {
|
|
return (
|
|
<div>
|
|
{isReadAll ? (
|
|
<div>{readAllContent}</div>
|
|
) : (
|
|
<h2 className={styles.contentHeading}>
|
|
{headings[currentIndex].name}
|
|
</h2>
|
|
)}
|
|
{children}
|
|
<Footer headings={headings} currentIndex={currentIndex} link={Link} />
|
|
</div>
|
|
);
|
|
} else {
|
|
return (
|
|
<div className={styles.organizedContent}>
|
|
<Nav headings={headings} currentIndex={currentIndex} link={Link} />
|
|
<div>
|
|
{isReadAll ? (
|
|
<div>{readAllContent}</div>
|
|
) : (
|
|
<h2 className={styles.contentHeading}>
|
|
{headings[currentIndex].name}
|
|
</h2>
|
|
)}
|
|
{children}
|
|
<Footer headings={headings} currentIndex={currentIndex} link={Link} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
};
|
|
|
|
const Nav: React.FC<ChildProps> = ({ headings, currentIndex, link: Link }) => {
|
|
return (
|
|
<div className={styles.nav}>
|
|
{headings.map((heading, index) => (
|
|
<div
|
|
className={index === currentIndex ? styles.selectedHeadingArea : ""}
|
|
key={heading.url}
|
|
>
|
|
<div
|
|
className={
|
|
styles.navOption +
|
|
" " +
|
|
(index === currentIndex
|
|
? styles.selectedHeading
|
|
: heading.name === "Read All"
|
|
? styles.readAll
|
|
: "")
|
|
}
|
|
>
|
|
{index === currentIndex && (
|
|
<span className={styles.selectedMarker} />
|
|
)}
|
|
<Link url={heading.url}>{heading.name}</Link>
|
|
</div>
|
|
<div className={styles.divider}></div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const Footer: React.FC<ChildProps> = ({
|
|
headings,
|
|
currentIndex,
|
|
link: Link,
|
|
}) => {
|
|
const isReadAll = headings[currentIndex].name === "Read All";
|
|
const prevHeading =
|
|
currentIndex > 0 && headings[currentIndex - 1].name !== "Read All"
|
|
? headings[currentIndex - 1]
|
|
: undefined;
|
|
const nextHeading =
|
|
currentIndex < headings.length - 1 && !isReadAll
|
|
? headings[currentIndex + 1]
|
|
: undefined;
|
|
|
|
return (
|
|
<div className={styles.footer}>
|
|
{prevHeading && (
|
|
<div className={styles.clickable}>
|
|
<Link url={prevHeading.url}>
|
|
<div className={styles.footerSection}>
|
|
<svg
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
width="14"
|
|
height="9"
|
|
viewBox="0 0 14 9"
|
|
className={styles.arrow + " " + styles.prevArrow}
|
|
>
|
|
<path d="M6.24407 8.12713C6.64284 8.58759 7.35716 8.58759 7.75593 8.12713L13.3613 1.65465C13.9221 1.00701 13.4621 0 12.6053 0H1.39467C0.537918 0 0.0778675 1.00701 0.638743 1.65465L6.24407 8.12713Z" />
|
|
</svg>
|
|
<div>
|
|
<div className={styles.prevNext}>Previous</div>
|
|
<div className={styles.arrowHeading}>{prevHeading.name}</div>
|
|
</div>
|
|
</div>
|
|
</Link>
|
|
</div>
|
|
)}
|
|
<div></div>
|
|
{nextHeading && (
|
|
<div className={styles.clickable}>
|
|
<Link url={nextHeading.url}>
|
|
<div className={styles.footerSection}>
|
|
<div>
|
|
<div className={styles.prevNext + " " + styles.nextText}>
|
|
Next
|
|
</div>
|
|
<div className={styles.arrowHeading}>{nextHeading.name}</div>
|
|
</div>
|
|
<svg
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
width="14"
|
|
height="9"
|
|
viewBox="0 0 14 9"
|
|
className={styles.arrow + " " + styles.nextArrow}
|
|
>
|
|
<path d="M6.24407 8.12713C6.64284 8.58759 7.35716 8.58759 7.75593 8.12713L13.3613 1.65465C13.9221 1.00701 13.4621 0 12.6053 0H1.39467C0.537918 0 0.0778675 1.00701 0.638743 1.65465L6.24407 8.12713Z" />
|
|
</svg>
|
|
</div>
|
|
</Link>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|