From ac386b5717c1f83c60f5fe1cf427ca3ead071517 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Fri, 28 Apr 2023 08:33:11 -0500 Subject: [PATCH] Feat: Add Background to Current Section Title Added functionality to allow the background color of the link that links to the current section to be highlighted. --- src/app/components/SideBar.module.css | 17 ++++++++++++----- src/app/components/SideBar.tsx | 25 ++++++++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/app/components/SideBar.module.css b/src/app/components/SideBar.module.css index e956b75..5fba29a 100644 --- a/src/app/components/SideBar.module.css +++ b/src/app/components/SideBar.module.css @@ -3,7 +3,7 @@ flex-direction: column; height: 100%; border-right: 1px solid #848586; - padding: 0 1rem; + padding: 0 1rem 0 0.5rem; overflow: auto; background-color: inherit; width: 300px; @@ -64,19 +64,26 @@ width: 100%; } +.linkGroup { + padding: 0 0.5rem; +} + .link, .activeLink { + padding: 0 1rem 0 0.5rem; text-decoration: none; } +.activeLink { + background-color: #8485866b; + border-top-right-radius: 999px; + border-bottom-right-radius: 999px; +} + .link:hover { color: #64adac; } -.activeLink { - background-color: #1e1e1e; -} - .expandable { width: 100%; display: flex; diff --git a/src/app/components/SideBar.tsx b/src/app/components/SideBar.tsx index 2f681c2..f677ad8 100644 --- a/src/app/components/SideBar.tsx +++ b/src/app/components/SideBar.tsx @@ -2,6 +2,7 @@ import Link from 'next/link.js'; import { useState } from 'react'; +import { useSectionContext } from '../context/section'; import { useThemeContext } from '../context/theme'; import { Doc, DocsStructure } from '../types/types'; import { toKebabCase } from '../utils/stringUtils'; @@ -11,6 +12,16 @@ function TreeNode({ doc }: { doc: Doc }) { const [isExpanded, setIsExpanded] = useState(true); + const { section, setSection } = useSectionContext(); + + const docTitleId = toKebabCase(doc.title); + + const isActiveSection = docTitleId === section; + + const linkStyle = isActiveSection + ? styles.activeLink + : styles.link; + const hasChildren = doc.children && doc.children?.length > 0; @@ -20,13 +31,16 @@ function TreeNode({ doc }: { doc: Doc }) {
{doc.copy ? ( setSection(docTitleId)} + href={`#${docTitleId}`} + className={linkStyle} > {doc.title} ) : ( -
{doc.title}
+
+ {doc.title} +
)}
) : doc.copy ? ( setSection(docTitleId)} + href={`#${docTitleId}`} + className={linkStyle} > {doc.title}