diff --git a/packages/cccv/src/components/InfoPanel/SlidingPanel.tsx b/packages/cccv/src/components/InfoPanel/SlidingPanel.tsx index 49f2fc34..8bd54e9b 100644 --- a/packages/cccv/src/components/InfoPanel/SlidingPanel.tsx +++ b/packages/cccv/src/components/InfoPanel/SlidingPanel.tsx @@ -2,28 +2,29 @@ import './SlidingPanel.scss' import React, { useState, useEffect, useRef } from 'react' interface InfoPanelProps { - showPanel: boolean; + showPanel?: boolean; contentChanged: boolean; onClose: () => void; onResize?: (width: number) => void; children?: React.ReactNode; } -export default function SlidingPanel({ showPanel, contentChanged, onResize, children }: InfoPanelProps) { +export default function SlidingPanel({ showPanel, contentChanged, onResize, onClose, children }: InfoPanelProps) { const panelRef = useRef(null) const isResizing = useRef(false) const [panelWidth, setPanelWidth] = useState(300) - const [isPanelVisible, setIsPanelVisible] = useState(showPanel) // Track visibility state - const [isLargeScreen, setIsLargeScreen] = useState(window.innerWidth > 640) // Detect if the screen is large + const [isPanelVisible, setIsPanelVisible] = useState(showPanel) + const [isLargeScreen, setIsLargeScreen] = useState(window.innerWidth > 640) + + useEffect(() => { + setIsPanelVisible(showPanel || true) + }, [showPanel]) useEffect(() => { - // Listen for window resize to update isLargeScreen const handleResize = () => { setIsLargeScreen(window.innerWidth > 640) } - window.addEventListener('resize', handleResize) - return () => { window.removeEventListener('resize', handleResize) } @@ -43,7 +44,6 @@ export default function SlidingPanel({ showPanel, contentChanged, onResize, chil if (isResizing.current && panelRef.current && isLargeScreen) { const panelRightEdge = panelRef.current.getBoundingClientRect().right const newWidth = panelRightEdge - e.clientX - if (newWidth > 100) { setPanelWidth(newWidth) onResize && onResize(newWidth) @@ -54,7 +54,7 @@ export default function SlidingPanel({ showPanel, contentChanged, onResize, chil const handleMouseUp = () => { isResizing.current = false - document.body.style.userSelect = '' // Re-enable text selection + document.body.style.userSelect = '' } document.addEventListener('mousemove', handleMouseMove) @@ -69,12 +69,17 @@ export default function SlidingPanel({ showPanel, contentChanged, onResize, chil const handleMouseDown = () => { if (isLargeScreen) { isResizing.current = true - document.body.style.userSelect = 'none' // Disable text selection + document.body.style.userSelect = 'none' } } const handleDoubleClick = () => { - setIsPanelVisible(!isPanelVisible) // Toggle panel visibility + setIsPanelVisible(!isPanelVisible) + } + + const handleClose = () => { + setIsPanelVisible(false) + onClose() } const revealOrHideInfoPanel = isPanelVisible ? 'animate-in' : 'animate-out' @@ -86,23 +91,32 @@ export default function SlidingPanel({ showPanel, contentChanged, onResize, chil ref={panelRef} className={`sliding-panel ${stateClass} absolute bg-white font-mono shadow-black ${signalUpdatedInfoPanel} ${revealOrHideInfoPanel} transition ease-in-out duration-500 z-10`} style={{ - width: isLargeScreen ? `${panelWidth}px` : '100%', // Full width for small screens - height: '100vh', // Full height of the viewport - maxHeight: '100vh', // Full height of the viewport + width: isLargeScreen ? `${panelWidth}px` : '100%', + height: isLargeScreen ? `100vh` : '92vh', + maxHeight: isLargeScreen ? `100vh` : '92vh', display: isPanelVisible ? 'block' : 'none', }} data-testid="sliding-panel" > - {/* Conditionally render the bezel only for large screens */} +
+ + + +
{isLargeScreen && (
)} - - {/* Scrollable content area */}
{children}