Skip to content

Display sidebar on no-TOC pages #2942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eleven-pants-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'gitbook': patch
---

Display sidebar on no-TOC pages
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
}

.openapi-column-preview-body {
@apply flex flex-col gap-4 sticky top-4 site-header:top-20 site-header-sections:top-32 page-api-block:xl:max-2xl:top-32 print-mode:static;
@apply flex flex-col gap-4 sticky top-4 site-header:top-20 site-header-sections:page-has-toc:top-32 page-api-block:xl:max-2xl:top-32 print-mode:static;
}

.openapi-column-preview pre {
Expand Down
36 changes: 18 additions & 18 deletions packages/gitbook/src/components/Header/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ export function Dropdown<E extends HTMLElement>(props: {
aria-orientation="vertical"
aria-labelledby={dropdownId}
className={tcls(
'w-52',
'max-h-80',
'flex',
'absolute',
'top-full',
'left-0',
'z-20',
'origin-top-left',
'invisible',
'transition-opacity',
Expand All @@ -54,22 +52,24 @@ export function Dropdown<E extends HTMLElement>(props: {
className
)}
>
<div
className={tcls(
'mt-2',
'w-full',
'bg-tint-base',
'rounded-lg',
'straight-corners:rounded-sm',
'p-2',
'shadow-1xs',
'overflow-auto',
'ring-1',
'ring-tint-subtle',
'focus:outline-none'
)}
>
{children}
<div className="fixed z-50 w-52">
<div
className={tcls(
'mt-2',
'w-full',
'bg-tint-base',
'rounded-lg',
'straight-corners:rounded-sm',
'p-2',
'shadow-1xs',
'overflow-auto',
'ring-1',
'ring-tint-subtle',
'focus:outline-none'
)}
>
{children}
</div>
</div>
</div>
</div>
Expand Down
65 changes: 45 additions & 20 deletions packages/gitbook/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { SpacesDropdown } from './SpacesDropdown';
export function Header(props: { context: GitBookSiteContext; withTopHeader?: boolean }) {
const { context, withTopHeader } = props;
const { siteSpace, siteSpaces, sections, customization } = context;
const isMultiVariants = siteSpaces.length > 1;

return (
<header
Expand All @@ -31,7 +30,7 @@ export function Header(props: { context: GitBookSiteContext; withTopHeader?: boo
`h-[${HEADER_HEIGHT_DESKTOP}px]`,
'sticky',
'top-0',
'z-10',
'z-30',
'w-full',
'flex-none',
'shadow-[0px_1px_0px]',
Expand Down Expand Up @@ -68,14 +67,12 @@ export function Header(props: { context: GitBookSiteContext; withTopHeader?: boo
'py-3',
'min-h-16',
'sm:h-16',
isMultiVariants && 'page-no-toc:max-[400px]:flex-wrap',
CONTAINER_STYLE
)}
>
<div
className={tcls(
'flex max-w-full',
isMultiVariants && 'page-no-toc:max-[400px]:w-full',
'min-w-0 shrink items-center justify-start gap-2 lg:gap-4'
)}
>
Expand All @@ -86,25 +83,13 @@ export function Header(props: { context: GitBookSiteContext; withTopHeader?: boo
'text-tint-strong',
'theme-bold:text-header-link',
'hover:bg-tint-hover',
'theme-bold:hover:bg-header-link/3'
'theme-bold:hover:bg-header-link/3',
'page-no-toc:hidden'
)}
/>
<HeaderLogo context={context} />
</div>

{isMultiVariants && (
<div className="mr-auto page-no-toc:flex hidden">
<SpacesDropdown
context={context}
siteSpace={siteSpace}
siteSpaces={siteSpaces}
className={
'theme-bold:bg-header-link/2 theme-bold:text-header-link theme-bold:ring-header-link/4 theme-bold:group-focus-within/dropdown:bg-header-link/3 theme-bold:group-focus-within/dropdown:text-header-link theme-bold:group-focus-within/dropdown:ring-header-link/6 theme-bold:group-hover/dropdown:bg-header-link/3 theme-bold:group-hover/dropdown:text-header-link theme-bold:group-hover/dropdown:ring-header-link/6 theme-bold:contrast-more:bg-header-background theme-bold:contrast-more:text-header-link theme-bold:contrast-more:ring-header-link theme-bold:contrast-more:group-hover/dropdown:text-header-link theme-bold:contrast-more:group-hover/dropdown:ring-header-link theme-bold:contrast-more:group-focus-within/dropdown:text-header-link theme-bold:contrast-more:group-focus-within/dropdown:ring-header-link theme-bold:dark:bg-header-link/2 theme-bold:dark:text-header-link theme-bold:dark:ring-header-link/4 theme-bold:dark:group-hover/dropdown:bg-header-link/3 theme-bold:dark:group-hover/dropdown:text-header-link theme-bold:dark:group-hover/dropdown:ring-header-link/6 theme-bold:contrast-more:dark:group-hover/dropdown:text-header-link theme-bold:contrast-more:dark:group-hover/dropdown:ring-header-link theme-bold:dark:group-focus-within/dropdown:bg-header-link/3 theme-bold:dark:group-focus-within/dropdown:text-header-link theme-bold:dark:group-focus-within/dropdown:ring-header-link/6 theme-bold:contrast-more:dark:group-focus-within/dropdown:text-header-link theme-bold:contrast-more:dark:group-focus-within/dropdown:ring-header-link'
}
/>
</div>
)}

{customization.header.links.length > 0 && (
<HeaderLinks>
{customization.header.links.map((link, index) => {
Expand Down Expand Up @@ -169,8 +154,48 @@ export function Header(props: { context: GitBookSiteContext; withTopHeader?: boo
</div>
</div>
</div>
{sections ? (
<SiteSectionTabs sections={encodeClientSiteSections(context, sections)} />

{sections || siteSpaces.length > 1 ? (
<div
className={tcls(
'w-full',
'overflow-x-scroll',
'overflow-y-hidden',
'hide-scroll',
'-mb-4 pb-4', // Positive padding / negative margin allows the navigation menu indicator to show in a scroll viewƒ
!sections ? ['hidden', 'page-no-toc:flex'] : 'flex'
)}
>
<div
className={tcls(
CONTAINER_STYLE,
'page-default-width:max-w-[unset]',
'grow',
'flex',
'items-end',
'page-default-width:2xl:px-[calc((100%-1536px+4rem)/2)]'
)}
>
{siteSpaces.length > 1 && (
<div
id="variants"
className="my-2 mr-5 page-no-toc:flex hidden grow border-tint border-r pr-5 *:grow only:mr-0 only:border-none only:pr-0 sm:max-w-64"
>
<SpacesDropdown
context={context}
siteSpace={siteSpace}
siteSpaces={siteSpaces}
className="w-full grow py-1"
/>
</div>
)}
{sections && (
<SiteSectionTabs
sections={encodeClientSiteSections(context, sections)}
/>
)}
</div>
</div>
) : null}
</header>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/gitbook/src/components/Header/HeaderLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export async function HeaderLogo(props: HeaderLogoProps) {
'min-w-0',
'max-w-40',
'lg:max-w-64',
'site-header-none:page-no-toc:lg:max-w-56',
'max-h-10',
'lg:max-h-12',
'h-full',
Expand Down Expand Up @@ -84,7 +85,7 @@ function LogoFallback(props: HeaderLogoProps) {
<div
className={tcls(
'text-pretty',
'line-clamp-3',
'line-clamp-2',
'tracking-tight',
'max-w-[18ch]',
'lg:max-w-[24ch]',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export function HeaderMobileMenu(props: Partial<React.ButtonHTMLAttributes<HTMLB
'px-2',
'rounded',
'straight-corners:rounded-sm',
'page-no-toc:hidden',
props.className
)}
>
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/src/components/Header/SpacesDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function SpacesDropdown(props: {
className
)}
>
<span className={tcls('line-clamp-2', 'grow')}>{siteSpace.title}</span>
<span className={tcls('truncate', 'grow')}>{siteSpace.title}</span>
<DropdownChevron />
</div>
)}
Expand Down
3 changes: 3 additions & 0 deletions packages/gitbook/src/components/PageAside/PageAside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ export function PageAside(props: {
'group/aside',
'hidden',
'xl:flex',
// 'page-no-toc:lg:flex',
'flex-col',
'basis-56',
// 'page-no-toc:basis-40',
// 'page-no-toc:xl:basis-56',
'grow-0',
'shrink-0',
'break-anywhere', // To prevent long words in headings from breaking the layout
Expand Down
8 changes: 4 additions & 4 deletions packages/gitbook/src/components/PageBody/PageBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ export function PageBody(props: {
'page-api-block:xl:max-2xl:pr-0',
// Max size to ensure one column in api is aligned with rest of content (2 x 3xl) + (gap-3 + 2) * px-12
'page-api-block:max-w-[1654px]',
'page-api-block:mx-auto',
'page-api-block:mx-auto'

page.layout.tableOfContents ? null : 'xl:ml-56'
// page.layout.tableOfContents ? null : 'xl:ml-56'
) +
(asFullWidth ? ' page-full-width' : '') +
(!page.layout.tableOfContents ? ' page-no-toc' : '')
(asFullWidth ? ' page-full-width' : ' page-default-width') +
(!page.layout.tableOfContents ? ' page-no-toc' : ' page-has-toc')
}
>
<PreservePageLayout asFullWidth={asFullWidth} />
Expand Down
6 changes: 5 additions & 1 deletion packages/gitbook/src/components/PageBody/PageCover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ export async function PageCover(props: {
'sm:-mx-6',
'md:-mx-8',
'-lg:mr-8',
page.layout.tableOfContents ? 'lg:ml-0' : null,
'lg:ml-0',
!page.layout.tableOfContents &&
context.customization.header.preset !== 'none'
? 'lg:-ml-64'
: null,
]
: ['sm:mx-auto', 'max-w-3xl', 'sm:rounded-md', 'mb-8']
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function CustomizationRootLayout(props: {
lang={customization.internationalization.locale}
className={tcls(
customization.header.preset === CustomizationHeaderPreset.None
? null
? 'site-header-none'
: 'scroll-pt-[76px]', // Take the sticky header in consideration for the scrolling
customization.styling.corners === CustomizationCorners.Straight
? ' straight-corners'
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/src/components/Search/SearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function SearchModal(props: SearchModalProps) {
'bg-tint-12/4',
'dark:bg-tint-1/6',
'backdrop-blur-2xl',
'z-30',
'z-50',
'px-4',
'pt-4',
'md:pt-[min(8vh,6rem)]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ export function SiteSectionGroupItem(props: {
return (
<>
<button
type="button"
onClick={(event) => {
event.preventDefault();
event.stopPropagation();
setIsVisible((prev) => !prev);
}}
className={`group/section-link flex w-full flex-row items-center gap-3 rounded-md straight-corners:rounded-none px-3 py-2 transition-all hover:bg-tint-hover hover:text-tint-strong contrast-more:hover:ring-1 contrast-more:hover:ring-tint ${
className={`group/section-link flex w-full flex-row items-center gap-3 rounded-md straight-corners:rounded-none px-3 py-2 text-left transition-all hover:bg-tint-hover hover:text-tint-strong contrast-more:hover:ring-1 contrast-more:hover:ring-tint ${
isActiveGroup
? 'font-semibold text-primary hover:bg-primary-hover hover:text-primary-strong contrast-more:text-primary-strong contrast-more:hover:ring-1 contrast-more:hover:ring-primary-hover'
: null
Expand Down
Loading