@@ -14,6 +14,11 @@ import styles from './DataTable.scss';
1414
1515export type { SortDirection } ;
1616
17+ export enum RowType {
18+ Totals = 'TOTALS' ,
19+ Footer = 'FOOTER' ,
20+ }
21+
1722export type TableRow =
1823 | DataTableProps [ 'headings' ]
1924 | DataTableProps [ 'rows' ]
@@ -146,23 +151,32 @@ class DataTableInner extends PureComponent<CombinedProps, DataTableState> {
146151 const className = classNames (
147152 styles . DataTable ,
148153 condensed && styles . condensed ,
154+ ! showTotalsInFooter && styles . ShowTotalsInFooter ,
149155 ) ;
150156
151157 const wrapperClassName = classNames (
152158 styles . TableWrapper ,
153159 condensed && styles . condensed ,
154160 ) ;
155161
156- const headingMarkup = < tr > { headings . map ( this . renderHeadings ) } </ tr > ;
162+ const headingMarkup = (
163+ < tr className = { styles . Stripe } > { headings . map ( this . renderHeadings ) } </ tr >
164+ ) ;
157165
158166 const totalsMarkup = totals ? (
159- < tr > { totals . map ( this . renderTotals ) } </ tr >
167+ < tr className = { this . addStripe ( RowType . Totals ) } >
168+ { totals . map ( this . renderTotals ) }
169+ </ tr >
160170 ) : null ;
161171
162172 const bodyMarkup = rows . map ( this . defaultRenderRow ) ;
163173
164174 const footerMarkup = footerContent ? (
165- < div className = { styles . Footer } > { footerContent } </ div >
175+ < div
176+ className = { classNames ( styles . Footer , this . addStripe ( RowType . Footer ) ) }
177+ >
178+ { footerContent }
179+ </ div >
166180 ) : null ;
167181
168182 const headerTotalsMarkup = ! showTotalsInFooter ? totalsMarkup : null ;
@@ -404,6 +418,7 @@ class DataTableInner extends PureComponent<CombinedProps, DataTableState> {
404418 const className = classNames (
405419 styles . TableRow ,
406420 hoverable && styles . hoverable ,
421+ this . addStripe ( index ) ,
407422 ) ;
408423
409424 return (
@@ -468,6 +483,30 @@ class DataTableInner extends PureComponent<CombinedProps, DataTableState> {
468483
469484 return handleSort ;
470485 } ;
486+
487+ private addStripe ( row : number | RowType = 0 ) {
488+ const { showTotalsInFooter, totals, rows} = this . props ;
489+
490+ if ( row === RowType . Totals ) {
491+ return showTotalsInFooter && rows . length % 2 !== 0 ? styles . Stripe : '' ;
492+ }
493+
494+ if ( row === RowType . Footer ) {
495+ return totals && ! showTotalsInFooter && rows . length % 2 === 0
496+ ? styles . Stripe
497+ : '' ;
498+ }
499+
500+ if ( typeof row === 'number' ) {
501+ if ( totals && ! showTotalsInFooter ) {
502+ return row % 2 === 0 ? styles . Stripe : '' ;
503+ }
504+
505+ return row % 2 !== 0 ? styles . Stripe : '' ;
506+ }
507+
508+ return '' ;
509+ }
471510}
472511
473512export function DataTable ( props : DataTableProps ) {
0 commit comments