2018-10-30 17:12:21 +00:00
|
|
|
/*
|
|
|
|
Copyright 2018 New Vector Ltd
|
2019-10-08 14:43:57 +00:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2018-10-30 17:12:21 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
2021-09-12 06:40:56 +00:00
|
|
|
import { NumberSize, Resizable } from 're-resizable';
|
2021-10-22 22:23:32 +00:00
|
|
|
import { Direction } from "re-resizable/lib/resizer";
|
|
|
|
|
2021-09-12 06:40:56 +00:00
|
|
|
import ResizeNotifier from "../../utils/ResizeNotifier";
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
resizeNotifier: ResizeNotifier;
|
|
|
|
collapsedRhs?: boolean;
|
2021-09-16 10:22:55 +00:00
|
|
|
panel?: JSX.Element;
|
2021-09-12 06:40:56 +00:00
|
|
|
}
|
2018-10-30 17:12:21 +00:00
|
|
|
|
2021-09-12 06:40:56 +00:00
|
|
|
export default class MainSplit extends React.Component<IProps> {
|
|
|
|
private onResizeStart = (): void => {
|
2020-09-02 11:00:35 +00:00
|
|
|
this.props.resizeNotifier.startResizing();
|
|
|
|
};
|
|
|
|
|
2021-09-12 06:40:56 +00:00
|
|
|
private onResize = (): void => {
|
2020-09-02 11:00:35 +00:00
|
|
|
this.props.resizeNotifier.notifyRightHandleResized();
|
|
|
|
};
|
|
|
|
|
2021-09-12 06:40:56 +00:00
|
|
|
private onResizeStop = (
|
|
|
|
event: MouseEvent | TouchEvent, direction: Direction, elementRef: HTMLElement, delta: NumberSize,
|
|
|
|
): void => {
|
2020-09-02 11:00:35 +00:00
|
|
|
this.props.resizeNotifier.stopResizing();
|
2021-09-12 06:40:56 +00:00
|
|
|
window.localStorage.setItem("mx_rhs_size", (this.loadSidePanelSize().width + delta.width).toString());
|
2020-09-02 11:00:35 +00:00
|
|
|
};
|
2018-12-03 09:43:35 +00:00
|
|
|
|
2021-09-12 06:40:56 +00:00
|
|
|
private loadSidePanelSize(): {height: string | number, width: number} {
|
2020-07-16 01:08:24 +00:00
|
|
|
let rhsSize = parseInt(window.localStorage.getItem("mx_rhs_size"), 10);
|
2018-10-30 17:12:21 +00:00
|
|
|
|
2020-07-16 01:08:24 +00:00
|
|
|
if (isNaN(rhsSize)) {
|
2018-12-18 16:12:32 +00:00
|
|
|
rhsSize = 350;
|
2018-10-31 11:08:41 +00:00
|
|
|
}
|
2019-12-24 02:26:59 +00:00
|
|
|
|
2020-07-16 01:08:24 +00:00
|
|
|
return {
|
|
|
|
height: "100%",
|
|
|
|
width: rhsSize,
|
|
|
|
};
|
2019-12-24 02:26:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-12 06:40:56 +00:00
|
|
|
public render(): JSX.Element {
|
2018-10-30 17:12:21 +00:00
|
|
|
const bodyView = React.Children.only(this.props.children);
|
|
|
|
const panelView = this.props.panel;
|
|
|
|
|
2020-03-10 20:09:40 +00:00
|
|
|
const hasResizer = !this.props.collapsedRhs && panelView;
|
|
|
|
|
|
|
|
let children;
|
|
|
|
if (hasResizer) {
|
2020-07-16 01:08:24 +00:00
|
|
|
children = <Resizable
|
2021-09-12 06:40:56 +00:00
|
|
|
defaultSize={this.loadSidePanelSize()}
|
2020-07-16 01:08:24 +00:00
|
|
|
minWidth={264}
|
|
|
|
maxWidth="50%"
|
|
|
|
enable={{
|
|
|
|
top: false,
|
|
|
|
right: false,
|
|
|
|
bottom: false,
|
|
|
|
left: true,
|
|
|
|
topRight: false,
|
|
|
|
bottomRight: false,
|
|
|
|
bottomLeft: false,
|
|
|
|
topLeft: false,
|
|
|
|
}}
|
2021-09-12 06:40:56 +00:00
|
|
|
onResizeStart={this.onResizeStart}
|
|
|
|
onResize={this.onResize}
|
|
|
|
onResizeStop={this.onResizeStop}
|
2020-07-16 01:08:24 +00:00
|
|
|
className="mx_RightPanel_ResizeWrapper"
|
2021-11-29 10:56:09 +00:00
|
|
|
handleClasses={{ left: "mx_ResizeHandle_horizontal" }}
|
2020-07-16 01:08:24 +00:00
|
|
|
>
|
2018-10-30 17:12:21 +00:00
|
|
|
{ panelView }
|
2020-07-16 01:08:24 +00:00
|
|
|
</Resizable>;
|
2018-10-30 17:12:21 +00:00
|
|
|
}
|
2020-03-10 20:09:40 +00:00
|
|
|
|
2020-07-16 01:08:24 +00:00
|
|
|
return <div className="mx_MainSplit">
|
2020-03-10 20:09:40 +00:00
|
|
|
{ bodyView }
|
|
|
|
{ children }
|
|
|
|
</div>;
|
2018-10-30 17:12:21 +00:00
|
|
|
}
|
2018-10-31 11:20:10 +00:00
|
|
|
}
|