Skip to content

Commit

Permalink
Add left-right resizer functionality to SplitView component
Browse files Browse the repository at this point in the history
  • Loading branch information
matanfield committed Sep 1, 2024
1 parent 42edf84 commit 02f79da
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
@import "../../../../../../constants";
@import "../../../../../../constants.scss";

.resizer {
flex-shrink: 0;
z-index: 99;
background: transparent;
background-clip: padding-box;
opacity: 0.2;
box-sizing: border-box;
.container {
display: flex;
height: 100%;
overflow: hidden;
}

.left, .center, .right {
height: 100%;
overflow-y: auto;
}

.divider {
width: 4px;
background-color: $gray-200;
cursor: col-resize;
transition: background-color 0.2s ease;

&:hover {
transition: all 2s ease;
background-color: $blue-500;
}

&:global(.vertical) {
width: 0.6875rem;
margin: 0 -0.3125rem;
border-left: 0.3125rem solid transparent;
border-right: 0.3125rem solid transparent;
cursor: col-resize;
&::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 16px;
height: 16px;
background-image: url('path/to/your/resize-icon.svg');
background-repeat: no-repeat;
background-position: center;
opacity: 0;
transition: opacity 0.2s ease;
}

&:hover {
border-left: 0.3125rem solid #{$split-view-resizer-border-hover-color};
border-right: 0.3125rem solid #{$split-view-resizer-border-hover-color};
}
&:hover::after {
opacity: 1;
}
}
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
import React, { FC, useEffect } from "react";
import SplitPane from "react-split-pane";
import { useLockedBody } from "@/shared/hooks";
import styles from "./SplitView.module.scss";
import React, { useState, useCallback } from 'react';
import classNames from 'classnames';
import styles from './SplitView.module.scss';

interface SplitViewProps {
className?: string;
size: number;
minSize: number;
maxSize: number;
defaultSize?: number;
onChange?: (newSize: number) => void;
left: React.ReactNode;
center: React.ReactNode;
right: React.ReactNode;
initialLeftWidth?: number;
initialRightWidth?: number;
}

const SplitView: FC<SplitViewProps> = (props) => {
const { className, size, minSize, maxSize, defaultSize, onChange, children } =
props;
const { lockBodyScroll, unlockBodyScroll } = useLockedBody();
const SplitView: React.FC<SplitViewProps> = ({
left,
center,
right,
initialLeftWidth = 250,
initialRightWidth = 400
}) => {
const [leftWidth, setLeftWidth] = useState(initialLeftWidth);
const [rightWidth, setRightWidth] = useState(initialRightWidth);

useEffect(() => {
lockBodyScroll();
return () => {
unlockBodyScroll();
};
const handleLeftDividerMouseDown = useCallback(() => {
// Implement left divider drag logic similar to the existing right divider
}, []);

const handleRightDividerMouseDown = useCallback(() => {
// ... existing right divider drag logic ...
}, []);

return (
<SplitPane
className={className}
split="vertical"
primary="first"
size={size}
minSize={minSize}
maxSize={maxSize}
defaultSize={defaultSize}
onChange={onChange}
resizerClassName={styles.resizer}
style={{
position: "relative",
overflow: "unset",
}}
paneStyle={{
display: "flex",
flexDirection: "column",
}}
pane1Style={{
overflow: "auto",
height: "calc(100vh - var(--split-view-top))",
}}
>
{children}
<div />
</SplitPane>
<div className={styles.container}>
<div className={styles.left} style={{ width: leftWidth }}>
{left}
</div>
<div
className={styles.divider}
onMouseDown={handleLeftDividerMouseDown}
onClick={(e) => e.preventDefault()}
/>
<div className={styles.center} style={{ width: `calc(100% - ${leftWidth}px - ${rightWidth}px)` }}>
{center}
</div>
<div
className={styles.divider}
onMouseDown={handleRightDividerMouseDown}
onClick={(e) => e.preventDefault()}
/>
<div className={styles.right} style={{ width: rightWidth }}>
{right}
</div>
</div>
);
};

Expand Down

0 comments on commit 02f79da

Please sign in to comment.