Skip to content

Commit 65de2fd

Browse files
committed
refactor(web): improve layout structure and scrolling behavior in DocsLayout component
1 parent 6ace861 commit 65de2fd

1 file changed

Lines changed: 25 additions & 29 deletions

File tree

apps/web/src/components/layouts/docs-layout.tsx

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function DocsSidebar() {
102102
const location = useLocation();
103103

104104
return (
105-
<div className="w-72 border-r h-[calc(100vh-4rem)] sticky top-0">
105+
<div className="w-72 border-r h-[calc(100vh-4rem)]">
106106
<ScrollArea className="h-full">
107107
<div className="p-4 space-y-2">
108108
{docsSections.map((section) => (
@@ -149,26 +149,24 @@ function TableOfContents({ items }: { items: TableOfContentsItem[] }) {
149149
if (!items.length) return null;
150150

151151
return (
152-
<div className="w-56 shrink-0">
153-
<div className="space-y-4">
154-
<div>
155-
<h4 className="text-sm font-semibold mb-2">On this page</h4>
156-
<div className="space-y-2">
157-
{items.map((item) => (
158-
<a
159-
key={item.id}
160-
href={`#${item.id}`}
161-
className={cn(
162-
"block text-xs text-muted-foreground hover:text-foreground transition-colors",
163-
item.level === 2 && "pl-0",
164-
item.level === 3 && "pl-3",
165-
item.level === 4 && "pl-6"
166-
)}
167-
>
168-
{item.title}
169-
</a>
170-
))}
171-
</div>
152+
<div className="space-y-4">
153+
<div>
154+
<h4 className="text-sm font-semibold mb-2">On this page</h4>
155+
<div className="space-y-2">
156+
{items.map((item) => (
157+
<a
158+
key={item.id}
159+
href={`#${item.id}`}
160+
className={cn(
161+
"block text-xs text-muted-foreground hover:text-foreground transition-colors",
162+
item.level === 2 && "pl-0",
163+
item.level === 3 && "pl-3",
164+
item.level === 4 && "pl-6"
165+
)}
166+
>
167+
{item.title}
168+
</a>
169+
))}
172170
</div>
173171
</div>
174172
</div>
@@ -221,9 +219,7 @@ export function DocsLayout({
221219
// Scroll to top when location changes
222220
useEffect(() => {
223221
// Find the main scroll container and scroll it to top
224-
const scrollContainer = document.querySelector(
225-
".overflow-y-auto, .overflow-auto"
226-
);
222+
const scrollContainer = document.querySelector("[data-docs-main-content]");
227223
if (scrollContainer) {
228224
scrollContainer.scrollTop = 0;
229225
} else {
@@ -245,15 +241,15 @@ export function DocsLayout({
245241

246242
return (
247243
<AppLayout>
248-
<div className="flex overflow-x-hidden">
244+
<div className="flex h-[calc(100vh-4rem)] overflow-hidden">
249245
{/* Desktop Sidebar */}
250246
<div className="hidden md:block">
251247
<DocsSidebar />
252248
</div>
253249

254250
{/* Main Content */}
255-
<main className="flex-1 max-w-5xl min-w-0">
256-
<div className="py-10 px-6">
251+
<main className="flex-1 min-w-0 overflow-y-auto" data-docs-main-content>
252+
<div className="max-w-5xl mx-auto py-10 px-6">
257253
{/* Header */}
258254
<div className="space-y-4 mb-8">
259255
<div className="flex items-center gap-2">
@@ -278,8 +274,8 @@ export function DocsLayout({
278274
</main>
279275

280276
{/* Table of Contents */}
281-
<aside className="hidden xl:block">
282-
<div className="sticky top-6 p-6">
277+
<aside className="hidden xl:block w-56 shrink-0">
278+
<div className="sticky top-6 p-6 h-[calc(100vh-6rem)] overflow-y-auto">
283279
<TableOfContents items={tableOfContents} />
284280
</div>
285281
</aside>

0 commit comments

Comments
 (0)