Skip to content

Commit b554d7d

Browse files
authored
Add isRoot prop to PagesList for root header offset (#3759)
1 parent 9568b8a commit b554d7d

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import { tcls } from '@/lib/tailwind';
77
import { PagesList } from './PagesList';
88
import { TOCPageIcon } from './TOCPageIcon';
99

10-
export function PageGroupItem(props: { page: ClientTOCPageGroup }) {
11-
const { page } = props;
10+
export function PageGroupItem(props: { page: ClientTOCPageGroup; isFirst?: boolean }) {
11+
const { page, isFirst } = props;
1212

1313
return (
14-
<li className="group/page-group-item flex flex-col">
14+
<li className="flex flex-col">
1515
<div
1616
className={tcls(
17-
'-top-6 group-first/page-group-item:-mt-6 sticky z-1 flex items-center gap-3 px-3 pt-6',
17+
'-top-6 sticky z-1 flex items-center gap-3 px-3 pt-6',
1818
'font-semibold text-xs uppercase tracking-wide',
1919
'pb-3', // Add extra padding to make the header fade a bit nicer
2020
'-mb-1.5', // Then pull the page items a bit closer, effective bottom padding is 1.5 units / 6px.
@@ -26,7 +26,8 @@ export function PageGroupItem(props: { page: ClientTOCPageGroup }) {
2626
'[html.sidebar-filled.theme-muted_&]:bg-tint-base',
2727
'[html.sidebar-filled.theme-bold.tint_&]:bg-tint-base',
2828
'[html.sidebar-default.theme-gradient_&]:bg-gradient-primary',
29-
'[html.sidebar-default.theme-gradient.tint_&]:bg-gradient-tint'
29+
'[html.sidebar-default.theme-gradient.tint_&]:bg-gradient-tint',
30+
isFirst ? '-mt-6' : ''
3031
)}
3132
>
3233
<TOCPageIcon page={page} />

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ import { PageDocumentItem } from './PageDocumentItem';
99
import { PageGroupItem } from './PageGroupItem';
1010
import { PageLinkItem } from './PageLinkItem';
1111

12-
export function PagesList(props: { pages: ClientTOCPage[]; style?: ClassValue }) {
13-
const { pages, style } = props;
12+
export function PagesList(props: {
13+
pages: ClientTOCPage[];
14+
style?: ClassValue;
15+
isRoot?: boolean;
16+
}) {
17+
const { pages, style, isRoot = false } = props;
1418

1519
return (
1620
<ul className={tcls('flex flex-col gap-y-0.5', style)}>
17-
{pages.map((page) => {
21+
{pages.map((page, idx) => {
1822
switch (page.type) {
1923
case 'document':
2024
return <PageDocumentItem key={page.id} page={page} />;
@@ -23,7 +27,13 @@ export function PagesList(props: { pages: ClientTOCPage[]; style?: ClassValue })
2327
return <PageLinkItem key={page.id} page={page} />;
2428

2529
case 'group':
26-
return <PageGroupItem key={page.id} page={page} />;
30+
return (
31+
<PageGroupItem
32+
key={page.id}
33+
page={page}
34+
isFirst={isRoot && idx === 0}
35+
/>
36+
);
2737

2838
default:
2939
assertNever(page);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export async function TableOfContents(props: {
111111
>
112112
<PagesList
113113
pages={pages}
114+
isRoot={true}
114115
style="page-no-toc:hidden border-tint-subtle sidebar-list-line:border-l"
115116
/>
116117
{customization.trademark.enabled ? (

0 commit comments

Comments
 (0)