2018-05-10 18:35:55 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2018-05-24 16:03:03 +00:00
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
|
|
|
import { decodeEntities } from '@wordpress/utils';
|
2018-05-18 17:31:08 +00:00
|
|
|
import { Fill } from 'react-slot-fill';
|
|
|
|
import { isArray, noop } from 'lodash';
|
|
|
|
import { IconButton } from '@wordpress/components';
|
2018-06-26 14:49:42 +00:00
|
|
|
import Link from 'components/link';
|
2018-05-10 18:35:55 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2018-06-04 14:25:41 +00:00
|
|
|
import WordPressNotices from './wordpress-notices';
|
2018-05-10 18:35:55 +00:00
|
|
|
|
2018-06-26 14:49:42 +00:00
|
|
|
const Header = ( { sections, onToggle, isSidebarOpen, isEmbedded } ) => {
|
2018-05-18 17:31:08 +00:00
|
|
|
const _sections = isArray( sections ) ? sections : [ sections ];
|
2018-05-10 18:35:55 +00:00
|
|
|
|
2018-05-24 16:03:03 +00:00
|
|
|
const documentTitle = _sections
|
|
|
|
.map( section => {
|
|
|
|
return isArray( section ) ? section[ 1 ] : section;
|
|
|
|
} )
|
|
|
|
.reverse()
|
|
|
|
.join( ' ‹ ' );
|
|
|
|
|
|
|
|
document.title = decodeEntities(
|
|
|
|
sprintf(
|
|
|
|
__( '%1$s ‹ %2$s — WooCommerce', 'woo-dash' ),
|
|
|
|
documentTitle,
|
|
|
|
wpApiSettings.schema.name
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2018-05-18 17:31:08 +00:00
|
|
|
return (
|
2018-06-01 14:35:18 +00:00
|
|
|
<div className="woocommerce-header">
|
2018-06-20 15:10:06 +00:00
|
|
|
<h1 className="woocommerce-header__breadcrumbs">
|
2018-05-14 13:41:30 +00:00
|
|
|
<span>
|
2018-05-22 15:19:56 +00:00
|
|
|
<Link to="/">WooCommerce</Link>
|
2018-05-14 13:41:30 +00:00
|
|
|
</span>
|
2018-05-24 16:03:03 +00:00
|
|
|
{ _sections.map( ( section, i ) => {
|
|
|
|
const sectionPiece = isArray( section ) ? (
|
2018-06-26 14:49:42 +00:00
|
|
|
<Link to={ section[ 0 ] } wpAdmin={ isEmbedded }>
|
|
|
|
{ section[ 1 ] }
|
|
|
|
</Link>
|
2018-05-24 16:03:03 +00:00
|
|
|
) : (
|
|
|
|
section
|
|
|
|
);
|
|
|
|
return <span key={ i }>{ sectionPiece }</span>;
|
|
|
|
} ) }
|
2018-05-10 18:35:55 +00:00
|
|
|
</h1>
|
2018-06-04 14:25:41 +00:00
|
|
|
<div className="woocommerce-header__buttons">
|
|
|
|
<div className="woocommerce-header__toggle">
|
|
|
|
<IconButton
|
|
|
|
className="woocommerce-header__button"
|
|
|
|
onClick={ onToggle }
|
|
|
|
icon="clock"
|
|
|
|
label={ __( 'Show Sidebar', 'woo-dash' ) }
|
|
|
|
aria-expanded={ isSidebarOpen }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<WordPressNotices />
|
2018-05-18 17:31:08 +00:00
|
|
|
</div>
|
2018-05-10 18:35:55 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Header.propTypes = {
|
|
|
|
sections: PropTypes.node.isRequired,
|
2018-05-18 17:31:08 +00:00
|
|
|
onToggle: PropTypes.func.isRequired,
|
|
|
|
isSidebarOpen: PropTypes.bool,
|
2018-06-26 14:49:42 +00:00
|
|
|
isEmbedded: PropTypes.bool,
|
2018-05-10 18:35:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Header.defaultProps = {
|
2018-05-18 17:31:08 +00:00
|
|
|
onToggle: noop,
|
2018-06-26 14:49:42 +00:00
|
|
|
isEmbedded: false,
|
2018-05-22 15:19:56 +00:00
|
|
|
};
|
2018-05-10 18:35:55 +00:00
|
|
|
|
2018-05-18 17:31:08 +00:00
|
|
|
export default function( props ) {
|
|
|
|
return (
|
|
|
|
<Fill name="header">
|
|
|
|
<Header { ...props } />
|
|
|
|
</Fill>
|
|
|
|
);
|
|
|
|
}
|