-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(frontend): Fixing Resizable Panels UI bugs (#2827)
- Loading branch information
Showing
18 changed files
with
382 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as Spaces from 'react-spaces'; | ||
|
||
const FillPanel: React.FC = ({children}) => <Spaces.Fill>{children}</Spaces.Fill>; | ||
|
||
export default FillPanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as Spaces from 'react-spaces'; | ||
import useResizablePanel, {TPanel, TSize} from '../ResizablePanels/hooks/useResizablePanel'; | ||
import Splitter from '../ResizablePanels/Splitter'; | ||
|
||
interface IProps { | ||
panel: TPanel; | ||
order?: number; | ||
children(size: TSize): React.ReactNode; | ||
} | ||
|
||
const LeftPanel = ({panel, order = 1, children}: IProps) => { | ||
const {size, toggle, onStopResize} = useResizablePanel({panel}); | ||
|
||
return ( | ||
<Spaces.LeftResizable | ||
onResizeEnd={newSize => onStopResize(newSize)} | ||
minimumSize={size.minSize} | ||
maximumSize={size.maxSize} | ||
size={size.size} | ||
key={size.name} | ||
order={order} | ||
handleRender={props => <Splitter {...props} name={size.name} isOpen={size.isOpen} onClick={() => toggle()} />} | ||
> | ||
{children(size)} | ||
</Spaces.LeftResizable> | ||
); | ||
}; | ||
|
||
export default LeftPanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as Spaces from 'react-spaces'; | ||
import Splitter from '../ResizablePanels/Splitter'; | ||
import useResizablePanel, {TPanel, TSize} from '../ResizablePanels/hooks/useResizablePanel'; | ||
|
||
interface IProps { | ||
panel: TPanel; | ||
order?: number; | ||
children(size: TSize): React.ReactNode; | ||
} | ||
|
||
const RightPanel = ({panel, order = 1, children}: IProps) => { | ||
const {size, toggle, onStopResize} = useResizablePanel({panel}); | ||
|
||
return ( | ||
<Spaces.RightResizable | ||
onResizeEnd={newSize => onStopResize(newSize)} | ||
minimumSize={size.minSize} | ||
maximumSize={size.maxSize} | ||
size={size.size} | ||
key={size.name} | ||
order={order} | ||
handleRender={props => <Splitter {...props} name={size.name} isOpen={!size.isOpen} onClick={() => toggle()} />} | ||
> | ||
{children(size)} | ||
</Spaces.RightResizable> | ||
); | ||
}; | ||
|
||
export default RightPanel; |
63 changes: 63 additions & 0 deletions
63
web/src/components/ResizablePanels/hooks/useResizablePanel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import {useCallback, useState} from 'react'; | ||
|
||
export type TPanel = { | ||
name: string; | ||
isDefaultOpen?: boolean; | ||
minSize?: number; | ||
maxSize?: number; | ||
}; | ||
|
||
interface IProps { | ||
panel: TPanel; | ||
} | ||
|
||
export type TSize = Exclude<TPanel, 'component'> & { | ||
size: number; | ||
isOpen: boolean; | ||
minSize: number; | ||
maxSize: number; | ||
}; | ||
|
||
const useResizablePanel = ({panel}: IProps) => { | ||
const [size, setSize] = useState<TSize>({ | ||
...panel, | ||
size: (panel.isDefaultOpen && panel.maxSize) || panel.minSize || 0, | ||
isOpen: panel.isDefaultOpen || false, | ||
minSize: panel.minSize || 0, | ||
maxSize: panel.maxSize || 0, | ||
}); | ||
|
||
const toggle = useCallback(() => { | ||
if (size.size <= size.minSize) { | ||
const currentSize = size.maxSize; | ||
setSize({ | ||
...size, | ||
size: currentSize, | ||
isOpen: currentSize > size.minSize, | ||
}); | ||
return; | ||
} | ||
setSize({ | ||
...size, | ||
size: size.minSize || 0, | ||
isOpen: false, | ||
}); | ||
}, [size]); | ||
|
||
const onStopResize = useCallback( | ||
newSize => { | ||
const currentSize = Number(newSize); | ||
|
||
setSize({ | ||
...size, | ||
size: currentSize, | ||
isOpen: currentSize > size.minSize, | ||
}); | ||
}, | ||
[size] | ||
); | ||
|
||
return {toggle, onStopResize, size}; | ||
}; | ||
|
||
export default useResizablePanel; |
76 changes: 0 additions & 76 deletions
76
web/src/components/ResizablePanels/hooks/useResizablePanels.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
import LeftPanel from './LeftPanel'; | ||
import RightPanel from './RightPanel'; | ||
import FillPanel from './FillPanel'; | ||
import {PanelContainer} from './ResizablePanels.styled'; | ||
|
||
// eslint-disable-next-line no-restricted-exports | ||
export {default} from './ResizablePanels'; | ||
export {LeftPanel, RightPanel, FillPanel, PanelContainer}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.