| 16 | } |
| 17 | |
| 18 | export const ThreePane: React.FC<ThreePaneProps> = ({ |
| 19 | left, |
| 20 | center, |
| 21 | right, |
| 22 | initialLeftWidth = 260, |
| 23 | minLeftWidth = 200, |
| 24 | maxLeftWidth = 420, |
| 25 | initialRightWidth = 420, |
| 26 | minRightWidth = 320, |
| 27 | maxRightWidth = 720, |
| 28 | header, |
| 29 | }) => { |
| 30 | const [leftWidth, setLeftWidth] = React.useState(initialLeftWidth) |
| 31 | const [rightWidth, setRightWidth] = React.useState(initialRightWidth) |
| 32 | const [resizing, setResizing] = React.useState<'left' | 'right' | null>(null) |
| 33 | const [isMobile, setIsMobile] = React.useState(false) |
| 34 | const [activeMobilePane, setActiveMobilePane] = React.useState< |
| 35 | 'files' | 'code' | 'chat' |
| 36 | >('code') |
| 37 | |
| 38 | React.useEffect(() => { |
| 39 | const mq = window.matchMedia('(max-width: 767.98px)') |
| 40 | const update = () => setIsMobile(mq.matches) |
| 41 | update() |
| 42 | mq.addEventListener('change', update) |
| 43 | return () => mq.removeEventListener('change', update) |
| 44 | }, []) |
| 45 | |
| 46 | const onMouseDownLeft = React.useCallback((e: React.MouseEvent) => { |
| 47 | setResizing('left') |
| 48 | e.preventDefault() |
| 49 | }, []) |
| 50 | const onMouseDownRight = React.useCallback((e: React.MouseEvent) => { |
| 51 | setResizing('right') |
| 52 | e.preventDefault() |
| 53 | }, []) |
| 54 | |
| 55 | const onMouseMove = React.useCallback( |
| 56 | (e: MouseEvent) => { |
| 57 | if (resizing === 'left') { |
| 58 | const newWidth = Math.min( |
| 59 | Math.max(e.clientX, minLeftWidth), |
| 60 | maxLeftWidth |
| 61 | ) |
| 62 | setLeftWidth(newWidth) |
| 63 | } else if (resizing === 'right') { |
| 64 | const newWidth = Math.min( |
| 65 | Math.max(window.innerWidth - e.clientX, minRightWidth), |
| 66 | maxRightWidth |
| 67 | ) |
| 68 | setRightWidth(newWidth) |
| 69 | } |
| 70 | }, |
| 71 | [resizing, minLeftWidth, maxLeftWidth, minRightWidth, maxRightWidth] |
| 72 | ) |
| 73 | |
| 74 | const onMouseUp = React.useCallback(() => { |
| 75 | setResizing(null) |