Skip to content

An AI-powered search engine with a generative UI

fix: improve sidebar panel open/close animations

Yoshiki Miura073cc10b0d72
diff --git a/bun.lock b/bun.lock
index 82644506..96095080 100644
--- a/bun.lock
+++ b/bun.lock
@@ -58,7 +58,6 @@
"react-dom": "^19.0.0",
"react-icons": "^5.0.1",
"react-markdown": "^8.0.7",
- "react-resizable-panels": "^3.0.0",
"react-syntax-highlighter": "^15.5.0",
"react-textarea-autosize": "^8.5.3",
"redis": "^4.7.0",
@@ -1633,8 +1632,6 @@
"react-remove-scroll-bar": ["[email protected]", "", { "dependencies": { "react-style-singleton": "^2.2.2", "tslib": "^2.0.0" }, "peerDependencies": { "@types/react": "*", "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" }, "optionalPeers": ["@types/react"] }, "sha512-9r+yi9+mgU33AKcj6IbT9oRCO78WriSj6t/cF8DWBZJ9aOGPOTEDvdUDz1FwKim7QXWwmHqtdHnRJfhAxEG46Q=="],
- "react-resizable-panels": ["[email protected]", "", { "peerDependencies": { "react": "^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc", "react-dom": "^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc" } }, "sha512-6ruCEyw0iqXRcXEktPQn1HL553DNhrdLisCyEdSpzhkmo9bPqZxskJZ+aGeFqJ1qPvIWxuAiag82kvLSb2JZTQ=="],
-
"react-style-singleton": ["[email protected]", "", { "dependencies": { "get-nonce": "^1.0.0", "tslib": "^2.0.0" }, "peerDependencies": { "@types/react": "*", "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react"] }, "sha512-b6jSvxvVnyptAiLjbkWLE/lOnR4lfTtDAl+eUC7RZy+QQWc6wRzIV2CE6xBuMmDxc2qIihtDCZD5NPOFl7fRBQ=="],
"react-syntax-highlighter": ["[email protected]", "", { "dependencies": { "@babel/runtime": "^7.3.1", "highlight.js": "^10.4.1", "highlightjs-vue": "^1.0.0", "lowlight": "^1.17.0", "prismjs": "^1.27.0", "refractor": "^3.6.0" }, "peerDependencies": { "react": ">= 0.14.0" } }, "sha512-OqJ2/vL7lEeV5zTJyG7kmARppUjiB9h9udl4qHQjjgEos66z00Ia0OckwYfRxCSFrW8RJIBnsBwQsHZbVPspqg=="],
diff --git a/components/artifact/artifact-context.tsx b/components/artifact/artifact-context.tsx
index 09b9e8f1..641e0b5b 100644
--- a/components/artifact/artifact-context.tsx
+++ b/components/artifact/artifact-context.tsx
@@ -18,7 +18,10 @@ interface ArtifactState {
isOpen: boolean
}
-type ArtifactAction = { type: 'OPEN'; payload: Part } | { type: 'CLOSE' }
+type ArtifactAction =
+ | { type: 'OPEN'; payload: Part }
+ | { type: 'CLOSE' }
+ | { type: 'CLEAR_CONTENT' }
const initialState: ArtifactState = {
part: null,
@@ -34,6 +37,8 @@ function artifactReducer(
return { part: action.payload, isOpen: true }
case 'CLOSE':
return { ...state, isOpen: false }
+ case 'CLEAR_CONTENT':
+ return { part: null, isOpen: false }
default:
return state
}
@@ -55,6 +60,10 @@ export function ArtifactProvider({ children }: { children: ReactNode }) {
const close = useCallback(() => {
dispatch({ type: 'CLOSE' })
+ // Keep content for animation purposes, clear after transition
+ setTimeout(() => {
+ dispatch({ type: 'CLEAR_CONTENT' })
+ }, 300)
}, [])
// Close artifact when sidebar opens
diff --git a/components/artifact/chat-artifact-container.tsx b/components/artifact/chat-artifact-container.tsx
index 5b8b19da..7f1482f9 100644
--- a/components/artifact/chat-artifact-container.tsx
+++ b/components/artifact/chat-artifact-container.tsx
@@ -1,38 +1,55 @@
'use client'
-import React, { useEffect, useState } from 'react'
+import React, { useCallback, useEffect, useState } from 'react'
-import { useMediaQuery } from '@/lib/hooks/use-media-query'
import { cn } from '@/lib/utils'
-import {
- ResizableHandle,
- ResizablePanel,
- ResizablePanelGroup
-} from '@/components/ui/resizable'
import { SidebarTrigger, useSidebar } from '@/components/ui/sidebar'
import { InspectorDrawer } from '@/components/inspector/inspector-drawer'
import { InspectorPanel } from '@/components/inspector/inspector-panel'
import { useArtifact } from './artifact-context'
+
+const DEFAULT_WIDTH = 500
+const MIN_WIDTH = 400
+const MAX_WIDTH = 800
+
export function ChatArtifactContainer({
children
}: {
children: React.ReactNode
}) {
const { state } = useArtifact()
- const isMobile = useMediaQuery('(max-width: 767px)') // Below md breakpoint
- const [renderPanel, setRenderPanel] = useState(state.isOpen)
- const { open, openMobile, isMobile: isMobileSidebar } = useSidebar()
+ const [width, setWidth] = useState(DEFAULT_WIDTH)
+ const [isResizing, setIsResizing] = useState(false)
+ const { open, isMobile: isMobileSidebar } = useSidebar()
+
+ const startResize = useCallback((e: React.MouseEvent) => {
+ e.preventDefault()
+ setIsResizing(true)
+ }, [])
useEffect(() => {
- if (state.isOpen) {
- setRenderPanel(true)
- } else {
- setRenderPanel(false)
+ if (!isResizing) return
+
+ const handleMouseMove = (e: MouseEvent) => {
+ const newWidth = window.innerWidth - e.clientX
+ setWidth(Math.max(MIN_WIDTH, Math.min(MAX_WIDTH, newWidth)))
+ }
+
+ const handleMouseUp = () => {
+ setIsResizing(false)
}
- }, [state.isOpen])
+
+ document.addEventListener('mousemove', handleMouseMove)
+ document.addEventListener('mouseup', handleMouseUp)
+
+ return () => {
+ document.removeEventListener('mousemove', handleMouseMove)
+ document.removeEventListener('mouseup', handleMouseUp)
+ }
+ }, [isResizing])
return (
<div className="flex-1 min-h-0 h-screen flex">
@@ -41,49 +58,56 @@ export function ChatArtifactContainer({
<SidebarTrigger className="animate-fade-in" />
)}
</div>
- {/* Desktop: Resizable panels (Do not render on mobile) */}
- {!isMobile && (
- <ResizablePanelGroup
- direction="horizontal"
- className="flex flex-1 min-w-0 h-full" // Responsive classes removed
- >
- <ResizablePanel
- className={cn(
- 'min-w-0',
- state.isOpen && 'transition-[flex-basis] duration-200 ease-out'
- )}
- >
- {children}
- </ResizablePanel>
-
- {renderPanel && (
- <>
- <ResizableHandle />
- <ResizablePanel
- className={cn('overflow-hidden', {
- 'animate-slide-in-right': state.isOpen
- })}
- maxSize={50}
- minSize={30}
- defaultSize={40}
- >
- <InspectorPanel />
- </ResizablePanel>
- </>
+
+ {/* Desktop: Independent panels like morphic-studio */}
+ <div className="hidden md:flex flex-1 overflow-hidden">
+ {/* Chat Panel - Independent container */}
+ <div className="flex-1 flex flex-col">{children}</div>
+
+ {/* Resize Handle */}
+ <div
+ className={cn(
+ 'w-1 mx-0.5 my-6 hover:bg-border transition-colors duration-200 cursor-col-resize select-none relative',
+ state.isOpen && state.part
+ ? 'opacity-100'
+ : 'opacity-0 pointer-events-none',
+ isResizing && 'bg-border/50'
)}
- </ResizablePanelGroup>
- )}
+ onMouseDown={startResize}
+ >
+ <div className="absolute inset-0 -left-2 -right-2" />
+ </div>
- {/* Mobile: full-width chat + drawer (Do not render on desktop) */}
- {isMobile && (
- <div className="flex-1 h-full">
- {' '}
- {/* Responsive classes removed */}
- {children}
- {/* ArtifactDrawer checks isMobile internally, no double check needed */}
- <InspectorDrawer />
+ {/* Right Panel - Independent with own animation */}
+ <div
+ className={cn(
+ 'bg-background overflow-hidden',
+ state.isOpen && state.part ? 'opacity-100' : 'w-0 opacity-0',
+ !isResizing && 'transition-all duration-300 ease-out'
+ )}
+ style={{
+ width: state.isOpen && state.part ? `${width}px` : '0px'
+ }}
+ >
+ <div className="h-full" style={{ width: `${width}px` }}>
+ {state.isOpen && state.part && <InspectorPanel />}
+ </div>
</div>
+ </div>
+
+ {/* Resize overlay to prevent text selection */}
+ {isResizing && (
+ <div
+ className="fixed inset-0 cursor-col-resize select-none"
+ style={{ zIndex: 9999 }}
+ />
)}
+
+ {/* Mobile: full-width chat + drawer */}
+ <div className="md:hidden flex-1 h-full">
+ {children}
+ <InspectorDrawer />
+ </div>
</div>
)
}
diff --git a/components/ui/resizable.tsx b/components/ui/resizable.tsx
deleted file mode 100644
index 9aff8691..00000000
--- a/components/ui/resizable.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-'use client'
-
-import * as ResizablePrimitive from 'react-resizable-panels'
-
-import { GripVertical } from 'lucide-react'
-
-import { cn } from '@/lib/utils/index'
-
-const ResizablePanelGroup = ({
- className,
- ...props
-}: React.ComponentProps<typeof ResizablePrimitive.PanelGroup>) => (
- <ResizablePrimitive.PanelGroup
- className={cn(
- 'flex h-full w-full data-[panel-group-direction=vertical]:flex-col',
- className
- )}
- {...props}
- />
-)
-
-const ResizablePanel = ResizablePrimitive.Panel
-
-const ResizableHandle = ({
- withHandle,
- className,
- ...props
-}: React.ComponentProps<typeof ResizablePrimitive.PanelResizeHandle> & {
- withHandle?: boolean
-}) => (
- <ResizablePrimitive.PanelResizeHandle
- className={cn(
- 'relative flex w-px items-center justify-center border border-border/50 hover:border-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90',
- className
- )}
- {...props}
- >
- {withHandle && (
- <div className="z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border">
- <GripVertical className="h-2.5 w-2.5" />
- </div>
- )}
- </ResizablePrimitive.PanelResizeHandle>
-)
-
-export { ResizableHandle, ResizablePanel, ResizablePanelGroup }
diff --git a/package.json b/package.json
index 1775113e..8cc7a608 100644
--- a/package.json
+++ b/package.json
@@ -70,7 +70,6 @@
"react-dom": "^19.0.0",
"react-icons": "^5.0.1",
"react-markdown": "^8.0.7",
- "react-resizable-panels": "^3.0.0",
"react-syntax-highlighter": "^15.5.0",
"react-textarea-autosize": "^8.5.3",
"redis": "^4.7.0",
diff --git a/tailwind.config.ts b/tailwind.config.ts
index e78e7f6d..f8375ebf 100644
--- a/tailwind.config.ts
+++ b/tailwind.config.ts
@@ -137,6 +137,14 @@ const config = {
transform: 'translateX(100%)',
opacity: '0'
}
+ },
+ 'fade-in': {
+ from: {
+ opacity: '0'
+ },
+ to: {
+ opacity: '1'
+ }
}
},
animation: {
@@ -144,8 +152,9 @@ const config = {
'accordion-up': 'accordion-up 0.2s ease-out',
'collapse-down': 'collapse-down 0.1s ease-in-out',
'collapse-up': 'collapse-up 0.1s ease-in-out',
- 'slide-in-right': 'slide-in-right 0.2s ease-out',
- 'slide-out-right': 'slide-out-right 0.2s ease-out'
+ 'slide-in-right': 'slide-in-right 0.3s ease-out',
+ 'slide-out-right': 'slide-out-right 0.3s ease-out',
+ 'fade-in': 'fade-in 0.3s ease-out'
},
fontFamily: {
sans: ['var(--font-sans)', ...fontFamily.sans]