forked from LAION-AI/Open-Assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSideMenu.tsx
101 lines (95 loc) · 2.61 KB
/
SideMenu.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { Box, Button, Card, Text, Tooltip } from "@chakra-ui/react";
import clsx from "clsx";
import { LucideIcon } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/router";
import { useTranslation } from "next-i18next";
import { getTypeSafei18nKey } from "src/lib/i18n";
import { HEADER_HEIGHT } from "./Header/Header";
export interface SideMenuItemType {
labelID: string;
pathname: string;
icon: LucideIcon;
target?: HTMLAnchorElement["target"];
}
export interface SideMenuProps {
items: SideMenuItemType[];
}
export const SIDE_MENU_WIDTH = {
MD: `100px`,
LG: `280px`,
};
export function SideMenu({ items }: SideMenuProps) {
return (
<Card
position={{ base: "relative", md: "fixed" }}
p={{ base: 4, md: 3, lg: 4 }}
width={{
base: "100%",
md: SIDE_MENU_WIDTH.MD,
lg: SIDE_MENU_WIDTH.LG,
}}
height={{ base: "auto", md: `calc(100vh - ${HEADER_HEIGHT} - ${1.5 * 2}rem)` }}
>
<Box
as="nav"
gap="2"
display={{ base: "grid", md: "flex" }}
flexDirection="column"
className="grid-cols-3 col-span-3"
>
{items.map((item) => (
<SideMenuItem item={item} key={item.labelID} variant="default"></SideMenuItem>
))}
</Box>
</Card>
);
}
export const SideMenuItem = ({
item,
variant = "default",
active,
}: {
item: SideMenuItemType;
variant: "default" | "chat";
active?: boolean;
}) => {
const isChat = variant === "chat";
const router = useRouter();
const { t } = useTranslation();
const label = t(getTypeSafei18nKey(item.labelID));
const isActive = active ?? router.pathname === item.pathname;
return (
<Tooltip
key={item.labelID}
label={label}
placement="right"
className={clsx("hidden sm:block", { "lg:hidden": !isChat })}
>
<Button
as={Link}
key={item.labelID}
href={item.pathname}
target={item.target}
className="no-underline"
gap={3}
borderRadius={isChat ? "2xl" : "lg"}
size="lg"
justifyContent={{ base: "center", lg: isChat ? "center" : "start" }}
width="full"
p={isChat ? 2 : undefined}
bg={isActive ? "blue.500" : undefined}
_hover={isActive ? { bg: "blue.600" } : undefined}
>
<item.icon size={"1em"} className={isActive ? "text-blue-200" : undefined} />
<Text
fontWeight="normal"
color={isActive ? "white" : undefined}
className={clsx("hidden", { "lg:block": !isChat })}
>
{label}
</Text>
</Button>
</Tooltip>
);
};