2018-05-18 17:31:08 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { Component } from '@wordpress/element';
|
|
|
|
import { find } from 'lodash';
|
|
|
|
import { HashRouter as Router, Route, Switch } from 'react-router-dom';
|
|
|
|
import { Slot } from 'react-slot-fill';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
|
|
|
import { Controller, getPages } from './controller';
|
|
|
|
import Notices from './notices';
|
|
|
|
import Sidebar from './sidebar';
|
|
|
|
|
|
|
|
class Layout extends Component {
|
|
|
|
constructor() {
|
|
|
|
super( ...arguments );
|
|
|
|
this.toggleSidebar = this.toggleSidebar.bind( this );
|
|
|
|
this.state = {
|
|
|
|
isSidebarOpen: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleSidebar() {
|
|
|
|
this.setState( state => ( { isSidebarOpen: ! state.isSidebarOpen } ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { path } = this.props.match;
|
|
|
|
const page = find( getPages(), { path } );
|
|
|
|
const className = classnames( {
|
2018-06-01 14:35:18 +00:00
|
|
|
'woocommerce-layout': true,
|
2018-05-18 17:31:08 +00:00
|
|
|
'has-visible-sidebar': page.hasOpenSidebar,
|
|
|
|
'has-hidden-sidebar': ! page.hasOpenSidebar,
|
|
|
|
} );
|
|
|
|
const headerProps = {
|
|
|
|
onToggle: this.toggleSidebar,
|
|
|
|
isSidebarOpen: this.state.isSidebarOpen,
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={ className }>
|
|
|
|
<Slot name="header" fillChildProps={ headerProps } />
|
2018-06-01 14:35:18 +00:00
|
|
|
<div className="woocommerce-layout__primary">
|
2018-05-18 17:31:08 +00:00
|
|
|
<Notices />
|
2018-06-01 14:35:18 +00:00
|
|
|
<div className="woocommerce-layout__main">
|
2018-05-18 17:31:08 +00:00
|
|
|
<Controller { ...this.props } />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Sidebar isOpen={ this.state.isSidebarOpen } onToggle={ this.toggleSidebar } />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class extends Component {
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Router>
|
|
|
|
<Switch>
|
|
|
|
{ getPages().map( page => {
|
|
|
|
return <Route key={ page.path } path={ page.path } exact component={ Layout } />;
|
|
|
|
} ) }
|
|
|
|
<Route component={ Layout } />
|
|
|
|
</Switch>
|
|
|
|
</Router>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|