Skip to content

Commit

Permalink
Integrate routing and fix dark mode for mobile nav menu
Browse files Browse the repository at this point in the history
  • Loading branch information
siddg97 committed Feb 11, 2024
1 parent 682c8f1 commit 778c3b2
Show file tree
Hide file tree
Showing 22 changed files with 534 additions and 105 deletions.
2 changes: 1 addition & 1 deletion react/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<title>Siddharth Gupta</title>
</head>
<body>
<div id="root"></div>
Expand Down
1 change: 1 addition & 0 deletions react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"framer-motion": "^11.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.0",
"tailwind-merge": "^2.2.1",
"use-dark-mode": "^2.3.1",
"usehooks-ts": "^2.13.0"
Expand Down
20 changes: 20 additions & 0 deletions react/public/gradient-bg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 19 additions & 3 deletions react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
import { Outlet, Route, Routes } from 'react-router-dom';
import { useDarkMode } from 'usehooks-ts';
import Navigation from './components/Navigation.tsx';
import { Navigation, PageContainer } from './components';
import { routes } from './routes';

function App() {
const { isDarkMode } = useDarkMode();

return (
<main
className={`${isDarkMode ? 'dark' : ''} w-full min-h-screen p-2 text-foreground bg-background`}
className={`${isDarkMode ? 'dark bg-accent-gr bg-auto' : ''} w-full min-h-screen text-foreground bg-background`}
>
<Navigation />
<div className='mt-6 flex w-full flex-col items-center'>Hello</div>
<Routes>
<Route
path='/'
element={
<PageContainer>
<Outlet />
</PageContainer>
}
>
{routes.map(r => (
<Route index={r.path === '/'} path={r.path} element={r.component} />
))}
{/*<Route path='*' element={<NoMatch />} />*/}
</Route>
</Routes>
</main>
);
}
Expand Down
96 changes: 0 additions & 96 deletions react/src/components/Navigation.tsx

This file was deleted.

15 changes: 15 additions & 0 deletions react/src/components/containers/PageContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ReactNode } from 'react';

type Props = {
children: ReactNode;
};

function PageContainer({ children }: Props) {
return (
<div className='mt-6 flex w-full justify-center justify-items-center items-center container mx-auto max-w-7xl px-6 flex-grow'>
{children}
</div>
);
}

export { PageContainer };
1 change: 1 addition & 0 deletions react/src/components/containers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './PageContainer';
1 change: 0 additions & 1 deletion react/src/components/index.ts

This file was deleted.

2 changes: 2 additions & 0 deletions react/src/components/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './containers';
export * from './navigation';
71 changes: 71 additions & 0 deletions react/src/components/navigation/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {
Navbar,
NavbarBrand,
NavbarContent,
NavbarItem,
NavbarMenu,
NavbarMenuToggle,
} from '@nextui-org/react';
import { routes } from '../../routes';
import { ThemeSwitcher } from './ThemeSwitcher.tsx';
import { NavigationLink } from './NavigationLink.tsx';

function Navigation() {
return (
<Navbar
classNames={{
item: 'data-[active=true]:text-primary dark:data-[active=true]:text-primary-500 font-semibold',
menuItem: 'data-[active=true]:text-primary dark:data-[active=true]:text-primary-500 font-semibold',
wrapper: 'px-4 sm:px-6',
}}
height='60px'
maxWidth='xl'
isBlurred
>
<NavbarBrand>
<NavbarMenuToggle className='mr-2 h-6 sm:hidden' />
<p className='font-bold text-inherit text-xl sm:text-2xl'>
Siddharth Gupta
</p>
</NavbarBrand>

<NavbarContent
className='ml-4 hidden h-12 w-full max-w-fit gap-4 rounded-full bg-content2 px-4 sm:flex'
justify='start'
>
{routes.map(r => (
<NavigationLink
key={`nav-${r.path}`}
path={r.path}
text={r.navText}
/>
))}
</NavbarContent>

<NavbarContent
className='ml-auto flex h-12 max-w-fit items-center gap-0 rounded-full p-0 lg:bg-content2 lg:px-1 lg:dark:bg-content1'
justify='end'
>
<NavbarItem>
<ThemeSwitcher />
</NavbarItem>
</NavbarContent>

{/* Mobile Menu */}
<NavbarMenu
portalContainer={document.body.getElementsByTagName('main')[0]}
>
{routes.map(r => (
<NavigationLink
key={`nav-mobile-${r.path}`}
path={r.path}
text={r.navText}
mobile
/>
))}
</NavbarMenu>
</Navbar>
);
}

export { Navigation };
37 changes: 37 additions & 0 deletions react/src/components/navigation/NavigationLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { NavbarItem, NavbarMenuItem } from '@nextui-org/react';
import { ReactNode } from 'react';
import { NavLink, Path, useMatch, useResolvedPath } from 'react-router-dom';

type Props = {
path: string;
text: ReactNode;
mobile?: boolean;
};

function NavigationLink({ path, text, mobile = false }: Props) {
const resolvedPath: Path = useResolvedPath(path);
const matchedPath = useMatch({
path: resolvedPath.pathname,
end: true,
});

if (mobile) {
return (
<NavbarMenuItem isActive={matchedPath !== null}>
<NavLink to={path} className='w-full'>
{text}
</NavLink>
</NavbarMenuItem>
);
}

return (
<NavbarItem isActive={matchedPath !== null}>
<NavLink className='flex gap-2 text-inherit' to={path}>
{text}
</NavLink>
</NavbarItem>
);
}

export { NavigationLink };
File renamed without changes.
3 changes: 3 additions & 0 deletions react/src/components/navigation/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './NavigationLink';
export * from './Navigation';
export * from './ThemeSwitcher';
9 changes: 6 additions & 3 deletions react/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { NextUIProvider } from '@nextui-org/react';
import React from 'react';
import ReactDOM from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import App from './App.tsx';
import './index.css';

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<NextUIProvider>
<App />
</NextUIProvider>
<BrowserRouter>
<NextUIProvider>
<App />
</NextUIProvider>
</BrowserRouter>
</React.StrictMode>
);
8 changes: 8 additions & 0 deletions react/src/pages/Contact.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

function Contact() {
return (
<div>Contact</div>
);
}

export { Contact };
Loading

0 comments on commit 778c3b2

Please sign in to comment.