* Create EmptyTable component

* Update failing test

* Make EmptyTable a functional component

* Add EmptyTable to example.md
This commit is contained in:
Albert Juhé Lluveras 2018-10-20 13:16:53 +02:00 committed by GitHub
parent 1dfd3b186b
commit bfcc817240
7 changed files with 61 additions and 20 deletions

View File

@ -43,6 +43,7 @@ export { default as SummaryListPlaceholder } from './summary/placeholder';
export { default as SummaryNumber } from './summary/item';
export { default as Table } from './table/table';
export { default as TableCard } from './table';
export { default as EmptyTable } from './table/empty';
export { default as TablePlaceholder } from './table/placeholder';
export { default as TableSummary } from './table/summary';
export { default as Tag } from './tag';

View File

@ -0,0 +1,33 @@
/** @format */
/**
* External dependencies
*/
import PropTypes from 'prop-types';
/**
* `EmptyTable` displays a blank space with an optional message passed as a children node
* with the purpose of replacing a table with no rows.
* It mimics the same height a table would have according to the `numberOfRows` prop.
*
* @return { object } -
*/
const EmptyTable = ( { children, numberOfRows } ) => {
return (
<div className="woocommerce-table is-empty" style={ { '--number-of-rows': numberOfRows } }>
{ children }
</div>
);
};
EmptyTable.propTypes = {
/**
* An integer with the number of rows the box should occupy.
*/
numberOfRows: PropTypes.number,
};
EmptyTable.defaultProps = {
numberOfRows: 5,
};
export default EmptyTable;

View File

@ -63,6 +63,13 @@ const MyTable = () => (
headers={ headers }
/>
</Section>
<H>Empty Table</H>
<Section component={ false }>
<EmptyTable>
There are no entries.
</EmptyTable>
</Section>
</div>
);
```

View File

@ -28,6 +28,22 @@
}
}
$row-text-height: 1.1375rem;
$row-height: #{$gap * 2} + #{$row-text-height} + 1px;
$header-row-height: #{$gap-smaller * 2} + #{$row-text-height} + 1px;
&.is-empty {
align-items: center;
background: $core-grey-light-100;
color: $core-grey-dark-500;
display: flex;
// Default to 5 rows for browsers not supporting custom properties (IE11)
height: calc(#{$header-row-height} + (#{$row-height}) * 5);
height: calc(#{$header-row-height} + (#{$row-height}) * var(--number-of-rows));
justify-content: center;
padding: $gap;
text-align: center;
}
button.woocommerce-table__download-button.is-link {
padding: 6px $gap-small;
color: #000;

View File

@ -11,7 +11,7 @@ import { withSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import { Card, Table, TablePlaceholder } from '@woocommerce/components';
import { Card, EmptyTable, Table, TablePlaceholder } from '@woocommerce/components';
import { getAdminLink } from 'lib/nav-utils';
import { numberFormat } from 'lib/number';
import { formatCurrency, getCurrencyFormatDecimal } from 'lib/currency';
@ -96,9 +96,9 @@ export class TopSellingProducts extends Component {
if ( rows.length === 0 ) {
return (
<div className="woocommerce-top-selling-products__empty-message">
<EmptyTable>
{ __( 'When new orders arrive, popular products will be listed here.', 'wc-admin' ) }
</div>
</EmptyTable>
);
}

View File

@ -4,20 +4,6 @@
padding: 0;
}
$row-text-height: 1.1375rem;
$row-height: #{$gap * 2} + #{$row-text-height} + 1px;
$header-row-height: #{$gap-smaller * 2} + #{$row-text-height} + 1px;
.woocommerce-top-selling-products__empty-message {
align-items: center;
background: $core-grey-light-100;
color: $core-grey-dark-500;
display: flex;
height: calc((#{$row-height}) * 5 + #{$header-row-height});
justify-content: center;
padding: $gap;
text-align: center;
}
.woocommerce-table__table {
margin-bottom: 0;

View File

@ -33,9 +33,7 @@ describe( 'TopSellingProducts', () => {
test( 'should render empty message when there are no rows', () => {
const topSellingProducts = shallow( <TopSellingProducts data={ {} } /> );
expect(
topSellingProducts.find( '.woocommerce-top-selling-products__empty-message' ).length
).toBe( 1 );
expect( topSellingProducts.find( 'EmptyTable' ).length ).toBe( 1 );
} );
test( 'should render correct data in the table', () => {