Dashboard Metrics
A dashboard header with a date range picker, reload action and a row of metric tiles with tooltip labels, built with Polaris Popover, OptionList, Button, InlineGrid, Card, Tooltip and SkeletonDisplayText.
Preview
Code
Example.jsx
import { useState } from 'react';
import { BlockStack, Box, Button, Card, InlineGrid, InlineStack, OptionList, Popover, SkeletonDisplayText, Text, Tooltip } from '@shopify/polaris';
import { CalendarIcon } from '@shopify/polaris-icons';
const RELOAD_DELAY = 900;
const DATE_RANGES = [
{ value: 'today', label: 'Today', range: 'Jul 20, 2026 - Jul 20, 2026' },
{ value: 'last-7-days', label: 'Last 7 days', range: 'Jul 14, 2026 - Jul 20, 2026' },
{ value: 'last-30-days', label: 'Last 30 days', range: 'Jun 21, 2026 - Jul 20, 2026' },
{ value: 'this-month', label: 'This month', range: 'Jul 20, 2026 - Aug 20, 2026' },
{ value: 'last-month', label: 'Last month', range: 'Jun 1, 2026 - Jun 30, 2026' },
{ value: 'this-year', label: 'This year', range: 'Jan 1, 2026 - Jul 20, 2026' },
];
const METRICS = [
{
id: 'impressions',
label: 'Number of impression',
tooltip: 'Total times the accessibility widget was shown to a visitor.',
value: '0',
},
{
id: 'features-usage',
label: 'Features usage',
tooltip: 'Total times a visitor turned on one of the accessibility features.',
value: '0',
},
{
id: 'most-used-feature',
label: 'Most used feature',
tooltip: 'The accessibility feature your visitors turned on the most.',
value: 'Contrast',
},
];
const LABEL_TRIGGER_STYLE = {
appearance: 'none',
border: 'none',
background: 'none',
padding: 0,
margin: 0,
display: 'inline',
cursor: 'help',
font: 'inherit',
fontSize: 'var(--p-font-size-325, 0.8125rem)',
lineHeight: 'var(--p-font-line-height-500, 1.25rem)',
fontWeight: 'var(--p-font-weight-semibold, 650)',
color: 'var(--p-color-text, #303030)',
borderBottom: '0.0625rem dashed #8a8a8a',
};
const MetricCard = ({ label, tooltip, value, loading }) => (
<Card>
<BlockStack gap="200" inlineAlign="start">
<Tooltip content={tooltip}>
<button type="button" style={LABEL_TRIGGER_STYLE}>
{label}
</button>
</Tooltip>
{loading ? (
<Box minWidth="4rem">
<SkeletonDisplayText size="medium" />
</Box>
) : (
<Text as="p" variant="headingXl" fontWeight="medium">
{value}
</Text>
)}
</BlockStack>
</Card>
);
export const Example = () => {
const [rangeValue, setRangeValue] = useState('this-month');
const [pickerActive, setPickerActive] = useState(false);
const [loading, setLoading] = useState(false);
const selectedRange = DATE_RANGES.find((option) => option.value === rangeValue);
const togglePicker = () => setPickerActive((prev) => !prev);
const reload = () => {
if (loading) return;
setLoading(true);
setTimeout(() => setLoading(false), RELOAD_DELAY);
};
const selectRange = (selected) => {
setRangeValue(selected[0]);
setPickerActive(false);
reload();
};
return (
<BlockStack gap="400">
<InlineStack gap="200" blockAlign="start">
<Popover
active={pickerActive}
onClose={togglePicker}
preferredAlignment="left"
activator={
<Button icon={CalendarIcon} onClick={togglePicker}>
{selectedRange.label}
</Button>
}
>
<OptionList
options={DATE_RANGES.map(({ value, label }) => ({ value, label }))}
selected={[rangeValue]}
onChange={selectRange}
/>
</Popover>
<Button loading={loading} onClick={reload}>
Reload
</Button>
<Box paddingBlockStart="150">
<Text as="p">{selectedRange.range}</Text>
</Box>
</InlineStack>
<InlineGrid columns={{ xs: 1, sm: 3 }} gap="400">
{METRICS.map((metric) => (
<MetricCard
key={metric.id}
label={metric.label}
tooltip={metric.tooltip}
value={metric.value}
loading={loading}
/>
))}
</InlineGrid>
</BlockStack>
);
};