From 5042393cfa7522e4192390c92e62155e1d2d2d65 Mon Sep 17 00:00:00 2001 From: Alexander Chabin Date: Thu, 21 Dec 2023 10:17:27 +0500 Subject: [PATCH] Add sticky menu-item in TOC --- .../TableOfContents/TableOfContents.jsx | 38 ++++++++++--------- .../TableOfContents.module.css | 35 +++++++++++++---- 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/components/TableOfContents/TableOfContents.jsx b/components/TableOfContents/TableOfContents.jsx index cc11aba2..e58acf02 100644 --- a/components/TableOfContents/TableOfContents.jsx +++ b/components/TableOfContents/TableOfContents.jsx @@ -72,27 +72,29 @@ function TableOfContents({ {order}.  {tUI(title)} + {currentPageUrl[1] && currentPageUrl[1] === url && anchorLinks.length > 0 && ( -
+ )} - {currentPageUrl[1] && currentPageUrl[1] === url && anchorLinks.length > 0 && ( - - )} ) diff --git a/components/TableOfContents/TableOfContents.module.css b/components/TableOfContents/TableOfContents.module.css index ff31a7a5..0080925a 100644 --- a/components/TableOfContents/TableOfContents.module.css +++ b/components/TableOfContents/TableOfContents.module.css @@ -86,6 +86,7 @@ html:has(.open) { .tableOfContentsLink:not(:only-child) { border-bottom-left-radius: 0; border-bottom-right-radius: 0; + border-bottom: 1px solid hsl(var(--color-hsl) / 20%); } @media (hover: hover) { @@ -192,6 +193,32 @@ html:has(.open) { list-style: none; } +.active { + position: sticky; + top: 0; + z-index: 1; +} + +.active::before, +.active::after { + content: ''; + position: absolute; + top: 0; + left: 0; + z-index: -1; + width: 100%; + height: 100%; + border-radius: inherit; +} + +.active::before { + background: var(--color-bg-light); +} + +.active::after { + background-color: var(--color-bg-dark); +} + .active, .active:hover, .innerlinkContainerList { @@ -200,14 +227,6 @@ html:has(.open) { background-color: var(--color-bg-dark); } -.separator { - height: 1px; - margin: 0; - border: 0; - background: var(--color); - opacity: 0.2; -} - .TableOfContents__aside { display: flex; }