Skip to content

Commit 5d85636

Browse files
committed
Remove bold.
Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>
1 parent 03eb037 commit 5d85636

File tree

4 files changed

+183
-20
lines changed

4 files changed

+183
-20
lines changed

src/scss/theme/_sidebar.scss

Lines changed: 98 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
.menu {
22
/* Sidebar "guide line" (vertical tree line) color */
33
--doc-sidebar-guide-line-color: var(--ifm-toc-border-color);
4+
/* Single source of truth for the tree-line X position (used by lines + selected highlight) */
5+
--doc-sidebar-line-x: 1.6rem;
6+
/* Selected item background tint (fallback first, then color-mix for nicer tinting) */
7+
--doc-sidebar-selected-bg: rgba(186, 242, 74, 0.10);
8+
--doc-sidebar-selected-bg: color-mix(in srgb, var(--ifm-color-primary) 14%, transparent);
9+
10+
@include bp('tablet') {
11+
--doc-sidebar-line-x: 2.4rem;
12+
}
413

514
&.thin-scrollbar {
615
padding: 1rem 0 0;
@@ -16,6 +25,11 @@
1625
}
1726

1827
&__list {
28+
/* The tree line is positioned relative to the list's padding box.
29+
* We store the current list padding-left so selected-row highlights can
30+
* compute a matching x-offset in the row coordinate space. */
31+
--doc-sidebar-list-padding-left: 0px;
32+
1933
padding-top: 0;
2034
padding-bottom: 0;
2135

@@ -26,9 +40,11 @@
2640

2741
.theme-doc-sidebar-item-category-level-1 & {
2842
padding-left: calc(var(--ifm-menu-link-padding-horizontal) / 4);
43+
--doc-sidebar-list-padding-left: calc(var(--ifm-menu-link-padding-horizontal) / 4);
2944

3045
@include bp('tablet') {
3146
padding-left: var(--ifm-menu-link-padding-horizontal);
47+
--doc-sidebar-list-padding-left: var(--ifm-menu-link-padding-horizontal);
3248
}
3349
}
3450

@@ -38,9 +54,11 @@
3854
.theme-doc-sidebar-item-category-level-5 &,
3955
.theme-doc-sidebar-item-category-level-6 & {
4056
padding-left: calc(var(--ifm-menu-link-padding-horizontal) / 4);
57+
--doc-sidebar-list-padding-left: calc(var(--ifm-menu-link-padding-horizontal) / 4);
4158

4259
@include bp('tablet') {
4360
padding-left: calc(var(--ifm-menu-link-padding-horizontal) / 2);
61+
--doc-sidebar-list-padding-left: calc(var(--ifm-menu-link-padding-horizontal) / 2);
4462
padding-top: 0;
4563
padding-bottom: 0;
4664
}
@@ -51,6 +69,7 @@
5169
padding-bottom: 0rem;
5270
margin-bottom: 0.25rem;
5371
padding-left: var(--ifm-menu-link-padding-horizontal);
72+
--doc-sidebar-list-padding-left: var(--ifm-menu-link-padding-horizontal);
5473
}
5574

5675
/* Vertical guide lines (tree lines) for expanded category trees (level 1+). */
@@ -67,18 +86,12 @@
6786
position: absolute;
6887
top: 0;
6988
bottom: 0;
70-
left: 1.6rem; /* align with default link text start */
89+
left: var(--doc-sidebar-line-x);
7190
width: 1px;
7291
background: var(--doc-sidebar-guide-line-color);
7392
pointer-events: none;
7493
opacity: 0;
7594
}
76-
77-
@include bp('tablet') {
78-
&::before {
79-
left: 2.4rem; /* align with tablet link text start */
80-
}
81-
}
8295
}
8396

8497
.menu__list-item.theme-doc-sidebar-item-category-level-1:not(.menu__list-item--collapsed) > .menu__list::before,
@@ -100,6 +113,7 @@
100113
&__list-item {
101114
position: relative;
102115
z-index: 1;
116+
width: 100%;
103117

104118
/* Reduce top-level nav emphasis (level 1). */
105119
&.theme-doc-sidebar-item-category-level-1 > .menu__list-item-collapsible > .menu__link {
@@ -113,13 +127,7 @@
113127
font-weight: 400;
114128
}
115129

116-
/* Active page + active ancestor path: bold for clearer orientation. */
117-
&.menu__list-item--active > .menu__list-item-collapsible > .menu__link,
118-
&.menu__list-item--active > .menu__link {
119-
color: var(--ifm-menu-color-active);
120-
/* Parent/ancestor path: keep it emphasized, but less prominent than the active page */
121-
font-weight: 600 !important;
122-
}
130+
/* Only the active page should be bold; keep ancestor path normal weight. */
123131

124132
&-collapsible {
125133
border-radius: 0;
@@ -185,6 +193,10 @@
185193
line-height: 124%;
186194
text-decoration: none;
187195
font-weight: 500;
196+
/* Ensure background fills the full row */
197+
display: flex;
198+
width: 100%;
199+
box-sizing: border-box;
188200
padding: 0.6rem 1.6rem;
189201
border-radius: 0;
190202
text-decoration: none !important;
@@ -195,9 +207,10 @@
195207

196208
&--active {
197209
color: var(--ifm-menu-color-active);
198-
font-weight: 700 !important;
199-
/* Ensure it still *looks* bold even if the font doesn't ship a true 700 weight */
200-
text-shadow: 0 0 0 currentColor;
210+
/* Docusaurus applies `menu__link--active` to the active page *and* its ancestor
211+
* categories. Keep active color, but don't bold the whole ancestor path. */
212+
font-weight: inherit;
213+
text-shadow: none;
201214
/* Selected item: no bar / no filled background */
202215
background-image: none !important;
203216
background-color: transparent !important;
@@ -207,9 +220,23 @@
207220
}
208221
}
209222

223+
/* Only the actual selected page link should be bold. */
224+
&[aria-current='page'] {
225+
/* Selected page: keep the *normal* text color (no green), rely on highlight only */
226+
font-weight: inherit;
227+
text-shadow: none;
228+
color: var(--ifm-menu-color) !important;
229+
230+
&:hover,
231+
&:focus-visible {
232+
color: var(--ifm-menu-color) !important;
233+
text-shadow: none;
234+
}
235+
}
236+
210237
/* Hover: slight contrast, no "highlight bar" */
211-
&:hover,
212-
&:focus-visible {
238+
&:hover:not([aria-current='page']),
239+
&:focus-visible:not([aria-current='page']) {
213240
background-image: none !important;
214241
background-color: transparent !important;
215242
background: transparent !important; /* override Infima `background:` shorthand */
@@ -219,6 +246,57 @@
219246
}
220247
}
221248

249+
/* Selected item highlight: apply to the *row header only* (not the whole <li>),
250+
* otherwise expanded categories would tint their entire subtree. We also avoid
251+
* relying on `:has()` by using `data-current-page` (stamped by our swizzled components). */
252+
253+
/* Link items: the row is the direct <a> child. */
254+
.menu__list-item[data-current-page='true'] > a.menu__link {
255+
position: relative;
256+
}
257+
.menu__list-item[data-current-page='true'] > a.menu__link::before {
258+
content: '';
259+
position: absolute;
260+
top: 0;
261+
bottom: 0;
262+
/* Convert list-space line position to row-space by subtracting the list padding-left. */
263+
left: calc(var(--doc-sidebar-line-x) - var(--doc-sidebar-list-padding-left) + 0.5px);
264+
right: 0;
265+
background: var(--doc-sidebar-selected-bg);
266+
pointer-events: none;
267+
z-index: 0;
268+
}
269+
270+
/* Top-level link items (level 1): no meaningful tree line on the row, so let the
271+
* selected highlight run full-width. */
272+
.menu__list-item.theme-doc-sidebar-item-link-level-1[data-current-page='true'] > a.menu__link::before {
273+
left: 0;
274+
}
275+
.menu__list-item[data-current-page='true'] > a.menu__link > * {
276+
position: relative;
277+
z-index: 1;
278+
}
279+
280+
/* Category items: the row header is the collapsible wrapper. */
281+
.menu__list-item[data-current-page='true'] > .menu__list-item-collapsible {
282+
position: relative;
283+
}
284+
.menu__list-item[data-current-page='true'] > .menu__list-item-collapsible::before {
285+
content: '';
286+
position: absolute;
287+
top: 0;
288+
bottom: 0;
289+
left: calc(var(--doc-sidebar-line-x) - var(--doc-sidebar-list-padding-left) + 0.5px);
290+
right: 0;
291+
background: var(--doc-sidebar-selected-bg);
292+
pointer-events: none;
293+
z-index: 0;
294+
}
295+
.menu__list-item[data-current-page='true'] > .menu__list-item-collapsible > * {
296+
position: relative;
297+
z-index: 1;
298+
}
299+
222300
&__caret {
223301
padding: 1rem 2rem 1rem 1rem;
224302
opacity: 0.25;
@@ -247,6 +325,7 @@
247325
/* Dark mode: make tree lines more subtle */
248326
[data-theme='dark'] .menu {
249327
--doc-sidebar-guide-line-color: rgba(255, 255, 255, 0.12);
328+
--doc-sidebar-selected-bg: rgba(186, 242, 74, 0.14);
250329
}
251330

252331
.theme-doc-sidebar-container {

src/theme/DocSidebarItem/Category/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ export default function DocSidebarItemCategory({
142142
'menu__list-item--collapsed': collapsed,
143143
},
144144
className
145-
)}>
145+
)}
146+
// Avoid CSS :has() dependency by stamping state on the row element
147+
data-current-page={isCurrentPage ? 'true' : undefined}
148+
>
146149
<div
147150
className={clsx('menu__list-item-collapsible', {
148151
'menu__list-item-collapsible--active': isCurrentPage,
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React, { type ReactNode } from 'react'
2+
import clsx from 'clsx'
3+
import { ThemeClassNames } from '@docusaurus/theme-common'
4+
import { isActiveSidebarItem } from '@docusaurus/plugin-content-docs/client'
5+
import Link from '@docusaurus/Link'
6+
import isInternalUrl from '@docusaurus/isInternalUrl'
7+
import IconExternalLink from '@theme/Icon/ExternalLink'
8+
import type { Props } from '@theme/DocSidebarItem/Link'
9+
10+
import styles from './styles.module.css'
11+
12+
function LinkLabel({ label }: { label: string }) {
13+
return (
14+
<span title={label} className={styles.linkLabel}>
15+
{label}
16+
</span>
17+
)
18+
}
19+
20+
export default function DocSidebarItemLink({
21+
item,
22+
onItemClick,
23+
activePath,
24+
level,
25+
index,
26+
...props
27+
}: Props): ReactNode {
28+
const { href, label, className, autoAddBaseUrl } = item
29+
const isActive = isActiveSidebarItem(item, activePath)
30+
const isInternalLink = isInternalUrl(href)
31+
32+
return (
33+
<li
34+
className={clsx(
35+
ThemeClassNames.docs.docSidebarItemLink,
36+
ThemeClassNames.docs.docSidebarItemLinkLevel(level),
37+
'menu__list-item',
38+
className
39+
)}
40+
// Avoid CSS :has() dependency by stamping state on the row element
41+
data-current-page={isActive ? 'true' : undefined}
42+
key={label}
43+
>
44+
<Link
45+
className={clsx('menu__link', !isInternalLink && styles.menuExternalLink, {
46+
'menu__link--active': isActive,
47+
})}
48+
autoAddBaseUrl={autoAddBaseUrl}
49+
aria-current={isActive ? 'page' : undefined}
50+
to={href}
51+
{...(isInternalLink && {
52+
onClick: onItemClick ? () => onItemClick(item) : undefined,
53+
})}
54+
{...props}
55+
>
56+
<LinkLabel label={label} />
57+
{!isInternalLink && <IconExternalLink />}
58+
</Link>
59+
</li>
60+
)
61+
}
62+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
.menuExternalLink {
9+
align-items: center;
10+
}
11+
12+
.linkLabel {
13+
overflow: hidden;
14+
display: -webkit-box;
15+
line-clamp: 2;
16+
-webkit-box-orient: vertical;
17+
-webkit-line-clamp: 2;
18+
}
19+

0 commit comments

Comments
 (0)