Skip to content

Commit 8436352

Browse files
committed
Make sidesheet work well in docs embed
1 parent f78e9ca commit 8436352

File tree

8 files changed

+26
-38
lines changed

8 files changed

+26
-38
lines changed

packages/gitbook/src/app/sites/dynamic/[mode]/[siteURL]/[siteData]/(content)/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export default async function SiteDynamicLayout({
2323

2424
return (
2525
<CustomizationRootLayout
26-
className="site-background"
26+
htmlClassName="sheet-open:gutter-stable"
27+
bodyClassName="site-background"
2728
forcedTheme={forcedTheme}
2829
context={context}
2930
>

packages/gitbook/src/app/sites/static/[mode]/[siteURL]/[siteData]/(content)/layout.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ export default async function SiteStaticLayout({
1919
const withTracking = shouldTrackEvents();
2020

2121
return (
22-
<CustomizationRootLayout className="site-background" context={context}>
22+
<CustomizationRootLayout
23+
htmlClassName="sheet-open:gutter-stable"
24+
bodyClassName="site-background"
25+
context={context}
26+
>
2327
<SiteLayout
2428
context={context}
2529
withTracking={withTracking}

packages/gitbook/src/components/AIChat/AIChat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function AIChat() {
8686
'ai-chat mx-auto not-hydrated:hidden w-96 max-w-full pl-8 transition-[width] duration-300 ease-quint lg:max-xl:w-80'
8787
)}
8888
>
89-
<EmbeddableFrame className="relative shrink-0 border-tint-subtle border-l to-tint-base transition-all duration-300 max-lg:circular-corners:rounded-3xl max-lg:rounded-corners:rounded-md max-lg:border lg:w-80 xl:w-96">
89+
<EmbeddableFrame className="relative shrink-0 border-tint-subtle border-l to-tint-base">
9090
<EmbeddableFrameMain>
9191
<EmbeddableFrameHeader>
9292
<AIChatDynamicIcon trademark={config.trademark} />

packages/gitbook/src/components/Embeddable/EmbeddableDocsPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export async function EmbeddableDocsPage(props: EmbeddableDocsPageProps) {
7979
contentClassName="p-4"
8080
fadeEdges={context.sections ? [] : ['leading']}
8181
>
82-
<TableOfContents className="pt-0" context={context} />
82+
<TableOfContents context={context} />
8383
<PageBody
8484
context={context}
8585
page={page}

packages/gitbook/src/components/Header/HeaderMobileMenu.tsx

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,20 @@
11
'use client';
22
import { usePathname } from 'next/navigation';
3-
import { useEffect, useRef, useState } from 'react';
3+
import { useEffect } from 'react';
44

55
import { tString, useLanguage } from '@/intl/client';
66

7-
import { useScrollListener } from '../hooks/useScrollListener';
87
import { Button, type ButtonProps } from '../primitives';
98

109
const globalClassName = 'navigation-open';
1110

12-
const SCROLL_DISTANCE = 320;
13-
1411
/**
1512
* Button to show/hide the table of content on mobile.
1613
*/
1714
export function HeaderMobileMenu(props: ButtonProps) {
1815
const language = useLanguage();
1916

2017
const pathname = usePathname();
21-
const hasScrollRef = useRef(false);
22-
23-
const [isOpen, setIsOpen] = useState(false);
24-
25-
const toggleNavigation = () => {
26-
if (!hasScrollRef.current && document.body.classList.contains(globalClassName)) {
27-
document.body.classList.remove(globalClassName);
28-
setIsOpen(false);
29-
} else {
30-
document.body.classList.add(globalClassName);
31-
setIsOpen(true);
32-
}
33-
};
34-
35-
const windowRef = useRef(typeof window === 'undefined' ? null : window);
36-
useScrollListener(() => {
37-
hasScrollRef.current = window.scrollY >= SCROLL_DISTANCE;
38-
}, windowRef);
3918

4019
// Close the navigation when navigating to a page
4120
useEffect(() => {
@@ -49,8 +28,10 @@ export function HeaderMobileMenu(props: ButtonProps) {
4928
variant="blank"
5029
size="default"
5130
label={tString(language, 'table_of_contents_button_label')}
52-
onClick={toggleNavigation}
53-
active={isOpen}
31+
onClick={() => {
32+
document.body.classList.toggle(globalClassName);
33+
}}
34+
// Since the button is hidden behind the TOC after toggling, we don't need to keep track of its active state.
5435
{...props}
5536
/>
5637
);

packages/gitbook/src/components/RootLayout/CustomizationRootLayout.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ function preloadFont(fontData: FontData) {
5757
* It takes care of setting the theme and the language.
5858
*/
5959
export async function CustomizationRootLayout(props: {
60+
/** The class name to apply to the html element. */
61+
htmlClassName?: string;
6062
/** The class name to apply to the body element. */
61-
className?: string;
63+
bodyClassName?: string;
6264
forcedTheme?: CustomizationThemeMode | null;
6365
context: GitBookAnyContext;
6466
children: React.ReactNode;
6567
}) {
66-
const { className, context, forcedTheme, children } = props;
68+
const { htmlClassName, bodyClassName, context, forcedTheme, children } = props;
6769
const customization =
6870
'customization' in context ? context.customization : defaultCustomization();
6971

@@ -91,7 +93,6 @@ export async function CustomizationRootLayout(props: {
9193
suppressHydrationWarning
9294
lang={customization.internationalization.locale}
9395
className={tcls(
94-
'sheet-open:gutter-stable',
9596
customization.styling.corners && `${customization.styling.corners}-corners`,
9697
'theme' in customization.styling && `theme-${customization.styling.theme}`,
9798
tintColor ? ' tint' : 'no-tint',
@@ -108,7 +109,8 @@ export async function CustomizationRootLayout(props: {
108109
// Set the dark/light class statically to avoid flashing and make it work when JS is disabled
109110
(forcedTheme ?? customization.themes.default) === CustomizationThemeMode.Dark
110111
? 'dark'
111-
: ''
112+
: '',
113+
htmlClassName
112114
)}
113115
>
114116
<head>
@@ -180,7 +182,7 @@ export async function CustomizationRootLayout(props: {
180182
}
181183
`}</style>
182184
</head>
183-
<body className={tcls(className, 'sheet-open:overflow-hidden')}>
185+
<body className={tcls(bodyClassName, 'sheet-open:overflow-hidden')}>
184186
<IconsProvider
185187
assetsURL={GITBOOK_ICONS_URL}
186188
assetsURLToken={GITBOOK_ICONS_TOKEN}

packages/gitbook/src/components/primitives/HoverCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function HoverCard(
2828
<RadixHoverCard.Portal>
2929
<RadixHoverCard.Content
3030
side={props.side ?? 'top'}
31-
className="pointer-events-none z-40 w-screen max-w-md animate-scale-in px-4 data-[state='closed']:animate-scale-out sm:w-auto"
31+
className="pointer-events-none z-50 w-screen max-w-md animate-scale-in px-4 data-[state='closed']:animate-scale-out sm:w-auto"
3232
>
3333
<div
3434
className={tcls(

packages/gitbook/src/components/primitives/SideSheet.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ export function SideSheet(
110110

111111
return (
112112
<>
113-
{isModal && withScrim ? (
113+
{withScrim ? (
114114
<SideSheetScrim
115-
className={isOpen ? '' : 'hidden opacity-0 backdrop-blur-none'}
115+
className={tcls(isModal && isOpen ? '' : 'hidden opacity-0 backdrop-blur-none')}
116116
onClick={handleClose}
117117
/>
118118
) : null}
@@ -138,11 +138,11 @@ export function SideSheet(
138138
{...rest}
139139
>
140140
{children}
141-
{isModal && withCloseButton ? (
141+
{withCloseButton ? (
142142
<SideSheetCloseButton
143143
className={tcls(
144144
side === 'left' ? 'left-full ml-4' : 'right-full mr-4',
145-
isOpen ? 'animate-blur-in' : 'hidden animate-blur-out'
145+
isModal && isOpen ? 'animate-blur-in' : 'hidden animate-blur-out'
146146
)}
147147
onClick={handleClose}
148148
/>

0 commit comments

Comments
 (0)