Open History to see the last commit
1import type { LinkOptions } from "@tanstack/react-router";
2import { Check } from "lucide-react";
3import type { ReactNode } from "react";
4
5import { cn } from "@/lib/utils";
6
7import { useActiveSection, useIsSectionDone } from "./guide-store";
8import { TryItButton } from "./try-it";
9
10interface GuideSectionProps {
11 id: string;
12 /** Small label above the heading, e.g. "Step 2". */
13 eyebrow?: string;
14 title: string;
15 /** Where the section's hands-on step happens in the app, if it has one. */
16 tryIt?: LinkOptions;
17 children: ReactNode;
18}
19
20export function GuideSection({ id, eyebrow, title, tryIt, children }: GuideSectionProps) {
21 const isActive = useActiveSection() === id;
22 const isDone = useIsSectionDone(id);
23
24 return (
25 <section
26 id={id}
27 data-scroll-anchor
28 data-active={isActive || undefined}
29 aria-current={isActive ? "step" : undefined}
30 className={cn(
31 "relative scroll-mt-6 rounded-2xl border border-transparent px-5 py-6 transition-[background-color,border-color,box-shadow] duration-300 sm:px-7",
32 "data-active:border-guide-accent/40 data-active:bg-guide-accent-soft data-active:shadow-[0_0_0_4px_color-mix(in_oklch,var(--guide-accent)_12%,transparent)]",
33 )}
34 >
35 <span
36 aria-hidden
37 className="absolute inset-y-6 left-0 w-[3px] rounded-full bg-guide-accent opacity-0 transition-opacity duration-300 group-data-active:opacity-100 [[data-active]>&]:opacity-100"
38 />
39 <header className="mb-3 flex items-center gap-2">
40 {eyebrow && (
41 <span className="text-xs font-semibold tracking-wide text-guide-accent uppercase">
42 {eyebrow}
43 </span>
44 )}
45 {isDone && (
46 <span
47 className="grid size-4 place-items-center rounded-full bg-emerald-600 text-white dark:bg-emerald-500"
48 title="Done"
49 >
50 <Check className="size-3" strokeWidth={3} aria-hidden />
51 <span className="sr-only">Done</span>
52 </span>
53 )}
54 {isActive && (
55 <span className="ml-auto inline-flex items-center gap-1.5 rounded-full bg-guide-accent px-2 py-0.5 text-[11px] font-semibold text-white">
56 <span className="size-1.5 animate-pulse rounded-full bg-white" />
57 You are here
58 </span>
59 )}
60 </header>
61 <h2 className="mb-3 text-[1.35rem] leading-tight font-semibold tracking-tight text-balance">
62 {title}
63 </h2>
64 <div className="guide-prose">{children}</div>
65 {tryIt && <TryItButton sectionId={id} target={tryIt} />}
66 </section>
67 );
68}