Files
Saxon Fletcher 7880c2f079 fix(studio): explorer chat and notebook layout refinements (#50453)
Five layout fixes across Explorer chat, notebooks, and the sidebar.

### Chat

- **Conversation fade overlapped the scrollbar.** The top and bottom
gradients are positioned against the conversation's padding box, which
includes the scroll container's scrollbar gutter, so `inset-x-0` painted
them over the scrollbar. They now stop at the conversation's content
gutter, which `Conversation` owns for both the content and the fades.
- **Composer background bled past the input's radius.** The form paints
the surface behind the textarea but had no radius of its own, so its
square corners showed outside the `rounded-lg` input. It now shares the
radius.
- **Message parts used two different widths.** Wide parts come down to
`max-w-3xl` so every part shares a column, matching `AssistantQueryCell`
and `AssistantNotebookPreview`. `isWide` / `isWideMessagePart` stay in
place with both widths equal, so a part can diverge again later without
rebuilding the mechanism.

### Notebooks

- **Cell controls sat at the container edge.** Each cell centred itself
at its own max width while the grip and add-cell button stayed at the
far left of the full-width row, leaving a large gap. `SortableSection`
takes a `sectionWidth` and carries its control gutter twice — once as
the controls, once as padding on the other side — so the section stays
centred with its controls immediately beside it. Cell widths are
unchanged (prose `48rem`, query `72rem`); set them equal and the two
cell types' controls line up on their own.

The controls stay in flow rather than floating in an outside gutter, so
on a viewport narrower than the cap the row just fills the space instead
of clipping the controls into the padding.

### Sidebar

- **Search icon didn't line up with the menu row icons.** The row box
already sits flush with the search input's box, so rows moved from
`pl-3` to `pl-2` to put their icons on the same 8px offset the search
icon uses. Spacing between the input and the list now matches the 12px
side padding.

### Testing

`pnpm --filter studio run typecheck`, Prettier, and 378 tests across
`Explorer`, `ProjectHome`, `AIAssistantPanel`, and `ExplorerLayout`
pass. ESLint warning counts are unchanged from master.

These were reasoned from layout rather than checked in a browser, so
they're worth a look on a preview before merge.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **UI Improvements**
* Updated Explorer layouts with flexible, configurable widths for
notebook and query sections.
  * Refined navigation spacing and padding across Explorer views.
* Centered and standardized AI Assistant preview, query, and message
content widths.
  * Improved chat form styling with rounded corners.
* Adjusted conversation spacing and fade overlays to avoid overlapping
the scrollbar.
* Preserved full-width behavior where appropriate while keeping controls
aligned.

* **Tests**
* Updated layout tests to reflect revised width and alignment behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-17 11:39:30 +08:00

113 lines
3.3 KiB
TypeScript

import { useDndMonitor } from '@dnd-kit/core'
import { useSortable } from '@dnd-kit/sortable'
import { GripVertical } from 'lucide-react'
import type { CSSProperties, PropsWithChildren, ReactNode } from 'react'
import { useEffect, useRef, useState } from 'react'
import { Button, cn, DropdownMenu, DropdownMenuTrigger } from 'ui'
const GRIP_WIDTH_REM = 1.5
const ACTIONS_WIDTH_REM = 1.75
const CONTROL_GAP_REM = 1
export const SortableSection = ({
id,
children,
actions,
sectionWidth,
gripClassName,
gripDropdownContent,
}: PropsWithChildren<{
id: string
/** Caps the section at this width and centres it, with the controls alongside it. */
sectionWidth?: string
gripClassName?: string
actions?: ReactNode
gripDropdownContent?: ReactNode
}>) => {
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
id,
})
const [menuOpen, setMenuOpen] = useState(false)
const isDraggingRef = useRef(false)
const openTimeoutRef = useRef<ReturnType<typeof setTimeout>>(undefined)
useDndMonitor({
onDragStart: (event) => {
if (event.active.id === id) {
isDraggingRef.current = true
clearTimeout(openTimeoutRef.current)
setMenuOpen(false)
}
},
onDragEnd: (event) => {
if (event.active.id === id) isDraggingRef.current = false
},
onDragCancel: (event) => {
if (event.active.id === id) isDraggingRef.current = false
},
})
useEffect(() => () => clearTimeout(openTimeoutRef.current), [])
// Carried twice — once as the controls, once as padding — so the section stays centred.
const gutterRem = (actions ? ACTIONS_WIDTH_REM : 0) + GRIP_WIDTH_REM + CONTROL_GAP_REM
const style: CSSProperties = {
transform: transform
? `translate3d(${Math.round(transform.x)}px, ${Math.round(transform.y)}px, 0)`
: undefined,
transition,
...(sectionWidth && {
marginInline: 'auto',
maxWidth: `calc(${sectionWidth} + ${2 * gutterRem}rem)`,
paddingRight: `${gutterRem}rem`,
}),
}
return (
<div
ref={setNodeRef}
style={style}
className="group relative will-change-transform flex w-full items-start gap-x-4 min-w-0"
>
<div className={cn('flex items-center', gripClassName)}>
{actions}
<DropdownMenu
open={menuOpen}
onOpenChange={(open) => {
clearTimeout(openTimeoutRef.current)
if (!open) {
setMenuOpen(false)
return
}
openTimeoutRef.current = setTimeout(() => {
if (!isDraggingRef.current) setMenuOpen(true)
}, 150)
}}
>
<DropdownMenuTrigger asChild>
<Button
type="button"
variant="text"
aria-label="Drag to reorder section"
className={cn(
'w-6 text-foreground-muted hover:text-foreground cursor-grab active:cursor-grabbing',
'rounded-sm focus-ring'
)}
{...attributes}
{...listeners}
tabIndex={0}
icon={<GripVertical />}
/>
</DropdownMenuTrigger>
{gripDropdownContent}
</DropdownMenu>
</div>
<div className={cn('w-full min-w-0', isDragging && 'opacity-70')}>{children}</div>
</div>
)
}