Skip to content

Commit dfffa83

Browse files
committed
close sidebar by default on mobile
1 parent 6ef9243 commit dfffa83

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

app/routes/$libraryId/$version.docs.framework.$framework.examples.$.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { seo } from '~/utils/seo'
2020
import { capitalize, slugToTitle } from '~/utils/utils'
2121
import type { GitHubFileNode } from '~/utils/documents.server'
2222
import { z } from 'zod'
23+
import { useWindowSize } from '~/hooks/useWindowSize'
2324

2425
const fileQueryOptions = (repo: string, branch: string, filePath: string) => {
2526
return queryOptions({
@@ -172,7 +173,7 @@ function RouteComponent() {
172173
[queryClient, library.repo, branch]
173174
)
174175

175-
const [sidebarWidth, setSidebarWidth] = React.useState(250)
176+
const [sidebarWidth, setSidebarWidth] = React.useState(200)
176177
const [isResizing, setIsResizing] = React.useState(false)
177178
const sidebarRef = React.useRef<HTMLDivElement>(null)
178179
const startResizeRef = React.useRef({
@@ -243,8 +244,16 @@ function RouteComponent() {
243244
const showNetlify = library.showNetlifyUrl
244245

245246
const [isFullScreen, setIsFullScreen] = React.useState(false)
247+
const windowSize = useWindowSize()
246248
const [isSidebarOpen, setIsSidebarOpen] = React.useState(true)
247249

250+
React.useEffect(() => {
251+
// Default to closed on mobile (width < 768px)
252+
if (windowSize.width && isSidebarOpen) {
253+
setIsSidebarOpen(windowSize.width >= 768)
254+
}
255+
}, [windowSize.width])
256+
248257
// Add escape key handler
249258
React.useEffect(() => {
250259
const handleEsc = (e: KeyboardEvent) => {
@@ -446,7 +455,7 @@ function RouteComponent() {
446455
onMouseDown={startResize}
447456
/>
448457
<div className="flex-1 overflow-auto relative">
449-
<CodeBlock isEmbedded>
458+
<CodeBlock isEmbedded className="max-h-[80dvh]">
450459
<code
451460
className={`language-${overrideExtension(
452461
currentPath.split('.').pop()
@@ -604,7 +613,7 @@ const RenderFileTree = (props: {
604613
: 'hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-300'
605614
}`}
606615
>
607-
<span className="flex-shrink-0">
616+
<span className="flex-shrink-0 select-none">
608617
{file.type === 'dir' ? (
609618
<FolderIcon isOpen={props.expandedFolders.has(file.path)} />
610619
) : (

0 commit comments

Comments
 (0)