From 4c99485781e04018779fbb8cadf7549a1e59a5bd Mon Sep 17 00:00:00 2001 From: Brandon Romano Date: Fri, 20 Dec 2024 13:53:05 -0800 Subject: [PATCH] Only highlight the first sidecar item --- src/components/sidecar/index.tsx | 61 ++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/src/components/sidecar/index.tsx b/src/components/sidecar/index.tsx index a9b0b2e7..c754c52d 100644 --- a/src/components/sidecar/index.tsx +++ b/src/components/sidecar/index.tsx @@ -15,41 +15,56 @@ interface SidecarProps { inViewHeaderIDs: string[]; } +// If there's less items than this, the sidecar content won't render +// it does not make sense to have a single item in the sidecar. +const MIN_SIDECAR_ITEMS = 2; + export default function Sidecar({ className, title, items, inViewHeaderIDs, }: SidecarProps) { + // Calculate the first header that's in view + var activeHeaderID: null | string; + for (const item of items) { + if (inViewHeaderIDs.includes(item.id.substring(1))) { + activeHeaderID = item.id; + break; + } + } return (
-
{title}
- + + )}
); }