Skip to content

Commit 283bc17

Browse files
authored
hide right sidebar when TOC items are 1 or less (#1335)
Co-authored-by: pourhakimi <[email protected]>
1 parent 81bf3be commit 283bc17

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

pcweb/templates/docpage/docpage.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
"""Template for documentation pages."""
22

3-
from datetime import datetime
43
import functools
4+
from datetime import datetime
55
from typing import Callable
66

7-
import reflex as rx
87
import flexdown
98
import mistletoe
9+
from reflex.components.radix.themes.base import LiteralAccentColor
10+
from reflex.utils.format import to_title_case, to_snake_case
11+
12+
from pcweb.components.button import button
13+
from pcweb.components.icons.icons import get_icon
1014
from pcweb.route import Route, get_path
15+
from pcweb.styles.colors import c_color
1116
from .blocks import *
1217
from .state import FeedbackState
13-
from pcweb.components.icons.icons import get_icon
14-
from pcweb.styles.colors import c_color
15-
from reflex.components.radix.themes.base import LiteralAccentColor
16-
from pcweb.components.button import button
17-
from reflex.utils.format import to_title_case, to_snake_case
1818

1919

2020
def footer_link(text: str, href: str):
@@ -403,9 +403,9 @@ def docpage(contents: Callable[[], Route]) -> Route:
403403
Returns:
404404
The final route with the template applied.
405405
"""
406-
# Get the path to set for the sidebar.
406+
407407
path = get_path(contents) if set_path is None else set_path
408-
# Set the page title.
408+
409409
title = contents.__name__.replace("_", " ").title() if t is None else t
410410

411411
@functools.wraps(contents)
@@ -419,23 +419,19 @@ def wrapper(*args, **kwargs) -> rx.Component:
419419
Returns:
420420
The page with the template applied.
421421
"""
422-
# Import here to avoid circular imports.
422+
423423
from pcweb.components.docpage.navbar import navbar
424424
from pcweb.components.docpage.sidebar import get_prev_next
425425
from pcweb.components.docpage.sidebar import sidebar as sb
426426
from pcweb.components.hosting_banner import HostingBannerState
427427

428-
# Create the docpage sidebar.
429428
sidebar = sb(url=path, width="300px")
430429

431-
# Set the sidebar path for the navbar sidebar.
432430
nav_sidebar = sb(url=path, width="100%")
433431

434-
# Get the previous and next sidebar links.
435432
prev, next = get_prev_next(path)
436433
links = []
437434

438-
# Create the previous component link.
439435
if prev:
440436
next_prev_name = (
441437
prev.alt_name_for_next_prev
@@ -463,7 +459,7 @@ def wrapper(*args, **kwargs) -> rx.Component:
463459
else:
464460
links.append(rx.fragment())
465461
links.append(rx.spacer())
466-
# Create the next component link.
462+
467463
if next:
468464
next_prev_name = (
469465
next.alt_name_for_next_prev
@@ -498,7 +494,10 @@ def wrapper(*args, **kwargs) -> rx.Component:
498494
if isinstance(comp, tuple):
499495
toc, comp = comp
500496

501-
# Return the templated page.
497+
show_right_sidebar = right_sidebar and len(toc) >= 2
498+
499+
main_content_width = " lg:w-[60%]" if show_right_sidebar else " lg:w-full"
500+
502501
return rx.box(
503502
navbar(),
504503
rx.el.main(
@@ -525,12 +524,7 @@ def wrapper(*args, **kwargs) -> rx.Component:
525524
docpage_footer(path=path.rstrip("/")),
526525
class_name="lg:mt-0 mt-6 px-4 lg:px-20",
527526
),
528-
class_name="h-full w-full"
529-
+ (
530-
" lg:w-[60%]"
531-
if right_sidebar
532-
else " lg:max-w-[60%] 2xl:max-w-[100%]"
533-
),
527+
class_name="h-full w-full" + main_content_width,
534528
),
535529
(
536530
rx.el.nav(
@@ -596,19 +590,18 @@ def wrapper(*args, **kwargs) -> rx.Component:
596590
)
597591
+ (
598592
" hidden xl:flex xl:flex-col"
599-
if right_sidebar
593+
if show_right_sidebar and not pseudo_right_bar
600594
else " hidden"
601595
),
602596
)
603-
if not pseudo_right_bar
597+
if not pseudo_right_bar or show_right_sidebar
604598
else rx.spacer()
605599
),
606600
class_name="justify-center flex flex-row mx-auto mt-0 max-w-[94.5em] h-full min-h-screen w-full",
607601
),
608602
class_name="flex flex-col justify-center bg-slate-1 w-full",
609603
)
610604

611-
# Return the route.
612605
components = path.split("/")
613606
category = (
614607
" ".join(

0 commit comments

Comments
 (0)