Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
add nav link highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
joshnies committed Aug 4, 2021
1 parent 261fd93 commit f986a16
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
4 changes: 2 additions & 2 deletions components/hamburger-button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTheme } from '@geist-ui/react';

export default function HamburgerButton(props: {
isActive: boolean;
active: boolean;
onClick: () => void;
}) {
const theme = useTheme();
Expand All @@ -24,7 +24,7 @@ export default function HamburgerButton(props: {
};

const Icon = () => {
if (props.isActive) {
if (props.active) {
return (
<>
<Line />
Expand Down
7 changes: 5 additions & 2 deletions components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import Navbar from './navbar';

export default function Layout(props: {
title?: string;
activeRoute?: string;
children: React.ReactNode;
}) {
const { activeRoute, children } = props;

return (
<>
<Head>
Expand All @@ -14,8 +17,8 @@ export default function Layout(props: {
<link rel="icon" href="/favicon.ico" />
</Head>
<main>
<Navbar />
{props.children}
<Navbar activeRoute={activeRoute} />
{children}
</main>
</>
);
Expand Down
6 changes: 5 additions & 1 deletion components/nav-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ export default function NavItem(props: {
className?: string;
children: React.ReactNode;
to: string;
activeRoute?: string;
newTab?: boolean;
}) {
const { children, to, newTab } = props;
const { children, to, activeRoute, newTab } = props;
const opacity = to === activeRoute ? 1 : 0.75;

if (newTab) {
return (
Expand All @@ -31,6 +33,7 @@ export default function NavItem(props: {
fontSize: 14,
fontWeight: 500,
color: 'white',
opacity,
marginLeft: 50,
userSelect: 'none',
transition: '250ms ease',
Expand Down Expand Up @@ -63,6 +66,7 @@ export default function NavItem(props: {
fontSize: 14,
fontWeight: 500,
color: 'white',
opacity,
marginLeft: 50,
userSelect: 'none',
transition: '250ms ease',
Expand Down
22 changes: 17 additions & 5 deletions components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import routes from '../routes';
/**
* Navbar.
*/
export default function Navbar() {
export default function Navbar(props: { activeRoute?: string }) {
const [showDrawer, setShowDrawer] = useState(false);
const theme = useTheme();

Expand Down Expand Up @@ -67,14 +67,26 @@ export default function Navbar() {
</a>
</Link>
</li>
<DynamicNavItem to={routes.theory.index}>theory</DynamicNavItem>
<DynamicNavItem to={routes.theory.caseStudy}>
<DynamicNavItem
to={routes.theory.index}
activeRoute={props.activeRoute}
>
theory
</DynamicNavItem>
<DynamicNavItem
to={routes.theory.caseStudy}
activeRoute={props.activeRoute}
>
case study
</DynamicNavItem>
<DynamicNavItem to={routes.blog} newTab>
<DynamicNavItem
to={routes.blog}
activeRoute={props.activeRoute}
newTab
>
blog
</DynamicNavItem>
<HamburgerButton isActive={showDrawer} onClick={toggleDrawer} />
<HamburgerButton active={showDrawer} onClick={toggleDrawer} />
</ul>
</nav>
{showDrawer && <NavDrawer />}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"start": "next start",
"lint": "next lint",
"storybook": "start-storybook -p 6006",
"sb": "yarn storybook",
"build-storybook": "build-storybook"
},
"dependencies": {
Expand Down
5 changes: 4 additions & 1 deletion stories/Navbar.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';
import Navbar from '../components/navbar';
import routes from '../routes';

export default {
title: 'Navbar',
component: Navbar,
} as ComponentMeta<typeof Navbar>;

const Template: ComponentStory<typeof Navbar> = () => <Navbar />;
const Template: ComponentStory<typeof Navbar> = () => (
<Navbar activeRoute={routes.theory.index} />
);

export const Default = Template.bind({});

0 comments on commit f986a16

Please sign in to comment.