import React, { ReactNode, ComponentType } from "react"; import styles from "./OrganizedContent.module.css"; export interface LinkProps { className?: string; url: string; children: string | ReactNode | (string | ReactNode)[]; } type Link = ComponentType; interface Heading { title: 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 = ({ headings, currentIndex, link: Link, children, }: Props) => { const isReadAll = headings[currentIndex].title === "Read All"; const readAllContent = headings .filter((heading: { title: string }) => heading.title !== "Read All") .map((heading) => (

{heading.title}

{heading.content}
)); const childProps: ChildProps = { headings: headings, currentIndex: currentIndex, link: Link, }; return (
); }; const Nav = ({ headings, currentIndex, link: Link }: ChildProps) => { return (
{headings.map((heading, index) => (
{index === currentIndex && ( )} {heading.title}
))}
); }; const Footer = ({ headings, currentIndex, link: Link }: ChildProps) => { const prevHeading = currentIndex > 0 && headings[currentIndex - 1].title !== "Read All" ? headings[currentIndex - 1] : undefined; const nextHeading = currentIndex < headings.length - 1 && headings[currentIndex + 1].title !== "Read All" ? headings[currentIndex + 1] : undefined; return (
{prevHeading && (
Previous
{prevHeading.title}
)}
{nextHeading && (
Next
{nextHeading.title}
)}
); };