Skip to content

Commit

Permalink
Revamp routing for documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Studio384 committed Feb 19, 2024
1 parent f238afb commit 33432a7
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 271 deletions.
51 changes: 44 additions & 7 deletions docs/src/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { createHashRouter } from 'react-router-dom';
import { Navigate, createHashRouter, redirect } from 'react-router-dom';

import Changelog from './app/Changelog';
import Docs from './app/Docs';
import PageBeat from './app/Docs/pages/Beat';
import Changelog from './app/Docs/pages/Changelog';
import PageFade from './app/Docs/pages/Fade';
import PageFlip from './app/Docs/pages/Flip';
import PageInstallation from './app/Docs/pages/Installation';
import PageRotate from './app/Docs/pages/Rotate';
import PageSpin from './app/Docs/pages/Spin';
import Error from './app/Error';
import Home from './app/Home';
import Icon from './app/Icon';
Expand All @@ -27,11 +33,42 @@ const router = createHashRouter([
},
{
path: '/docs',
element: <Docs />
},
{
path: '/docs/changelog',
element: <Changelog />
element: <Docs />,
errorElement: <Error />,
children: [
{
index: true,
element: <Navigate to="installation" replace />
},
{
path: 'installation',
element: <PageInstallation />
},
{
path: 'spin',
element: <PageSpin />
},
{
path: 'rotate',
element: <PageRotate />
},
{
path: 'flip',
element: <PageFlip />
},
{
path: 'beat',
element: <PageBeat />
},
{
path: 'fade',
element: <PageFade />
},
{
path: 'changelog',
element: <Changelog />
}
]
}
]
}
Expand Down
226 changes: 0 additions & 226 deletions docs/src/app/Changelog.tsx

This file was deleted.

15 changes: 3 additions & 12 deletions docs/src/app/Docs.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { Outlet } from 'react-router-dom';

import { Box, Container, Stack, Typography } from '@mui/joy';

import Header from '@/design/layout/LayoutElements/Header';

import DocsNavigation from './Docs/Navigation';
import PageBeat from './Docs/pages/Beat';
import PageFade from './Docs/pages/Fade';
import PageFlip from './Docs/pages/Flip';
import PageInstallation from './Docs/pages/Installation';
import PageRotate from './Docs/pages/Rotate';
import PageSpin from './Docs/pages/Spin';

export default function Docs() {
return (
Expand All @@ -30,12 +26,7 @@ export default function Docs() {
<DocsNavigation />
</Box>
<Stack gap={4}>
<PageInstallation />
<PageSpin />
<PageRotate />
<PageFlip />
<PageBeat />
<PageFade />
<Outlet />
</Stack>
</Box>
</Container>
Expand Down
18 changes: 10 additions & 8 deletions docs/src/app/Docs/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fragment } from 'react';
import { NavLink } from 'react-router-dom';
import { NavLink, useLocation } from 'react-router-dom';

import { List, ListItem, ListItemButton, ListItemContent, ListSubheader, Typography } from '@mui/joy';

Expand All @@ -15,6 +15,8 @@ import Amicon, {
} from '@studio384/amaranth';

export default function DocsNavigation() {
const location = useLocation();

const pages = [
{
title: 'Get started',
Expand All @@ -23,7 +25,7 @@ export default function DocsNavigation() {
{
title: 'Installation',
icon: aiAmicons,
link: '#installation'
link: '/docs/installation'
}
]
},
Expand All @@ -34,27 +36,27 @@ export default function DocsNavigation() {
{
title: 'Spin',
icon: aiSpinner,
link: '#spin'
link: '/docs/spin'
},
{
title: 'Rotate',
icon: aiArrowRotateRight,
link: '#rotate'
link: '/docs/rotate'
},
{
title: 'Flip',
icon: aiArrowsDownLeftRightUpCenter,
link: '#flip'
link: '/docs/flip'
},
{
title: 'Beat',
icon: aiHeart,
link: '#beat'
link: '/docs/beat'
},
{
title: 'Fade',
icon: aiCircleHalfInner,
link: '#fade'
link: '/docs/fade'
}
]
},
Expand Down Expand Up @@ -92,7 +94,7 @@ export default function DocsNavigation() {
</ListSubheader>
{category.pages.map((page) => (
<ListItem key={page.link}>
<ListItemButton component={NavLink} to={page.link} color="primary">
<ListItemButton component={NavLink} to={page.link} color="primary" selected={location.pathname.includes(page.link)}>
<ListItemContent>
<Typography noWrap>{page.title}</Typography>
</ListItemContent>
Expand Down
Loading

0 comments on commit 33432a7

Please sign in to comment.