bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/sidebar-navigation/component.jsx

114 lines
2.6 KiB
React
Raw Normal View History

2021-05-18 04:25:07 +08:00
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import Resizable from 're-resizable';
import { ACTIONS } from '../layout/enums';
import UserListContainer from '../user-list/container';
const propTypes = {
top: PropTypes.number.isRequired,
2021-07-27 04:28:05 +08:00
left: PropTypes.number,
right: PropTypes.number,
2021-05-18 04:25:07 +08:00
zIndex: PropTypes.number.isRequired,
minWidth: PropTypes.number.isRequired,
width: PropTypes.number.isRequired,
maxWidth: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
isResizable: PropTypes.bool.isRequired,
resizableEdge: PropTypes.objectOf(PropTypes.bool).isRequired,
contextDispatch: PropTypes.func.isRequired,
};
2021-07-27 04:28:05 +08:00
const defaultProps = {
left: null,
right: null,
};
2021-05-18 04:25:07 +08:00
const SidebarNavigation = (props) => {
const {
top,
left,
2021-07-27 04:28:05 +08:00
right,
2021-05-18 04:25:07 +08:00
zIndex,
minWidth,
width,
maxWidth,
height,
isResizable,
resizableEdge,
contextDispatch,
} = props;
const [resizableWidth, setResizableWidth] = useState(width);
const [isResizing, setIsResizing] = useState(false);
const [resizeStartWidth, setResizeStartWidth] = useState(0);
useEffect(() => {
if (!isResizing) setResizableWidth(width);
}, [width]);
useEffect(() => {
}, [resizeStartWidth]);
const setSidebarNavWidth = (dWidth) => {
const newWidth = resizeStartWidth + dWidth;
setResizableWidth(newWidth);
contextDispatch({
type: ACTIONS.SET_SIDEBAR_NAVIGATION_SIZE,
value: {
width: newWidth,
browserWidth: window.innerWidth,
browserHeight: window.innerHeight,
},
});
};
return (
<Resizable
minWidth={minWidth}
maxWidth={maxWidth}
size={{
width,
height,
}}
enable={{
top: isResizable && resizableEdge.top,
left: isResizable && resizableEdge.left,
bottom: isResizable && resizableEdge.bottom,
right: isResizable && resizableEdge.right,
}}
handleStyles={{
right: {
right: '-8px',
},
}}
2021-05-18 04:25:07 +08:00
handleWrapperClass="resizeSidebarNavWrapper"
onResizeStart={() => {
setIsResizing(true);
setResizeStartWidth(resizableWidth);
}}
2021-07-28 03:34:21 +08:00
onResize={(...[, , , delta]) => setSidebarNavWidth(delta.width)}
2021-05-18 04:25:07 +08:00
onResizeStop={() => {
setIsResizing(false);
setResizeStartWidth(0);
}}
style={{
position: 'absolute',
top,
left,
2021-07-27 04:28:05 +08:00
right,
2021-05-18 04:25:07 +08:00
zIndex,
width,
height,
}}
>
<UserListContainer />
</Resizable>
);
};
SidebarNavigation.propTypes = propTypes;
2021-07-27 04:28:05 +08:00
SidebarNavigation.defaultProps = defaultProps;
2021-05-18 04:25:07 +08:00
export default SidebarNavigation;