2022-03-14 13:18:11 +00:00
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
import { Vega } from '../icons/vega';
|
|
|
|
import Link from 'next/link';
|
|
|
|
import { AnchorButton } from '@vegaprotocol/ui-toolkit';
|
2022-06-08 08:47:31 +00:00
|
|
|
import { t } from '@vegaprotocol/react-helpers';
|
2022-03-14 13:18:11 +00:00
|
|
|
|
|
|
|
export const Navbar = () => {
|
|
|
|
return (
|
|
|
|
<nav className="flex items-center">
|
|
|
|
<Link href="/" passHref={true}>
|
|
|
|
<a className="px-[26px]">
|
|
|
|
<Vega className="fill-black dark:fill-white" />
|
|
|
|
</a>
|
|
|
|
</Link>
|
2022-06-08 08:47:31 +00:00
|
|
|
{[
|
|
|
|
{ name: t('Trading'), path: '/markets' },
|
|
|
|
{ name: t('Portfolio'), path: '/portfolio' },
|
|
|
|
].map((route) => (
|
2022-03-14 13:18:11 +00:00
|
|
|
<NavLink key={route.path} {...route} />
|
|
|
|
))}
|
|
|
|
</nav>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
interface NavLinkProps {
|
|
|
|
name: string;
|
|
|
|
path: string;
|
|
|
|
exact?: boolean;
|
2022-06-06 16:19:56 +00:00
|
|
|
testId?: string;
|
2022-03-14 13:18:11 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 08:47:31 +00:00
|
|
|
const NavLink = ({ name, path, exact, testId = name }: NavLinkProps) => {
|
2022-03-14 13:18:11 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const isActive =
|
|
|
|
router.asPath === path || (!exact && router.asPath.startsWith(path));
|
|
|
|
return (
|
|
|
|
<AnchorButton
|
|
|
|
variant={isActive ? 'accent' : 'inline'}
|
2022-03-24 18:08:57 +00:00
|
|
|
className="px-16 py-6 h-[38px] uppercase border-0 self-end xs:text-ui sm:text-body-large md:text-h5 lg:text-h4"
|
2022-06-06 16:19:56 +00:00
|
|
|
data-testid={testId}
|
2022-06-08 08:47:31 +00:00
|
|
|
href={path}
|
2022-03-14 13:18:11 +00:00
|
|
|
>
|
|
|
|
{name}
|
|
|
|
</AnchorButton>
|
|
|
|
);
|
|
|
|
};
|