Skip to content

Commit f640128

Browse files
committed
Update DataTable Readme and focus states
1 parent 95f63b2 commit f640128

File tree

2 files changed

+109
-1
lines changed

2 files changed

+109
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ $breakpoint: 768px;
125125
padding: 0;
126126

127127
.IncreasedTableDensity & {
128-
padding: var(--p-space-2) var(--p-space-4);
128+
padding: var(--p-space-2);
129129
}
130130
}
131131

@@ -171,6 +171,7 @@ $breakpoint: 768px;
171171
font-weight: var(--p-font-weight-medium);
172172
font-size: var(--p-font-size-1);
173173
padding: 0;
174+
padding-left: var(--p-space-1);
174175
margin: 0;
175176
}
176177

@@ -185,6 +186,14 @@ $breakpoint: 768px;
185186

186187
&:focus:not(:active) {
187188
@include focus-ring($style: 'focused');
189+
color: var(--p-interactive-hovered);
190+
191+
.Icon {
192+
opacity: 1;
193+
svg {
194+
fill: var(--p-surface-subdued);
195+
}
196+
}
188197
}
189198
}
190199

polaris-react/src/components/DataTable/README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,105 @@ function FullDataTableExample() {
437437
}
438438
```
439439

440+
### Data table with all of its elements, increased density, and zebra striping on data
441+
442+
Use as a broad example that includes most props available to data table.
443+
444+
```jsx
445+
function FullDataTableExample() {
446+
const [sortedRows, setSortedRows] = useState(null);
447+
448+
const initiallySortedRows = [
449+
[
450+
<Link
451+
removeUnderline
452+
url="https://www.example.com"
453+
key="emerald-silk-gown"
454+
>
455+
Emerald Silk Gown
456+
</Link>,
457+
'$875.00',
458+
124689,
459+
140,
460+
'$121,500.00',
461+
],
462+
[
463+
<Link
464+
removeUnderline
465+
url="https://www.example.com"
466+
key="mauve-cashmere-scarf"
467+
>
468+
Mauve Cashmere Scarf
469+
</Link>,
470+
'$230.00',
471+
124533,
472+
83,
473+
'$19,090.00',
474+
],
475+
[
476+
<Link
477+
removeUnderline
478+
url="https://www.example.com"
479+
key="navy-merino-wool"
480+
>
481+
Navy Merino Wool Blazer with khaki chinos and yellow belt
482+
</Link>,
483+
'$445.00',
484+
124518,
485+
32,
486+
'$14,240.00',
487+
],
488+
];
489+
490+
const rows = sortedRows ? sortedRows : initiallySortedRows;
491+
const handleSort = useCallback(
492+
(index, direction) => setSortedRows(sortCurrency(rows, index, direction)),
493+
[rows],
494+
);
495+
496+
return (
497+
<Page title="Sales by product">
498+
<Card>
499+
<DataTable
500+
columnContentTypes={[
501+
'text',
502+
'numeric',
503+
'numeric',
504+
'numeric',
505+
'numeric',
506+
]}
507+
headings={[
508+
'Product',
509+
'Price',
510+
'SKU Number',
511+
'Net quantity',
512+
'Net sales',
513+
]}
514+
rows={rows}
515+
totals={['', '', '', 255, '$155,830.00']}
516+
sortable={[false, true, false, false, true]}
517+
defaultSortDirection="descending"
518+
initialSortColumnIndex={4}
519+
onSort={handleSort}
520+
footerContent={`Showing ${rows.length} of ${rows.length} results`}
521+
hasZebraStripingOnData
522+
increasedTableDensity
523+
/>
524+
</Card>
525+
</Page>
526+
);
527+
528+
function sortCurrency(rows, index, direction) {
529+
return [...rows].sort((rowA, rowB) => {
530+
const amountA = parseFloat(rowA[index].substring(1));
531+
const amountB = parseFloat(rowB[index].substring(1));
532+
533+
return direction === 'descending' ? amountB - amountA : amountA - amountB;
534+
});
535+
}
536+
}
537+
```
538+
440539
---
441540

442541
## Best practices

0 commit comments

Comments
 (0)