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

49 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-02-17 05:14:23 +00:00
import { useRouter } from 'next/router';
2022-03-02 00:43:45 +00:00
import { Vega } from '../icons/vega';
import Link from 'next/link';
import { AnchorButton } from '@vegaprotocol/ui-toolkit';
2022-02-17 05:08:17 +00:00
export const Navbar = () => {
return (
<nav className="flex items-center">
2022-03-02 00:43:45 +00:00
<Link href="/" passHref={true}>
<a className="px-[26px]">
<Vega className="fill-black dark:fill-white" />
2022-03-02 00:43:45 +00:00
</a>
</Link>
2022-02-17 05:08:17 +00:00
{[
{ name: 'Trading', path: '/', exact: true },
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;
exact?: boolean;
2022-02-17 05:14:23 +00:00
}
const NavLink = ({ name, path, exact }: NavLinkProps) => {
2022-02-17 05:14:23 +00:00
const router = useRouter();
const isActive =
router.asPath === path || (!exact && router.asPath.startsWith(path));
2022-02-17 05:14:23 +00:00
return (
<AnchorButton
variant={isActive ? 'accent' : 'inline'}
className="px-16 h-[38px] text-h4 uppercase border-0"
2022-02-17 05:14:23 +00:00
href={path}
onClick={(e) => {
e.preventDefault();
router.push(path);
}}
>
{name}
</AnchorButton>
2022-02-17 05:14:23 +00:00
);
};