Progress bar
A horizontal bar that shows how far along a long-running task is, with highlight, primary, success and critical tones in three sizes.
Preview
Code
Example.jsx
import { useState } from 'react';
import { Card, BlockStack, InlineStack, Text, ProgressBar, Button, Divider } from '@shopify/polaris';
const TOTAL_PRODUCTS = 480;
const STEP = 15;
const TONE_EXAMPLES = [
{ id: 'highlight', tone: 'highlight', label: 'Highlight', progress: 40 },
{ id: 'primary', tone: 'primary', label: 'Primary', progress: 55 },
{ id: 'success', tone: 'success', label: 'Success', progress: 100 },
{ id: 'critical', tone: 'critical', label: 'Critical', progress: 25 },
];
const SIZE_EXAMPLES = [
{ id: 'small', size: 'small', label: 'Small' },
{ id: 'medium', size: 'medium', label: 'Medium' },
{ id: 'large', size: 'large', label: 'Large' },
];
export const Example = () => {
const [progress, setProgress] = useState(30);
const imported = Math.round((progress / 100) * TOTAL_PRODUCTS);
const isDone = progress >= 100;
return (
<BlockStack gap="400">
<Card>
<BlockStack gap="300">
<InlineStack align="space-between" blockAlign="center">
<Text as="h2" variant="headingMd">
Importing products
</Text>
<Text as="span" variant="bodySm" tone="subdued">
{`${imported} of ${TOTAL_PRODUCTS}`}
</Text>
</InlineStack>
<ProgressBar progress={progress} tone={isDone ? 'success' : 'primary'} size="medium" />
<InlineStack gap="200" blockAlign="center">
<Button onClick={() => setProgress((value) => Math.min(100, value + STEP))} disabled={isDone}>
Import next batch
</Button>
<Button variant="plain" onClick={() => setProgress(0)}>
Reset
</Button>
<Text as="span" variant="bodySm" tone={isDone ? 'success' : 'subdued'}>
{isDone ? 'Import complete' : `${progress}% complete`}
</Text>
</InlineStack>
</BlockStack>
</Card>
<Card>
<BlockStack gap="400">
<BlockStack gap="300">
<Text as="h3" variant="headingSm">
Tones
</Text>
{TONE_EXAMPLES.map((item) => (
<BlockStack key={item.id} gap="100">
<Text as="span" variant="bodySm" tone="subdued">
{item.label}
</Text>
<ProgressBar progress={item.progress} tone={item.tone} />
</BlockStack>
))}
</BlockStack>
<Divider />
<BlockStack gap="300">
<Text as="h3" variant="headingSm">
Sizes
</Text>
{SIZE_EXAMPLES.map((item) => (
<BlockStack key={item.id} gap="100">
<Text as="span" variant="bodySm" tone="subdued">
{item.label}
</Text>
<ProgressBar progress={65} size={item.size} />
</BlockStack>
))}
</BlockStack>
</BlockStack>
</Card>
</BlockStack>
);
};