Skip to content
Merged
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
7 changes: 7 additions & 0 deletions .changeset/strong-bottles-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@shopify/polaris': minor
---

Refactored `SkeletonPage` to use primitive Layout components
Removed `max-width` on children in `AlphaStack`
Added `narrowWidth` and `fullWidth` examples to `AlphaStack` stories
4 changes: 0 additions & 4 deletions polaris-react/src/components/AlphaStack/AlphaStack.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
@media #{$p-breakpoints-xl-up} {
gap: var(--pc-stack-gap-xl);
}

> * {
max-width: 100%;
}
}

.listReset {
Expand Down
82 changes: 5 additions & 77 deletions polaris-react/src/components/SkeletonPage/SkeletonPage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,19 @@

$primary-action-button-height: 36px;
$primary-action-button-width: 100px;
$skeleton-display-text-max-width: 120px;

.Page {
@include page-layout;
}

.fullWidth {
max-width: none;
}

.narrowWidth {
max-width: $layout-width-primary-max;
}

.Content {
@include page-content-layout;
}

.Header {
@include page-header-layout;
padding-bottom: var(--p-space-2);
}

.BreadcrumbAction {
padding-top: var(--p-space-4);
padding-bottom: var(--p-space-4);
margin-top: calc(-1 * var(--p-space-1));
margin-bottom: calc(-1 * var(--p-space-1));
}

.TitleAndPrimaryAction {
display: flex;
align-items: flex-start;
}

.TitleWrapper {
flex: 1 1 0%;
:root {
--pc-skeleton-page-max-width: 998px;
--pc-skeleton-page-max-width-narrow: 662px;
}

.Title {
font-weight: var(--p-font-weight-semibold);
font-size: 24px;
line-height: 28px;

@media #{$p-breakpoints-md-up} {
font-size: 20px;
}
font-size: var(--p-font-size-300);
line-height: var(--p-font-line-height-4);
}

.SkeletonTitle {
display: flex;
background-color: var(--p-surface-neutral);
border-radius: var(--p-border-radius-base);
max-width: $skeleton-display-text-max-width;
height: 28px;

@media screen and (-ms-high-contrast: active) {
background-color: grayText;
}
Expand All @@ -71,32 +28,3 @@ $skeleton-display-text-max-width: 120px;
min-width: $primary-action-button-width;
}
}

.Actions {
margin-top: var(--p-space-2);
display: flex;
flex-direction: row-reverse;
justify-content: flex-end;
align-items: center;
}

.Action {
display: flex;
flex-direction: column;
justify-content: center;
min-height: control-slim-height();
padding-right: var(--p-space-6);
margin-top: calc(-1 * var(--p-space-1));
margin-bottom: calc(-1 * var(--p-space-1));
padding-top: var(--p-space-4);

&:first-child {
padding-right: 0;
}

@media #{$p-breakpoints-lg-down} {
&:not(:last-child) {
display: none;
}
}
}
100 changes: 100 additions & 0 deletions polaris-react/src/components/SkeletonPage/SkeletonPage.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,103 @@ export function WithStaticContent() {
</SkeletonPage>
);
}

export function WithNarrowWidth() {
return (
<SkeletonPage primaryAction narrowWidth>
<Layout>
<Layout.Section>
<Card sectioned>
<SkeletonBodyText />
</Card>
<Card sectioned>
<TextContainer>
<SkeletonDisplayText size="small" />
<SkeletonBodyText />
</TextContainer>
</Card>
<Card sectioned>
<TextContainer>
<SkeletonDisplayText size="small" />
<SkeletonBodyText />
</TextContainer>
</Card>
</Layout.Section>
<Layout.Section secondary>
<Card>
<Card.Section>
<TextContainer>
<SkeletonDisplayText size="small" />
<SkeletonBodyText lines={2} />
</TextContainer>
</Card.Section>
<Card.Section>
<SkeletonBodyText lines={1} />
</Card.Section>
</Card>
<Card subdued>
<Card.Section>
<TextContainer>
<SkeletonDisplayText size="small" />
<SkeletonBodyText lines={2} />
</TextContainer>
</Card.Section>
<Card.Section>
<SkeletonBodyText lines={2} />
</Card.Section>
</Card>
</Layout.Section>
</Layout>
</SkeletonPage>
);
}

export function WithFullWidth() {
return (
<SkeletonPage primaryAction fullWidth>
<Layout>
<Layout.Section>
<Card sectioned>
<SkeletonBodyText />
</Card>
<Card sectioned>
<TextContainer>
<SkeletonDisplayText size="small" />
<SkeletonBodyText />
</TextContainer>
</Card>
<Card sectioned>
<TextContainer>
<SkeletonDisplayText size="small" />
<SkeletonBodyText />
</TextContainer>
</Card>
</Layout.Section>
<Layout.Section secondary>
<Card>
<Card.Section>
<TextContainer>
<SkeletonDisplayText size="small" />
<SkeletonBodyText lines={2} />
</TextContainer>
</Card.Section>
<Card.Section>
<SkeletonBodyText lines={1} />
</Card.Section>
</Card>
<Card subdued>
<Card.Section>
<TextContainer>
<SkeletonDisplayText size="small" />
<SkeletonBodyText lines={2} />
</TextContainer>
</Card.Section>
<Card.Section>
<SkeletonBodyText lines={2} />
</Card.Section>
</Card>
</Layout.Section>
</Layout>
</SkeletonPage>
);
}
77 changes: 52 additions & 25 deletions polaris-react/src/components/SkeletonPage/SkeletonPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';

import {classNames} from '../../utilities/css';
import {useI18n} from '../../utilities/i18n';
import {SkeletonDisplayText} from '../SkeletonDisplayText';
import {SkeletonBodyText} from '../SkeletonBodyText';
import {Box} from '../Box';
import {Inline} from '../Inline';
import {AlphaStack} from '../AlphaStack';

import styles from './SkeletonPage.scss';

Expand Down Expand Up @@ -31,46 +33,71 @@ export function SkeletonPage({
breadcrumbs,
}: SkeletonPageProps) {
const i18n = useI18n();
const className = classNames(
styles.Page,
fullWidth && styles.fullWidth,
narrowWidth && styles.narrowWidth,
);

const titleContent = title ? (
<h1 className={styles.Title}>{title}</h1>
) : (
<div className={styles.SkeletonTitle} />
<div className={styles.SkeletonTitle}>
<Box
background="surface-neutral"
minWidth="120px"
minHeight="28px"
borderRadius="base"
/>
</div>
);

const titleMarkup = <div className={styles.TitleWrapper}>{titleContent}</div>;

const primaryActionMarkup = primaryAction ? (
<div className={styles.PrimaryAction}>
<SkeletonDisplayText size="large" />
</div>
) : null;

const breadcrumbMarkup = breadcrumbs ? (
<div className={styles.BreadcrumbAction} style={{width: 60}}>
<Box maxWidth="60px" paddingBlockStart="4" paddingBlockEnd="4">
<SkeletonBodyText lines={1} />
</div>
</Box>
) : null;

return (
<div
className={className}
role="status"
aria-label={i18n.translate('Polaris.SkeletonPage.loadingLabel')}
>
<div className={styles.Header}>
{breadcrumbMarkup}
<div className={styles.TitleAndPrimaryAction}>
{titleMarkup}
{primaryActionMarkup}
</div>
</div>
<div className={styles.Content}>{children}</div>
</div>
<AlphaStack align="center" fullWidth>
<Box
padding="0"
paddingInlineStart={{sm: '6'}}
paddingInlineEnd={{sm: '6'}}
maxWidth="var(--pc-skeleton-page-max-width)"
aria-label={i18n.translate('Polaris.SkeletonPage.loadingLabel')}
role="status"
{...(narrowWidth && {
maxWidth: 'var(--pc-skeleton-page-max-width-narrow)',
})}
{...(fullWidth && {
maxWidth: 'none',
})}
>
<AlphaStack gap="0" fullWidth>
<Box
padding={{xs: '4', md: '5'}}
paddingBlockEnd={{xs: '2', md: '5'}}
paddingInlineStart={{sm: '0'}}
paddingInlineEnd={{sm: '0'}}
>
{breadcrumbMarkup}
<Inline align="space-between" blockAlign="start">
{titleContent}
{primaryActionMarkup}
</Inline>
</Box>
<Box
paddingBlockStart={{xs: '2', md: '5'}}
paddingBlockEnd="2"
paddingInlineStart="0"
paddingInlineEnd="0"
>
{children}
</Box>
</AlphaStack>
</Box>
</AlphaStack>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from 'react';
import {mountWithApp} from 'tests/utilities';

import {Card} from '../../Card';
import {Text} from '../../Text';
import {Layout} from '../../Layout';
import {SkeletonBodyText} from '../../SkeletonBodyText';
import {SkeletonDisplayText} from '../../SkeletonDisplayText';
import {SkeletonPage} from '../SkeletonPage';
import {Box} from '../../Box';

describe('<SkeletonPage />', () => {
it('renders its children', () => {
Expand Down Expand Up @@ -38,7 +38,9 @@ describe('<SkeletonPage />', () => {
const skeletonPage = mountWithApp(<SkeletonPage title="Products" />);

expect(skeletonPage).toContainReactComponent('h1', {className: 'Title'});
expect(skeletonPage).not.toContainReactComponent(Text);
expect(skeletonPage).not.toContainReactComponent(Box, {
background: 'surface-neutral',
});
});

it('renders SkeletonTitle when a title not defined', () => {
Expand All @@ -47,8 +49,8 @@ describe('<SkeletonPage />', () => {
expect(skeletonPage).not.toContainReactComponent('h1', {
className: 'Title',
});
expect(skeletonPage).toContainReactComponent('div', {
className: 'SkeletonTitle',
expect(skeletonPage).toContainReactComponent(Box, {
background: 'surface-neutral',
});
});

Expand All @@ -58,8 +60,8 @@ describe('<SkeletonPage />', () => {
expect(skeletonPage).not.toContainReactComponent('h1', {
className: 'Title',
});
expect(skeletonPage).toContainReactComponent('div', {
className: 'SkeletonTitle',
expect(skeletonPage).toContainReactComponent(Box, {
background: 'surface-neutral',
});
});
});
Expand Down