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

103 lines
2.5 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,
};
2024-06-11 21:05:08 +08:00
const SidebarNavigation = ({
top,
left = null,
right = null,
zIndex,
minWidth,
width,
maxWidth,
height,
isResizable,
resizableEdge,
contextDispatch,
}) => {
2021-05-18 04:25:07 +08:00
const [resizableWidth, setResizableWidth] = useState(width);
const [isResizing, setIsResizing] = useState(false);
const [resizeStartWidth, setResizeStartWidth] = useState(0);
useEffect(() => {
if (!isResizing) setResizableWidth(width);
}, [width]);
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;
export default SidebarNavigation;