2018-05-18 17:31:08 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classnames from 'classnames';
|
2018-06-26 14:49:42 +00:00
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2018-06-26 14:59:35 +00:00
|
|
|
import { Router, Route, Switch } from 'react-router-dom';
|
2018-05-18 17:31:08 +00:00
|
|
|
import { Slot } from 'react-slot-fill';
|
2018-06-26 14:49:42 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-05-18 17:31:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2018-06-26 14:49:42 +00:00
|
|
|
import Header from 'components/header';
|
2018-05-18 17:31:08 +00:00
|
|
|
import { Controller, getPages } from './controller';
|
2018-06-26 14:59:35 +00:00
|
|
|
import history from 'lib/history';
|
2018-05-18 17:31:08 +00:00
|
|
|
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() {
|
2018-06-26 14:49:42 +00:00
|
|
|
// TODO The activity panel will now always be collapsed. We should refactor some of these classnames.
|
|
|
|
const className = classnames( 'woocommerce-layout', {
|
|
|
|
'has-visible-sidebar': false,
|
|
|
|
'has-hidden-sidebar': true,
|
2018-05-18 17:31:08 +00:00
|
|
|
} );
|
|
|
|
const headerProps = {
|
|
|
|
onToggle: this.toggleSidebar,
|
|
|
|
isSidebarOpen: this.state.isSidebarOpen,
|
|
|
|
};
|
|
|
|
|
2018-06-26 14:49:42 +00:00
|
|
|
const { isEmbeded, ...restProps } = this.props;
|
|
|
|
|
2018-05-18 17:31:08 +00:00
|
|
|
return (
|
|
|
|
<div className={ className }>
|
|
|
|
<Slot name="header" fillChildProps={ headerProps } />
|
2018-06-04 14:25:41 +00:00
|
|
|
<div className="woocommerce-layout__primary" id="woocommerce-layout__primary">
|
2018-05-18 17:31:08 +00:00
|
|
|
<Notices />
|
2018-06-26 14:49:42 +00:00
|
|
|
{ ! isEmbeded && (
|
|
|
|
<div className="woocommerce-layout__main">
|
|
|
|
<Controller { ...restProps } />
|
|
|
|
</div>
|
|
|
|
) }
|
2018-05-18 17:31:08 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<Sidebar isOpen={ this.state.isSidebarOpen } onToggle={ this.toggleSidebar } />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-26 14:49:42 +00:00
|
|
|
Layout.propTypes = {
|
|
|
|
isEmbededLayout: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
export class PageLayout extends Component {
|
2018-05-18 17:31:08 +00:00
|
|
|
render() {
|
|
|
|
return (
|
2018-06-26 14:59:35 +00:00
|
|
|
<Router history={ history }>
|
2018-05-18 17:31:08 +00:00
|
|
|
<Switch>
|
|
|
|
{ getPages().map( page => {
|
|
|
|
return <Route key={ page.path } path={ page.path } exact component={ Layout } />;
|
|
|
|
} ) }
|
|
|
|
<Route component={ Layout } />
|
|
|
|
</Switch>
|
|
|
|
</Router>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-06-26 14:49:42 +00:00
|
|
|
|
|
|
|
export class EmbedLayout extends Component {
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<Header sections={ wcSettings.embedBreadcrumbs } isEmbedded />
|
|
|
|
<Layout isEmbeded />
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|