diff --git a/components/OrganizedContent.module.css b/components/OrganizedContent.module.css new file mode 100644 index 00000000..dcc336a0 --- /dev/null +++ b/components/OrganizedContent.module.css @@ -0,0 +1,6 @@ +.organizedcontent { + background-color: rgb(78, 212, 178, 0.2); + color: var(--purple-2); + display:flex; + flex-direction:row; +} \ No newline at end of file diff --git a/components/OrganizedContent.tsx b/components/OrganizedContent.tsx new file mode 100644 index 00000000..c3c6ad05 --- /dev/null +++ b/components/OrganizedContent.tsx @@ -0,0 +1,62 @@ +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 + + +interface Heading { + name: string; + url: string; +} + +interface Props { + headings: Heading[]; + currentIndex: number; + link: Link + children: ReactNode; +} + +export const OrganizedContent: React.FC = ({ + headings, + currentIndex, + children, + link: Link, +}) => { + const prevHeading = currentIndex > 0 ? headings[currentIndex - 1] : undefined; + const nextHeading = + currentIndex < headings.length - 1 ? headings[currentIndex + 1] : undefined; + + return ( +
+
+ {headings.map((heading, index) => ( +

+ {heading.name} +

+ ))} +
+ +
+

{headings[currentIndex].name}

+ {children} + {prevHeading && ( + + Previous + {prevHeading.name} + + )} + {nextHeading && ( + + Next + {nextHeading.name} + + )} +
+
+ ); +}; diff --git a/components/playground.tsx b/components/playground.tsx index bbb85e0e..6efb17d1 100644 --- a/components/playground.tsx +++ b/components/playground.tsx @@ -1,5 +1,4 @@ -import React from "react"; - +import React, { useState } from "react"; import styles from "./playground.module.css"; import AfterHoursContent, { @@ -7,6 +6,7 @@ import AfterHoursContent, { } from "../content/playground/after-hours.event.mdx"; import { MiniEventCard } from "./MiniEventCard"; +import { OrganizedContent, LinkProps } from "./OrganizedContent"; export function MiniEventCardDemo() { const { name, location, short, date } = afterHoursMetadata; @@ -48,5 +48,59 @@ export function MiniEventCardDemo() { description={} /> + ) +} + +export function OrganizedContentDemo() { + let sections = [ + { + name: "Heading1", + url: "a", + content:
Hello World! 1
, + }, + { + name: "Heading2", + url: "b", + content:
Hello World! 2
, + }, + { + name: "Heading3", + url: "c", + content:
Hello World! 3
, + }, + ]; + + const readAllSection = { + name: "Read all", + url: "readall", + content: <>{sections.map((section => section.content))} + } + + sections = [readAllSection, ...sections]; + + const [index, setIndex] = useState(0); + + function FakeLink({ url, children }: LinkProps) { + return ( +
{ + const target = sections.findIndex((section) => section.url === url); + + if (target >= 0) { + setIndex(target); + } + }} + > + {children} +
+ ); + } + + const { content } = sections[index]; + + return ( + + {content} + ); } diff --git a/pages/playground.mdx b/pages/playground.mdx index 87d8a405..b11c1775 100644 --- a/pages/playground.mdx +++ b/pages/playground.mdx @@ -1,4 +1,4 @@ -import {MiniEventCardDemo} from '../components/playground' +import { MiniEventCardDemo, OrganizedContentDemo } from '../components/playground' # Playground @@ -7,4 +7,10 @@ import {MiniEventCardDemo} from '../components/playground' The `` component has a collapsible description, and it used on the events page. It uses the `
` tag and works without JS! - \ No newline at end of file + + +## `` + +Works without JS! + + \ No newline at end of file