feat: add navigation between version 1 and 2
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
margin: 0 auto;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.divider {
|
||||||
|
width: 100%;
|
||||||
|
height: 1px;
|
||||||
|
background-color: #848586;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { DocSection } from '../types/types';
|
||||||
|
import styles from './Main.module.css';
|
||||||
|
import Section from './Section';
|
||||||
|
|
||||||
|
export default function Main({
|
||||||
|
versionSections,
|
||||||
|
}: {
|
||||||
|
versionSections: DocSection[];
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<main className={styles.container}>
|
||||||
|
{versionSections.map(section => (
|
||||||
|
<>
|
||||||
|
<Section key={section.title}>
|
||||||
|
{section.copy}
|
||||||
|
{section.example}
|
||||||
|
</Section>
|
||||||
|
<div className={styles.divider}> </div>
|
||||||
|
</>
|
||||||
|
))}
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,17 +2,26 @@
|
|||||||
|
|
||||||
import Link from 'next/link.js';
|
import Link from 'next/link.js';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
import { DocsStructure } from '../types/types.js';
|
||||||
import styles from './NavBar.module.css';
|
import styles from './NavBar.module.css';
|
||||||
|
|
||||||
function NavbarDropdown() {
|
function NavbarDropdown({ version }: { version: string }) {
|
||||||
const versions = ['Version 1', 'Version 2'];
|
const versions = {
|
||||||
|
version_001: {
|
||||||
|
name: 'Version 1',
|
||||||
|
path: '/version-1',
|
||||||
|
},
|
||||||
|
version_002: {
|
||||||
|
name: 'Version 2',
|
||||||
|
path: '/',
|
||||||
|
},
|
||||||
|
} as { [key: string]: { name: string; path: string } };
|
||||||
|
|
||||||
|
const currentVersion = versions[version];
|
||||||
|
|
||||||
const [isDropdownOpen, setIsDropdownOpen] =
|
const [isDropdownOpen, setIsDropdownOpen] =
|
||||||
useState<boolean>(false);
|
useState<boolean>(false);
|
||||||
|
|
||||||
const [version, setVersion] =
|
|
||||||
useState<string>('Version 2');
|
|
||||||
|
|
||||||
const handleDropdownToggle = () => {
|
const handleDropdownToggle = () => {
|
||||||
setIsDropdownOpen(!isDropdownOpen);
|
setIsDropdownOpen(!isDropdownOpen);
|
||||||
};
|
};
|
||||||
@@ -23,7 +32,7 @@ function NavbarDropdown() {
|
|||||||
className={styles.navLink}
|
className={styles.navLink}
|
||||||
onClick={handleDropdownToggle}
|
onClick={handleDropdownToggle}
|
||||||
>
|
>
|
||||||
{version}{' '}
|
{currentVersion.name}{' '}
|
||||||
{isDropdownOpen ? (
|
{isDropdownOpen ? (
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
@@ -61,31 +70,35 @@ function NavbarDropdown() {
|
|||||||
: styles.dropdownMenu
|
: styles.dropdownMenu
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{versions
|
{Object.keys(versions)
|
||||||
.filter(v => v !== version)
|
.filter(v => v !== version)
|
||||||
.map(v => (
|
.map(v => (
|
||||||
<a
|
<Link
|
||||||
|
href={`${versions[v].path}`}
|
||||||
key={v}
|
key={v}
|
||||||
className={styles.navLink}
|
className={styles.navLink}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setVersion(v);
|
|
||||||
setIsDropdownOpen(false);
|
setIsDropdownOpen(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{v}
|
{versions[v].name}
|
||||||
</a>
|
</Link>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function NavBar() {
|
export default function NavBar({
|
||||||
|
version,
|
||||||
|
}: {
|
||||||
|
version: DocsStructure;
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<nav className={styles.nav}>
|
<nav className={styles.nav}>
|
||||||
<ul className={styles.navList}>
|
<ul className={styles.navList}>
|
||||||
<li className={styles.navItem}>
|
<li className={styles.navItem}>
|
||||||
<NavbarDropdown />
|
<NavbarDropdown version={version.version} />
|
||||||
</li>
|
</li>
|
||||||
<li className={styles.navItem}>
|
<li className={styles.navItem}>
|
||||||
<Link
|
<Link
|
||||||
|
|||||||
@@ -76,11 +76,9 @@ function ListTree({ docs }: { docs: Doc[] }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function SideBar({
|
export default function SideBar({
|
||||||
versionOne,
|
version,
|
||||||
versionTwo,
|
|
||||||
}: {
|
}: {
|
||||||
versionOne: DocsStructure;
|
version: DocsStructure;
|
||||||
versionTwo: DocsStructure;
|
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
@@ -88,7 +86,7 @@ export default function SideBar({
|
|||||||
<span className={styles.onspring}>Onspring</span>{' '}
|
<span className={styles.onspring}>Onspring</span>{' '}
|
||||||
<span className={styles.api}>API</span>
|
<span className={styles.api}>API</span>
|
||||||
</h1>
|
</h1>
|
||||||
<ListTree docs={versionTwo.docs} />
|
<ListTree docs={version.docs} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-14
@@ -1,8 +1,4 @@
|
|||||||
import { versionOne } from '@/docs/version_001/docsStructure';
|
|
||||||
import { versionTwo } from '@/docs/version_002/docsStructure';
|
|
||||||
import { ReactNode } from 'react';
|
import { ReactNode } from 'react';
|
||||||
import NavBar from './components/NavBar';
|
|
||||||
import SideBar from './components/SideBar';
|
|
||||||
import './globals.css';
|
import './globals.css';
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
@@ -25,16 +21,7 @@ export default function RootLayout({
|
|||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<body>
|
<body>{children}</body>
|
||||||
<SideBar
|
|
||||||
versionOne={versionOne}
|
|
||||||
versionTwo={versionTwo}
|
|
||||||
/>
|
|
||||||
<div className="container">
|
|
||||||
<NavBar />
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import fs from 'fs';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import React, { ReactNode } from 'react';
|
import React, { ReactNode } from 'react';
|
||||||
import Code from '../components/Code';
|
import Code from '../components/Code';
|
||||||
import { Doc, Section } from './../types/types';
|
import { Doc, DocSection } from './../types/types';
|
||||||
const DOCS_PATH = path.join(process.cwd(), 'src/docs');
|
const DOCS_PATH = path.join(process.cwd(), 'src/docs');
|
||||||
|
|
||||||
function getCopyPath(version: string, doc: Doc): string {
|
function getCopyPath(version: string, doc: Doc): string {
|
||||||
@@ -78,8 +78,8 @@ function getExampleChild(version: string, doc: Doc) {
|
|||||||
export function loadSections(
|
export function loadSections(
|
||||||
version: string,
|
version: string,
|
||||||
docs: Doc[],
|
docs: Doc[],
|
||||||
sections: Section[] = []
|
sections: DocSection[] = []
|
||||||
): Section[] {
|
): DocSection[] {
|
||||||
for (const doc of docs) {
|
for (const doc of docs) {
|
||||||
sections.push({
|
sections.push({
|
||||||
title: doc.title,
|
title: doc.title,
|
||||||
|
|||||||
+11
-14
@@ -1,25 +1,22 @@
|
|||||||
import { versionTwo } from '@/docs/version_002/docsStructure';
|
import { versionTwo } from '@/docs/version_002/docsStructure';
|
||||||
import Section from './components/Section';
|
import Main from './components/Main';
|
||||||
|
import NavBar from './components/NavBar';
|
||||||
|
import SideBar from './components/SideBar';
|
||||||
import { loadSections } from './lib/markdoc';
|
import { loadSections } from './lib/markdoc';
|
||||||
import styles from './page.module.css';
|
|
||||||
|
|
||||||
export default function Home() {
|
export default function Page() {
|
||||||
const versionTwoSections = loadSections(
|
const versionTwoSections = loadSections(
|
||||||
versionTwo.version,
|
versionTwo.version,
|
||||||
versionTwo.docs
|
versionTwo.docs
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className={styles.container}>
|
<>
|
||||||
{versionTwoSections.map(section => (
|
<SideBar version={versionTwo} />
|
||||||
<>
|
<div className="container">
|
||||||
<Section key={section.title}>
|
<NavBar version={versionTwo} />
|
||||||
{section.copy}
|
<Main versionSections={versionTwoSections} />
|
||||||
{section.example}
|
</div>
|
||||||
</Section>
|
</>
|
||||||
<div className={styles.divider}> </div>
|
|
||||||
</>
|
|
||||||
))}
|
|
||||||
</main>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export type Doc = {
|
|||||||
children?: Doc[];
|
children?: Doc[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Section = {
|
export type DocSection = {
|
||||||
title: string;
|
title: string;
|
||||||
copy: ReactNode;
|
copy: ReactNode;
|
||||||
example: ReactNode;
|
example: ReactNode;
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { versionOne } from '@/docs/version_001/docsStructure';
|
||||||
|
import Main from '../components/Main';
|
||||||
|
import NavBar from '../components/NavBar';
|
||||||
|
import SideBar from '../components/SideBar';
|
||||||
|
import { loadSections } from '../lib/markdoc';
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
const versionOneSections = loadSections(
|
||||||
|
versionOne.version,
|
||||||
|
versionOne.docs
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<SideBar version={versionOne} />
|
||||||
|
<div className="container">
|
||||||
|
<NavBar version={versionOne} />
|
||||||
|
<Main versionSections={versionOneSections} />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,13 +2,5 @@ import { DocsStructure } from '@/app/types/types';
|
|||||||
|
|
||||||
export const versionOne: DocsStructure = {
|
export const versionOne: DocsStructure = {
|
||||||
version: 'version_001',
|
version: 'version_001',
|
||||||
docs: [
|
docs: [],
|
||||||
{
|
|
||||||
title: 'Introduction',
|
|
||||||
folder: 'introduction',
|
|
||||||
copy: 'copy.md',
|
|
||||||
example: 'example.md',
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user