Files
transform/components/Navigator.tsx
T

101 lines
2.9 KiB
TypeScript

import React, { Fragment } from "react";
import { Heading, Pane, Text } from "evergreen-ui";
import { categorizedRoutes, Route } from "@utils/routes";
import { Link, useRouterState } from "@tanstack/react-router";
import SearchBox from "@components/Searchbox";
export default function Navigator() {
const pathname = useRouterState({ select: state => state.location.pathname });
return (
<Pane
width={240}
height={"calc(100vh - 40px)"}
borderRight
display="flex"
flexDirection="column"
paddingTop={20}
backgroundColor="#FFFFFF"
>
<Pane paddingX={15}>
<SearchBox />
</Pane>
<Pane
display="flex"
flex={1}
overflowY="scroll"
flexDirection="column"
paddingBottom={10}
>
{categorizedRoutes.map(route => {
return (
<Fragment key={route.category}>
<Pane paddingX={10} marginTop={15} marginBottom={2}>
<Heading marginLeft={5} size={400}>
{route.category}
</Heading>
</Pane>
{(route.content as Route[])
.sort((a, b) => a.label.localeCompare(b.label))
.map((a: Route) => {
const isActive = pathname === a.path;
return (
<Link
key={a.label}
to={a.path}
preload={false}
style={{ textDecoration: "none" }}
>
<Pane
paddingLeft={16}
paddingY={3}
backgroundColor={isActive ? "#f3f3f3" : undefined}
borderLeft={
isActive
? "3px solid #009688"
: "3px solid transparent"
}
css={{
"&:hover": {
backgroundColor: "#f5f5f5"
}
}}
>
<Text fontSize={13}>{a.label}</Text>
</Pane>
</Link>
);
})}
</Fragment>
);
})}
</Pane>
<Pane borderTop>
<a
href="https://vercel.com?utm_source=ritz078&utm_campaign=oss"
target="_blank"
>
<img
src="https://www.datocms-assets.com/31049/1618983297-powered-by-vercel.svg"
alt="Vercel"
style={{
height: 40,
display: "block",
margin: "10px auto 0"
}}
/>
</a>
<Heading size={400} paddingY={15} textAlign="center">
Created by{" "}
<a href="https://twitter.com/ritz078" target="_blank">
@ritz078
</a>
</Heading>
</Pane>
</Pane>
);
}