vega-frontend-monorepo/apps/trading/components/navbar/index.tsx

43 lines
949 B
TypeScript
Raw Normal View History

2022-02-17 05:14:23 +00:00
import { useRouter } from 'next/router';
import classNames from 'classnames';
2022-02-17 05:08:17 +00:00
export const Navbar = () => {
2022-03-02 00:26:51 +00:00
const navClasses = classNames('border-neutral-200 border-b');
2022-02-17 05:08:17 +00:00
return (
<nav className={navClasses}>
2022-02-17 05:08:17 +00:00
{[
{ name: 'Portfolio', path: '/portfolio' },
{ name: 'Markets', path: '/markets' },
].map((route) => (
2022-02-17 05:14:23 +00:00
<NavLink key={route.path} {...route} />
2022-02-17 05:08:17 +00:00
))}
</nav>
);
};
2022-02-17 05:14:23 +00:00
interface NavLinkProps {
name: string;
path: string;
}
const NavLink = ({ name, path }: NavLinkProps) => {
const router = useRouter();
const className = classNames('inline-block', 'p-8', {
2022-03-02 00:26:51 +00:00
// Handle direct math and child page matches
'text-vega-pink': router.asPath === path || router.asPath.startsWith(path),
});
2022-02-17 05:14:23 +00:00
return (
<a
className={className}
2022-02-17 05:14:23 +00:00
href={path}
onClick={(e) => {
e.preventDefault();
router.push(path);
}}
>
{name}
</a>
);
};