Skip to content

Commit 2e063fb

Browse files
committed
Change density and apply stripes to Data Table
1 parent 87ed4e2 commit 2e063fb

File tree

2 files changed

+58
-9
lines changed

2 files changed

+58
-9
lines changed

polaris-react/src/components/DataTable/DataTable.scss

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ $breakpoint: 768px;
6767
}
6868

6969
.Cell {
70-
padding: var(--p-space-4);
70+
padding: var(--p-space-2) var(--p-space-4);
7171
white-space: nowrap;
7272
text-align: left;
7373
transition: background-color var(--p-duration-200) var(--p-ease-in-out);
74+
75+
.Stripe & {
76+
background: var(--p-surface-subdued);
77+
}
7478
}
7579

7680
.Cell-firstColumn {
@@ -94,10 +98,13 @@ $breakpoint: 768px;
9498
@include text-emphasis-normal;
9599
border-bottom: var(--p-border-divider);
96100
border-top: 0;
101+
font-weight: var(--p-font-weight-medium);
102+
font-size: var(--p-font-size-1);
97103
}
98104

99105
.Cell-sortable {
100-
padding: 0;
106+
padding: var(--p-space-2);
107+
margin: var(--p-space-2);
101108
}
102109

103110
.Cell-verticalAlignTop {
@@ -132,11 +139,11 @@ $breakpoint: 768px;
132139
justify-content: flex-end;
133140
align-items: baseline;
134141
@include recolor-icon(var(--p-icon));
142+
font-weight: var(--p-font-weight-medium);
143+
font-size: var(--p-font-size-1);
135144
color: var(--p-text);
136145
transition: color var(--p-duration-200) var(--p-ease);
137146
cursor: pointer;
138-
padding: var(--p-space-2);
139-
margin: var(--p-space-2);
140147

141148
&:hover {
142149
@include recolor-icon(var(--p-interactive-hovered));
@@ -165,7 +172,6 @@ $breakpoint: 768px;
165172

166173
.Cell-total {
167174
@include text-emphasis-strong;
168-
background: var(--p-surface-subdued);
169175
border-bottom: var(--p-border-divider);
170176
}
171177

@@ -178,10 +184,13 @@ $breakpoint: 768px;
178184

179185
.Footer {
180186
padding: var(--p-space-4);
181-
background: var(--p-surface-subdued);
182187
color: var(--p-text-subdued);
183188
text-align: center;
184189
border-top: var(--p-border-divider);
185190
border-bottom-left-radius: var(--p-border-radius-1);
186191
border-bottom-right-radius: var(--p-border-radius-1);
192+
193+
&.Stripe {
194+
background: var(--p-surface-subdued);
195+
}
187196
}

polaris-react/src/components/DataTable/DataTable.tsx

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import styles from './DataTable.scss';
1414

1515
export type {SortDirection};
1616

17+
export enum RowType {
18+
Totals = 'TOTALS',
19+
Footer = 'FOOTER',
20+
}
21+
1722
export 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,31 @@ class DataTableInner extends PureComponent<CombinedProps, DataTableState> {
468483

469484
return handleSort;
470485
};
486+
487+
private addStripe(row: number | RowType = 0) {
488+
489+
const {showTotalsInFooter, totals, rows} = this.props;
490+
491+
if (row === RowType.Totals) {
492+
return showTotalsInFooter && rows.length % 2 !== 0 ? styles.Stripe : '';
493+
}
494+
495+
if (row === RowType.Footer) {
496+
return totals && !showTotalsInFooter && rows.length % 2 === 0
497+
? styles.Stripe
498+
: '';
499+
}
500+
501+
if (typeof row === 'number') {
502+
if (totals && !showTotalsInFooter) {
503+
return row % 2 === 0 ? styles.Stripe : '';
504+
}
505+
506+
return row % 2 !== 0 ? styles.Stripe : '';
507+
}
508+
509+
return '';
510+
}
471511
}
472512

473513
export function DataTable(props: DataTableProps) {

0 commit comments

Comments
 (0)