2018-06-14 15:16:57 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2018-07-30 15:14:09 +00:00
|
|
|
import classnames from 'classnames';
|
2018-06-14 15:16:57 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-07-30 15:14:09 +00:00
|
|
|
import { uniqueId } from 'lodash';
|
2018-06-14 15:16:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
const SummaryList = ( { children, label } ) => {
|
|
|
|
if ( ! label ) {
|
2018-07-10 12:48:06 +00:00
|
|
|
label = __( 'Performance Indicators', 'wc-admin' );
|
2018-06-14 15:16:57 +00:00
|
|
|
}
|
2018-07-30 15:14:09 +00:00
|
|
|
// We default to "one" because we can't have empty children. If `children` is just one item,
|
|
|
|
// it's not an array and .length is undefined.
|
|
|
|
let hasItemsClass = 'has-one-item';
|
|
|
|
if ( children && children.length ) {
|
|
|
|
const length = children.filter( Boolean ).length;
|
|
|
|
hasItemsClass = length < 10 ? `has-${ length }-items` : 'has-10-items';
|
|
|
|
}
|
|
|
|
const classes = classnames( 'woocommerce-summary', hasItemsClass );
|
|
|
|
|
|
|
|
const instanceId = uniqueId( 'woocommerce-summary-helptext-' );
|
2018-06-14 15:16:57 +00:00
|
|
|
return (
|
2018-07-30 15:14:09 +00:00
|
|
|
<nav aria-label={ label } aria-describedby={ instanceId }>
|
|
|
|
<p id={ instanceId } className="screen-reader-text">
|
|
|
|
{ __( 'View the report for the selected data point.', 'wc-admin' ) }
|
|
|
|
</p>
|
|
|
|
<ul className={ classes }>{ children }</ul>
|
|
|
|
</nav>
|
2018-06-14 15:16:57 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
SummaryList.propTypes = {
|
|
|
|
children: PropTypes.node.isRequired,
|
|
|
|
label: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export { SummaryList };
|
|
|
|
export { default as SummaryNumber } from './item';
|