Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/famous-penguins-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': minor
---

Updates the loading state of the `IndexTable`
98 changes: 77 additions & 21 deletions polaris-react/src/components/IndexTable/IndexTable.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,72 @@ $loading-panel-height: 53px;
border-collapse: collapse;
}

@keyframes shimmer {
0% {
background-position: 200% 0%;
}

100% {
background-position: 0%;
}
}

@keyframes shimmer-min-motion {
0%,
100% {
background: var(--p-surface);
}

50% {
background: var(--p-surface-hovered);
}
}

$table-loading-animation-duration: 2s;

.Table-loading {
// stylelint-disable-next-line selector-max-type, selector-max-combinators
tbody tr {
background: linear-gradient(
90deg,
var(--p-surface) 5%,
var(--p-surface-hovered) 20%,
var(--p-surface) 35%
);
background-size: 200% 100%;
animation: shimmer $table-loading-animation-duration infinite linear;
animation-delay: calc(0.125s * var(--pc-index-table-row-stagger-index));

// stylelint-disable-next-line stylelint-polaris/media-queries-allowed-list
@media (prefers-reduced-motion) {
background: var(--p-surface);
animation-name: shimmer-min-motion;
animation-delay: 0s;
}
}
}

.CondensedList-loading {
li {
background: linear-gradient(
90deg,
var(--p-surface) 5%,
var(--p-surface-hovered) 20%,
var(--p-surface) 35%
);
background-size: 200% 100%;
animation: shimmer $table-loading-animation-duration infinite linear;
animation-delay: calc(0.125s * var(--pc-index-table-row-stagger-index));

// stylelint-disable-next-line stylelint-polaris/media-queries-allowed-list
@media (prefers-reduced-motion) {
background: var(--p-surface);
animation-name: shimmer-min-motion;
animation-delay: 0s;
}
}
}

.Table-scrolling {
// stylelint-disable-next-line selector-max-class, selector-max-combinators
.TableCell-first,
Expand Down Expand Up @@ -127,49 +193,39 @@ $loading-panel-height: 53px;
}

&.statusSuccess {
// stylelint-disable-next-line selector-max-combinators, selector-max-class, selector-max-specificity
&,
.TableCell-first,
.TableCell-first + .TableCell {
// stylelint-disable-next-line selector-max-class
.TableCell {
background-color: var(--p-surface-primary-selected);
}
}

&.statusSubdued {
// stylelint-disable-next-line selector-max-combinators, selector-max-class, selector-max-specificity
&,
.TableCell-first,
.TableCell-first + .TableCell {
// stylelint-disable-next-line selector-max-class
.TableCell {
background-color: var(--p-surface-subdued);
}
}

&.TableRow-hovered {
// stylelint-disable-next-line selector-max-class, selector-max-combinators, selector-max-specificity
&,
.TableCell-first,
.TableCell-first + .TableCell {
// stylelint-disable-next-line selector-max-class
.TableCell {
background-color: var(--p-surface-hovered);
}
}

&.TableRow-selected {
// stylelint-disable-next-line selector-max-class, selector-max-combinators, selector-max-specificity
&,
// stylelint-disable-next-line selector-max-class
.TableCell,
.TableHeading-first,
.TableHeading-second,
.TableCell-first,
.TableCell-first + .TableCell {
.TableHeading-second {
background-color: var(--p-surface-selected);
}
}

// stylelint-disable-next-line selector-max-class
&.TableRow-hovered.TableRow-selected {
// stylelint-disable-next-line selector-max-class, selector-max-combinators, selector-max-specificity
&,
.TableCell-first,
.TableCell-first + .TableCell {
// stylelint-disable-next-line selector-max-class, selector-max-specificity
.TableCell {
background-color: var(--p-surface-selected-hovered);
}
}
Expand Down
233 changes: 233 additions & 0 deletions polaris-react/src/components/IndexTable/IndexTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,159 @@ export function SmallScreen() {
);
}

export function SmallScreenLoading() {
const customers = [
{
id: '3415',
url: 'customers/341',
name: 'Mae Jemison',
location: 'Decatur, USA',
orders: 20,
amountSpent: '$2,400',
},
{
id: '2565',
url: 'customers/256',
name: 'Ellen Ochoa',
location: 'Los Angeles, USA',
orders: 30,
amountSpent: '$140',
},
{
id: '1234',
url: 'customers/341',
name: 'David Reynolds',
location: 'Phoenix, USA',
orders: 4,
amountSpent: '$84',
},
{
id: '1289',
url: 'customers/256',
name: 'Jennifer Jennings',
location: 'Boise, USA',
orders: 62,
amountSpent: '$542',
},
{
id: '9874',
url: 'customers/341',
name: 'Robert Bradley',
location: 'Seattle, USA',
orders: 21,
amountSpent: '$450',
},
{
id: '4873',
url: 'customers/256',
name: 'Brian Johnson',
location: 'San Diego, USA',
orders: 35,
amountSpent: '$765',
},
{
id: '9082',
url: 'customers/341',
name: 'Kimberley Rogers',
location: 'Kansas City, USA',
orders: 36,
amountSpent: '$1,230',
},
{
id: '3627',
url: 'customers/256',
name: 'Nina Rodriguez',
location: 'Mobile, USA',
orders: 67,
amountSpent: '$986',
},
{
id: '4328',
url: 'customers/341',
name: 'Pam Mahoney',
location: 'Austin, USA',
orders: 24,
amountSpent: '$2,300',
},
{
id: '2635',
url: 'customers/256',
name: 'Joe Talbot',
location: 'Tacoma, USA',
orders: 5,
amountSpent: '$86',
},
{
id: '0982',
url: 'customers/341',
name: 'Billy Parker',
location: 'Madison, USA',
orders: 87,
amountSpent: '$1,930',
},
{
id: '8326',
url: 'customers/256',
name: 'Ahmed Mahmood',
location: 'Portland, USA',
orders: 34,
amountSpent: '$243',
},
];
const resourceName = {
singular: 'customer',
plural: 'customers',
};

const {selectedResources, allResourcesSelected, handleSelectionChange} =
useIndexResourceState(customers);

const rowMarkup = customers.map(
({id, name, location, orders, amountSpent}, index) => (
<IndexTable.Row
id={id}
key={id}
selected={selectedResources.includes(id)}
position={index}
>
<div style={{padding: '12px 16px'}}>
<p>
<TextStyle variation="strong">{name}</TextStyle>
</p>
<p>{location}</p>
<p>{orders}</p>
<p>{amountSpent}</p>
</div>
</IndexTable.Row>
),
);

return (
<div style={{width: '430px'}}>
<Card>
<IndexTable
resourceName={resourceName}
itemCount={customers.length}
selectedItemsCount={
allResourcesSelected ? 'All' : selectedResources.length
}
onSelectionChange={handleSelectionChange}
condensed
loading
headings={[
{title: 'Name'},
{title: 'Location'},
{title: 'Order count'},
{title: 'Amount spent'},
]}
>
{rowMarkup}
</IndexTable>
</Card>
</div>
);
}

export function WithEmptyState() {
const customers = [];
const resourceName = {
Expand Down Expand Up @@ -597,6 +750,86 @@ export function WithLoadingState() {
orders: 30,
amountSpent: '$140',
},
{
id: '1234',
url: 'customers/341',
name: 'David Reynolds',
location: 'Phoenix, USA',
orders: 4,
amountSpent: '$84',
},
{
id: '1289',
url: 'customers/256',
name: 'Jennifer Jennings',
location: 'Boise, USA',
orders: 62,
amountSpent: '$542',
},
{
id: '9874',
url: 'customers/341',
name: 'Robert Bradley',
location: 'Seattle, USA',
orders: 21,
amountSpent: '$450',
},
{
id: '4873',
url: 'customers/256',
name: 'Brian Johnson',
location: 'San Diego, USA',
orders: 35,
amountSpent: '$765',
},
{
id: '9082',
url: 'customers/341',
name: 'Kimberley Rogers',
location: 'Kansas City, USA',
orders: 36,
amountSpent: '$1,230',
},
{
id: '3627',
url: 'customers/256',
name: 'Nina Rodriguez',
location: 'Mobile, USA',
orders: 67,
amountSpent: '$986',
},
{
id: '4328',
url: 'customers/341',
name: 'Pam Mahoney',
location: 'Austin, USA',
orders: 24,
amountSpent: '$2,300',
},
{
id: '2635',
url: 'customers/256',
name: 'Joe Talbot',
location: 'Tacoma, USA',
orders: 5,
amountSpent: '$86',
},
{
id: '0982',
url: 'customers/341',
name: 'Billy Parker',
location: 'Madison, USA',
orders: 87,
amountSpent: '$1,930',
},
{
id: '8326',
url: 'customers/256',
name: 'Ahmed Mahmood',
location: 'Portland, USA',
orders: 34,
amountSpent: '$243',
},
];
const resourceName = {
singular: 'customer',
Expand Down
Loading