Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com
Open History to see the last commit

TutorialTableOfContents.tsx

76 lines2.3 KB

1import { ExternalLinkIcon } from "lucide-react";
2import {
3 SidebarGroup,
4 SidebarGroupContent,
5 SidebarGroupLabel,
6 SidebarMenu,
7 SidebarMenuItem,
8 SidebarMenuSub,
9 SidebarMenuSubButton,
10 SidebarMenuSubItem,
11} from "@/components/ui/sidebar";
12import { deepDiveArticles, tutorialArticles } from "@/data/tutorial";
13import { Button } from "../ui/button";
14​
15type TutorialTableOfContentsProps = {
16 activeStep: string | null;
17 onStepChange: (stepTitle: string) => void;
18};
19​
20const sections = [
21 {
22 sectionTitle: "Tutorial",
23 articles: tutorialArticles,
24 },
25 {
26 sectionTitle: "Deep Dive Articles",
27 articles: deepDiveArticles,
28 },
29];
30​
31export function TutorialTableOfContents({
32 activeStep,
33 onStepChange,
34}: TutorialTableOfContentsProps) {
35 return (
36 <div className="w-48 shrink-0">
37 <div className="px-2 py-2 mb-2">
38 <a
39 href="https://tanstack.com/db/latest"
40 target="_blank"
41 rel="noreferrer"
42 className="text-foreground font-bold flex items-center text-sm hover:text-primary transition-colors"
43 >
44 Official docs <ExternalLinkIcon className="h-4 ml-1" />
45 </a>
46 </div>
47​
48 {sections.map(({ sectionTitle, articles }) => (
49 <SidebarGroup key={sectionTitle} className="px-0 py-1">
50 <SidebarGroupLabel className="text-foreground font-bold text-sm px-2">
51 {sectionTitle}
52 </SidebarGroupLabel>
53 <SidebarGroupContent>
54 <SidebarMenu>
55 <SidebarMenuItem>
56 <SidebarMenuSub className="border-l-muted-foreground/30">
57 {articles.map((step) => (
58 <SidebarMenuSubItem key={step.title}>
59 <SidebarMenuSubButton
60 isActive={activeStep === step.title}
61 onClick={() => onStepChange(step.title)}
62 className="cursor-pointer text-muted-foreground hover:text-foreground data-[active=true]:bg-secondary data-[active=true]:text-primary-foreground h-fit"
63 >
64 {step.title}
65 </SidebarMenuSubButton>
66 </SidebarMenuSubItem>
67 ))}
68 </SidebarMenuSub>
69 </SidebarMenuItem>
70 </SidebarMenu>
71 </SidebarGroupContent>
72 </SidebarGroup>
73 ))}
74 </div>
75 );