Skip to content

Commit 92b7668

Browse files
authored
Fix header offset (#2812)
1 parent 3973b1c commit 92b7668

File tree

6 files changed

+37
-60
lines changed

6 files changed

+37
-60
lines changed

.changeset/khaki-bags-shout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'gitbook': patch
3+
---
4+
5+
Improve header offset

packages/gitbook/src/components/DocumentView/OpenAPI/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
}
129129

130130
.openapi-column-preview-body {
131-
@apply flex flex-col gap-4 sticky top-4 space-header:top-20 page-api-block:xl:max-2xl:top-32 print-mode:static;
131+
@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;
132132
}
133133

134134
.openapi-column-preview pre {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export function Header(props: {
3636

3737
return (
3838
<header
39+
id="site-header"
3940
className={tcls(
4041
'flex',
4142
'flex-col',
@@ -50,7 +51,7 @@ export function Header(props: {
5051
'bg-tint-base/9',
5152
'[html.tint.sidebar-filled_&]:bg-tint-subtle/9',
5253
'contrast-more:bg-tint-base',
53-
withTopHeader ? null : 'lg:hidden',
54+
withTopHeader ? null : 'lg:hidden mobile-only',
5455
'text-sm',
5556
'backdrop-blur-lg',
5657
)}

packages/gitbook/src/components/PageAside/PageAside.tsx

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,6 @@ import { Ad } from '../Ads';
2424
import { PageFeedbackForm } from '../PageFeedback';
2525
import { ThemeToggler } from '../ThemeToggler';
2626

27-
function getTopOffset(props: { sectionsHeader: boolean; topHeader: boolean }) {
28-
if (props.topHeader && props.sectionsHeader) {
29-
return 'lg:top-[6.75rem]';
30-
}
31-
32-
if (props.topHeader) {
33-
return 'lg:top-16';
34-
}
35-
36-
return 'lg:top-0';
37-
}
38-
39-
function getMaxHeight(props: { sectionsHeader: boolean; topHeader: boolean }) {
40-
if (props.topHeader && props.sectionsHeader) {
41-
return 'lg:max-h-[calc(100vh_-_6.75rem)]';
42-
}
43-
44-
if (props.topHeader) {
45-
return 'lg:max-h-[calc(100vh_-_4rem)]';
46-
}
47-
48-
return 'lg:max-h-screen';
49-
}
50-
5127
/**
5228
* Aside listing the headings in the document.
5329
*/
@@ -62,20 +38,9 @@ export async function PageAside(props: {
6238
withFullPageCover: boolean;
6339
withPageFeedback: boolean;
6440
}) {
65-
const {
66-
space,
67-
site,
68-
page,
69-
document,
70-
customization,
71-
withHeaderOffset,
72-
withPageFeedback,
73-
context,
74-
} = props;
41+
const { space, site, page, document, customization, withPageFeedback, context } = props;
7542
const language = getSpaceLanguage(customization);
7643

77-
const topOffset = getTopOffset(withHeaderOffset);
78-
const maxHeight = getMaxHeight(withHeaderOffset);
7944
const pdfHref = await getAbsoluteHref(
8045
`~gitbook/pdf?${getPDFUrlSearchParams({
8146
page: page.id,
@@ -97,8 +62,17 @@ export async function PageAside(props: {
9762
'text-tint',
9863
'contrast-more:text-tint-strong',
9964
'sticky',
100-
topOffset,
101-
maxHeight,
65+
// Without header
66+
'lg:top:0',
67+
'lg:max-h-screen',
68+
69+
// With header
70+
'site-header:lg:top-16',
71+
'site-header:lg:max-h-[calc(100vh_-_4rem)]',
72+
73+
// With header & sections
74+
'site-header-sections:lg:top-[6.75rem]',
75+
'site-header-sections:lg:max-h-[calc(100vh_-_6.75rem)]',
10276

10377
// When in api page mode, we display it as an overlay on non-large resolutions
10478
'page-api-block:xl:max-2xl:z-10',
@@ -158,7 +132,9 @@ export async function PageAside(props: {
158132
'pb-12',
159133

160134
'sticky',
161-
topOffset,
135+
'lg:top:0',
136+
'site-header:lg:top-16',
137+
'site-header-sections:lg:top-[6.75rem]',
162138

163139
'gap-6',
164140
'pt-8',

packages/gitbook/src/components/TableOfContents/TableOfContents.tsx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ import { PagesList } from './PagesList';
1717
import { TOCScrollContainer } from './TOCScroller';
1818
import { Trademark } from './Trademark';
1919

20-
function getTopOffset(props: { sectionsHeader: boolean; topHeader: boolean }) {
21-
if (props.topHeader && props.sectionsHeader) {
22-
return 'lg:top-[6.75rem] lg:h-[calc(100vh_-_6.75rem)]';
23-
}
24-
25-
if (props.topHeader) {
26-
return 'lg:top-16 lg:h-[calc(100vh_-_4rem)]';
27-
}
28-
29-
return 'lg:top-0 lg:h-screen';
30-
}
31-
3220
export function TableOfContents(props: {
3321
space: Space;
3422
customization: CustomizationSettings | SiteCustomizationSettings;
@@ -46,8 +34,6 @@ export function TableOfContents(props: {
4634
const { innerHeader, space, customization, pages, ancestors, header, context, headerOffset } =
4735
props;
4836

49-
const topOffset = getTopOffset(headerOffset);
50-
5137
return (
5238
<aside // Sidebar container, responsible for setting the right dimensions and position for the sidebar.
5339
data-testid="table-of-contents"
@@ -61,11 +47,19 @@ export function TableOfContents(props: {
6147
'lg:basis-72',
6248

6349
'relative',
64-
'lg:sticky',
65-
'top-0',
66-
'h-screen',
67-
topOffset,
6850
'z-[1]',
51+
'lg:sticky',
52+
// Without header
53+
'lg:top-0',
54+
'lg:h-screen',
55+
56+
// With header
57+
'site-header:lg:top-16',
58+
'site-header:lg:h-[calc(100vh_-_4rem)]',
59+
60+
// With header and sections
61+
'site-header-sections:lg:top-[6.75rem]',
62+
'site-header-sections:lg:h-[calc(100vh_-_6.75rem)]',
6963

7064
'pt-6',
7165
'pb-4',

packages/gitbook/tailwind.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ const config: Config = {
362362
/**
363363
* Variant when a header is displayed.
364364
*/
365-
addVariant('space-header', 'body:has(header) &');
365+
addVariant('site-header', 'body:has(#site-header:not(.mobile-only)) &');
366+
addVariant('site-header-sections', 'body:has(#site-header:not(.mobile-only) > nav) &');
366367

367368
/**
368369
* Variant for sidebar styles

0 commit comments

Comments
 (0)