Skip to content

Commit bcfa8d8

Browse files
authored
Improve vertical alignment of site items and fix floating page aside (#3560)
1 parent 43766d6 commit bcfa8d8

File tree

8 files changed

+223
-187
lines changed

8 files changed

+223
-187
lines changed

.changeset/moody-badgers-teach.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 vertical alignment of site items and fix floating page aside

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
}
148148

149149
.openapi-column-preview-body {
150-
@apply flex flex-col gap-4 sticky top-4 site-header:top-20 site-header:xl:max-2xl:top-32 site-header-sections:top-32 site-header-sections:xl:max-2xl:top-44 print-mode:static;
150+
@apply flex flex-col gap-4 sticky top-[calc(var(--toc-top-offset)+5rem)] print-mode:static;
151151
}
152152

153153
.openapi-column-preview pre {

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

Lines changed: 202 additions & 178 deletions
Large diffs are not rendered by default.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function ScrollSectionsList(props: { sections: DocumentSection[] }) {
4040
});
4141

4242
return (
43-
<ul className={tcls('sidebar-list-line:border-l', 'border-tint-subtle')}>
43+
<ul className="flex flex-col border-tint-subtle sidebar-list-line:border-l">
4444
{sections.map((section) => (
4545
<motion.li
4646
key={section.id}
@@ -50,6 +50,8 @@ export function ScrollSectionsList(props: { sections: DocumentSection[] }) {
5050
'relative',
5151
'h-fit',
5252
'mt-2',
53+
'first:mt-0',
54+
'mb-0.5',
5355
section.depth > 1 && ['ml-3', 'my-0', 'sidebar-list-line:ml-0']
5456
)}
5557
>

packages/gitbook/src/components/PageBody/PageBody.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function PageBody(props: {
5050
<main
5151
className={tcls(
5252
'relative min-w-0 flex-1',
53-
'mx-auto max-w-screen-2xl py-11',
53+
'mx-auto max-w-screen-2xl py-8',
5454
// Allow words to break if they are too long.
5555
'break-anywhere',
5656
pageWidthWide ? 'page-width-wide 2xl:px-8' : 'page-width-default',

packages/gitbook/src/components/PageBody/PageHeader.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export async function PageHeader(props: {
2828
externalAI: true,
2929
};
3030

31+
const hasAncestors = ancestors.length > 0;
32+
3133
return (
3234
<header
3335
className={tcls(
@@ -37,16 +39,17 @@ export async function PageHeader(props: {
3739
'mb-6',
3840
'space-y-3',
3941
'page-api-block:ml-0',
40-
'page-api-block:max-w-full'
42+
'page-api-block:max-w-full',
43+
hasAncestors ? 'page-has-ancestors' : 'page-no-ancestors'
4144
)}
4245
>
4346
{page.layout.tableOfContents &&
4447
// Show page actions if *any* of the actions are enabled
4548
(withAIChat || pageActions.markdown || pageActions.externalAI) ? (
4649
<div
4750
className={tcls(
48-
'float-right mb-2 ml-4 xl:max-2xl:page-api-block:mr-58',
49-
ancestors.length > 0 ? '-mt-2' : '-mt-3 xs:mt-2'
51+
'float-right ml-4 xl:max-2xl:page-api-block:mr-62',
52+
hasAncestors ? '-my-1.5' : '-mt-3 xs:mt-2'
5053
)}
5154
>
5255
<AIActionsDropdown
@@ -57,7 +60,7 @@ export async function PageHeader(props: {
5760
/>
5861
</div>
5962
) : null}
60-
{ancestors.length > 0 && (
63+
{hasAncestors && (
6164
<nav aria-label="Breadcrumb">
6265
<ol className={tcls('flex', 'flex-wrap', 'items-center', 'gap-2', 'text-tint')}>
6366
{ancestors.map((breadcrumb, index) => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function PageGroupItem(props: { page: ClientTOCPageGroup }) {
1414
<li className="group/page-group-item flex flex-col">
1515
<div
1616
className={tcls(
17-
'-top-5 group-first/page-group-item:-mt-5 sticky z-1 flex items-center gap-3 px-3 pt-6',
17+
'-top-6 group-first/page-group-item:-mt-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.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ export function TableOfContentsScript() {
1818

1919
// Set sticky top position based on header
2020
const headerHeight = header?.offsetHeight ?? 0;
21-
root.style.setProperty('--toc-top-offset', `${headerHeight}px`);
2221

2322
// Start with full viewport height minus header
2423
let height = window.innerHeight - headerHeight;
24+
let offset = headerHeight;
2525

2626
// Subtract visible banner (if any)
2727
if (banner && window.getComputedStyle(banner).display !== 'none') {
2828
const bannerRect = banner.getBoundingClientRect();
2929
if (bannerRect.height > 0 && bannerRect.bottom > 0) {
3030
height -= Math.min(bannerRect.height, bannerRect.bottom);
31+
offset += Math.min(bannerRect.height, bannerRect.bottom);
3132
}
3233
}
3334

@@ -41,6 +42,7 @@ export function TableOfContentsScript() {
4142

4243
// Update height
4344
root.style.setProperty('--toc-height', `${height}px`);
45+
root.style.setProperty('--toc-top-offset', `${offset}px`);
4446
};
4547

4648
// Initial update

0 commit comments

Comments
 (0)