Files
onspring-api-docs/src/app/components/NavBar.tsx
T

173 lines
4.3 KiB
TypeScript
Raw Normal View History

2023-04-08 14:32:56 -05:00
'use client';
import Link from 'next/link';
import { useState } from 'react';
import { themes, useThemeContext } from '../theme';
import { DocsStructure } from '../types/types';
2023-04-07 23:18:45 -05:00
import styles from './NavBar.module.css';
import SectionDropdown from './SectionDropdown';
2023-04-07 23:18:45 -05:00
2023-04-17 23:06:10 -05:00
function VersionsDropdown({
version,
}: {
version: string;
}) {
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];
2023-04-08 14:32:56 -05:00
const [isDropdownOpen, setIsDropdownOpen] =
useState<boolean>(false);
const handleDropdownToggle = () => {
setIsDropdownOpen(!isDropdownOpen);
};
return (
<>
<a
className={styles.navLink}
onClick={handleDropdownToggle}
>
{currentVersion.name}{' '}
2023-04-08 14:32:56 -05:00
{isDropdownOpen ? (
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
fill="currentColor"
className={styles.chevron}
viewBox="0 0 16 16"
>
<path
fillRule="evenodd"
2023-04-08 14:32:56 -05:00
d="M7.646 4.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1-.708.708L8 5.707l-5.646 5.647a.5.5 0 0 1-.708-.708l6-6z"
/>
</svg>
) : (
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
fill="currentColor"
className={styles.chevron}
viewBox="0 0 16 16"
>
<path
fillRule="evenodd"
2023-04-08 14:32:56 -05:00
d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"
/>
</svg>
)}
</a>
<div
className={
isDropdownOpen
? styles.dropdownMenuOpen
: styles.dropdownMenu
}
>
{Object.keys(versions)
2023-04-08 14:32:56 -05:00
.filter(v => v !== version)
.map(v => (
<Link
href={`${versions[v].path}`}
2023-04-08 14:32:56 -05:00
key={v}
className={styles.navLink}
onClick={() => {
setIsDropdownOpen(false);
}}
>
{versions[v].name}
</Link>
2023-04-08 14:32:56 -05:00
))}
</div>
</>
);
}
export default function NavBar({
version,
}: {
version: DocsStructure;
}) {
const { theme } = useThemeContext();
const themeStyles = themes[theme];
2023-04-19 23:09:51 -05:00
const [isNavOpen, setIsNavOpen] =
useState<boolean>(false);
const handleNavToggle = () => {
setIsNavOpen(!isNavOpen);
};
2023-04-07 23:18:45 -05:00
return (
<nav style={themeStyles} className={styles.nav}>
2023-04-19 23:09:51 -05:00
<ul className={styles.navListLeft}>
2023-04-18 22:51:50 -05:00
<li className={styles.sectionDropdown}>
<SectionDropdown version={version} />
</li>
</ul>
2023-04-19 23:09:51 -05:00
<div>
<div
onClick={handleNavToggle}
className={styles.navbarToggle}
>
<div className={styles.navbarToggleLine}></div>
<div className={styles.navbarToggleLine}></div>
<div className={styles.navbarToggleLine}></div>
</div>
<ul
className={
isNavOpen
? `${styles.navListRight} ${styles.navListRightOpen}`
: styles.navListRight
}
>
<li className={styles.navItem}>
<VersionsDropdown version={version.version} />
</li>
2023-04-25 16:56:06 -05:00
<li className={styles.navItem}>
<Link
href={version.officialDocs}
className={styles.navLink}
target="_blank"
>
Official Docs
</Link>
</li>
{version.hasSwagger ? (
<li className={styles.navItem}>
2023-04-19 23:09:51 -05:00
<Link
href="https://api.onspring.com/swagger"
className={styles.navLink}
target="_blank"
>
Swagger
</Link>
</li>
) : null}
2023-04-19 23:09:51 -05:00
<li className={styles.navItem}>
2023-04-13 17:22:28 -05:00
<Link
2023-04-19 23:09:51 -05:00
href="https://onspring.com/customer-service/admin-support/"
2023-04-13 17:22:28 -05:00
className={styles.navLink}
target="_blank"
>
2023-04-19 23:09:51 -05:00
Support
2023-04-13 17:22:28 -05:00
</Link>
2023-04-19 23:09:51 -05:00
</li>
</ul>
</div>
2023-04-07 23:18:45 -05:00
</nav>
);
}