DocSpace-buildtools/web/ASC.Web.Components/src/components/layout/index.js

168 lines
4.5 KiB
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
import Backdrop from './sub-components/backdrop'
2019-07-10 09:49:14 +00:00
import Header from './sub-components/header'
import Nav from './sub-components/nav'
import Aside from './sub-components/aside'
import Main from './sub-components/main'
2019-07-10 09:59:00 +00:00
import HeaderNav from './sub-components/header-nav'
2019-07-05 15:10:16 +00:00
import NavLogoItem from './sub-components/nav-logo-item'
import NavItem from './sub-components/nav-item'
class Layout extends React.Component {
constructor(props) {
super(props);
2019-07-09 10:16:50 +00:00
let currentModule = null,
2019-07-10 09:49:14 +00:00
isolateModules = [],
mainModules = [],
totalNotifications = 0,
item = null;
2019-07-05 12:15:58 +00:00
2019-07-09 10:16:50 +00:00
for (let i=0, l=props.availableModules.length; i<l; i++)
{
item = props.availableModules[i];
2019-07-09 10:16:50 +00:00
if (item.id == props.currentModuleId)
currentModule = item;
2019-07-09 10:16:50 +00:00
if (item.isolateMode) {
isolateModules.push(item);
} else {
mainModules.push(item);
if (item.seporator) continue;
totalNotifications+=item.notifications;
2019-07-09 10:16:50 +00:00
}
}
this.state = {
2019-07-10 09:49:14 +00:00
isBackdropOpen: props.isBackdropOpen,
2019-07-08 13:42:05 +00:00
isNavigationHoverEnabled: props.isNavigationHoverEnabled,
isNavigationOpen: props.isNavigationOpen,
2019-07-10 09:49:14 +00:00
isAsideOpen: props.isAsideOpen,
onLogoClick: props.onLogoClick,
asideContent: props.asideContent,
2019-07-08 13:42:05 +00:00
currentUser: props.currentUser || null,
2019-07-09 10:16:50 +00:00
currentUserActions: props.currentUserActions || [],
2019-07-10 09:49:14 +00:00
2019-07-09 10:16:50 +00:00
availableModules: props.availableModules || [],
isolateModules: isolateModules,
mainModules: mainModules,
2019-07-10 09:49:14 +00:00
currentModule: currentModule,
currentModuleId: props.currentModuleId,
2019-07-08 13:42:05 +00:00
totalNotifications: totalNotifications
};
};
2019-07-10 09:49:14 +00:00
backdropClick = () => {
2019-07-08 13:42:05 +00:00
this.setState({
2019-07-10 09:49:14 +00:00
isBackdropOpen: false,
isNavigationOpen: false,
isAsideOpen: false,
2019-07-08 13:42:05 +00:00
isNavigationHoverEnabled: !this.state.isNavigationHoverEnabled
});
};
2019-07-10 09:49:14 +00:00
showNav = () => {
this.setState({
isBackdropOpen: true,
isNavigationOpen: true,
isAsideOpen: false,
isNavigationHoverEnabled: false
});
};
handleNavHover = () => {
2019-07-08 13:42:05 +00:00
if(!this.state.isNavigationHoverEnabled) return;
2019-07-10 09:49:14 +00:00
2019-07-08 13:42:05 +00:00
this.setState({
2019-07-10 09:49:14 +00:00
isBackdropOpen: false,
isNavigationOpen: !this.state.isNavigationOpen,
isAsideOpen: false
2019-07-08 13:42:05 +00:00
});
}
2019-07-10 09:49:14 +00:00
toggleAside = () => {
2019-07-08 13:42:05 +00:00
this.setState({
2019-07-10 09:49:14 +00:00
isBackdropOpen: true,
isNavigationOpen: false,
isAsideOpen: true,
isNavigationHoverEnabled: false
2019-07-08 13:42:05 +00:00
});
};
render() {
return (
2019-07-10 09:49:14 +00:00
<>
<Backdrop isOpen={this.state.isBackdropOpen} onClick={this.backdropClick}/>
2019-07-10 09:59:00 +00:00
<HeaderNav
2019-07-10 09:49:14 +00:00
modules={this.state.isolateModules}
user={this.state.currentUser}
userActions={this.state.currentUserActions}
/>
<Header
badgeNumber={this.state.totalNotifications}
onClick={this.showNav}
2019-07-10 11:24:27 +00:00
currentModule={this.state.currentModule}
2019-07-10 09:49:14 +00:00
/>
<Nav
isOpen={this.state.isNavigationOpen}
onMouseEnter={this.handleNavHover}
onMouseLeave={this.handleNavHover}
>
<NavLogoItem
isOpen={this.state.isNavigationOpen}
onClick={this.state.onLogoClick}
2019-07-09 10:16:50 +00:00
/>
2019-07-10 09:49:14 +00:00
{
this.state.mainModules.map(item =>
<NavItem
seporator={!!item.seporator}
key={item.id}
isOpen={this.state.isNavigationOpen}
active={item.id == this.state.currentModuleId}
iconName={item.iconName}
badgeNumber={item.notifications}
onClick={item.onClick}
onBadgeClick={(e)=>{item.onBadgeClick(e); this.toggleAside();}}
>
{item.title}
</NavItem>
)
}
</Nav>
<Aside isOpen={this.state.isAsideOpen} onClick={this.backdropClick}>{this.state.asideContent}</Aside>
<Main>{this.props.children}</Main>
</>
);
2019-07-05 12:15:58 +00:00
}
}
Layout.propTypes = {
2019-07-10 09:49:14 +00:00
isBackdropOpen: PropTypes.bool,
2019-07-08 13:42:05 +00:00
isNavigationHoverEnabled: PropTypes.bool,
2019-07-05 12:15:58 +00:00
isNavigationOpen: PropTypes.bool,
2019-07-10 09:49:14 +00:00
isAsideOpen: PropTypes.bool,
onLogoClick: PropTypes.func,
asideContent: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
2019-07-05 12:15:58 +00:00
currentUser: PropTypes.object,
2019-07-09 10:16:50 +00:00
currentUserActions: PropTypes.array,
2019-07-05 12:15:58 +00:00
availableModules: PropTypes.array,
2019-07-09 10:16:50 +00:00
currentModuleId: PropTypes.string
}
Layout.defaultProps = {
2019-07-10 09:49:14 +00:00
isBackdropOpen: false,
2019-07-08 13:42:05 +00:00
isNavigationHoverEnabled: true,
2019-07-10 09:49:14 +00:00
isNavigationOpen: false,
isAsideOpen: false
}
export default Layout