element-web/src/components/structures/MainSplit.js

88 lines
2.7 KiB
JavaScript
Raw Normal View History

/*
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
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';
2020-07-16 01:08:24 +00:00
import { Resizable } from 're-resizable';
2021-06-29 12:11:58 +00:00
import { replaceableComponent } from "../../utils/replaceableComponent";
@replaceableComponent("structures.MainSplit")
export default class MainSplit extends React.Component {
_onResizeStart = () => {
this.props.resizeNotifier.startResizing();
};
_onResize = () => {
this.props.resizeNotifier.notifyRightHandleResized();
};
_onResizeStop = (event, direction, refToElement, delta) => {
this.props.resizeNotifier.stopResizing();
2020-07-16 01:08:24 +00:00
window.localStorage.setItem("mx_rhs_size", this._loadSidePanelSize().width + delta.width);
};
2020-07-16 01:08:24 +00:00
_loadSidePanelSize() {
let rhsSize = parseInt(window.localStorage.getItem("mx_rhs_size"), 10);
2020-07-16 01:08:24 +00:00
if (isNaN(rhsSize)) {
rhsSize = 350;
}
2020-07-16 01:08:24 +00:00
return {
height: "100%",
width: rhsSize,
};
}
render() {
const bodyView = React.Children.only(this.props.children);
const panelView = this.props.panel;
const hasResizer = !this.props.collapsedRhs && panelView;
let children;
if (hasResizer) {
2020-07-16 01:08:24 +00:00
children = <Resizable
defaultSize={this._loadSidePanelSize()}
minWidth={264}
maxWidth="50%"
enable={{
top: false,
right: false,
bottom: false,
left: true,
topRight: false,
bottomRight: false,
bottomLeft: false,
topLeft: false,
}}
onResizeStart={this._onResizeStart}
onResize={this._onResize}
onResizeStop={this._onResizeStop}
2020-07-16 01:08:24 +00:00
className="mx_RightPanel_ResizeWrapper"
2021-06-29 12:11:58 +00:00
handleClasses={{ left: "mx_RightPanel_ResizeHandle" }}
2020-07-16 01:08:24 +00:00
>
{ panelView }
2020-07-16 01:08:24 +00:00
</Resizable>;
}
2020-07-16 01:08:24 +00:00
return <div className="mx_MainSplit">
{ bodyView }
{ children }
</div>;
}
2018-10-31 11:20:10 +00:00
}