Timeline
A Shopify-style activity feed: events grouped under date headings on a continuous connector line, with tone-driven markers, optional app icons and links.
Preview
Code
Example.jsx
import { Badge, BlockStack, Box, Icon, InlineGrid, InlineStack, Link, Text } from '@shopify/polaris';
import { AlertCircleIcon, CheckCircleIcon, ChevronRightIcon, CircleChevronRightIcon } from '@shopify/polaris-icons';
const TIMELINE_STYLES = `
.Timeline-Marker {
position: relative;
display: flex;
align-items: center;
justify-content: center;
height: 24px;
width: 24px;
margin-right: 10px;
}
.Timeline-Marker::before {
content: '';
position: absolute;
top: -40px;
bottom: -30px;
left: 50%;
transform: translateX(-50%);
width: 2px;
background-color: #dfe3e8;
z-index: 0;
}
.Timeline-MarkerIcon {
z-index: 1;
}
.Timeline-MarkerDot {
display: flex;
justify-content: center;
align-items: center;
width: 16px;
height: 16px;
background-color: var(--p-color-border);
border-radius: 3px;
z-index: 1;
}
.Timeline-MarkerDotInner {
width: 8px;
height: 8px;
background-color: var(--p-color-icon);
border-radius: 3px;
}
.Timeline-Event [class*='Polaris-Icon'] {
display: inline;
margin: 0;
}
a:hover .Timeline-EventLink {
text-decoration: underline;
}
`;
const markerIconFor = (tone) => {
switch (tone) {
case 'critical':
case 'caution':
return AlertCircleIcon;
case 'success':
return CheckCircleIcon;
case 'base':
case undefined:
return null;
default:
return CircleChevronRightIcon;
}
};
const AppIcon = ({ src }) => <img src={src} width="16" height="16" alt="" />;
const ITEMS = [
{
tone: 'base',
event: (
<>
A refund was processed for order <Badge>#1242</Badge>. An ARN was generated - 23587235897.
</>
),
timestamp: new Date('2024-09-12T13:30:00'),
},
{
tone: 'base',
icon: <AppIcon src="/timeline-icon_ricemill.png" />,
event: (
<>
Order <Badge>#1241</Badge> was successfully delivered. (Ricemill)
</>
),
timestamp: new Date('2024-09-12T09:29:00'),
},
{
tone: 'critical',
event: (
<>
Order <Badge>#1240</Badge> flagged for review due to suspicious activity.
</>
),
timestamp: new Date('2024-09-11T15:00:00'),
},
{
tone: 'success',
url: 'https://example.com/order/1235',
event: (
<>
Order <Badge>#1235</Badge> shipped via Fedex.
</>
),
timestamp: new Date('2024-09-11T14:59:00'),
},
{
tone: 'base',
event: <>Customer logged in.</>,
timestamp: new Date('2024-09-11T09:44:00'),
},
{
tone: 'base',
event: <>Failed login attempt detected.</>,
timestamp: new Date('2024-09-11T06:59:00'),
},
{
tone: 'base',
icon: <AppIcon src="/timeline-icon_loyalty.png" />,
event: (
<>
Customer redeemed 50 reward points on an order <Badge>#1237</Badge> (LoyaltyPlus)
</>
),
timestamp: new Date('2024-09-10T18:19:00'),
},
{
tone: 'base',
icon: <AppIcon src="/timeline-icon_loyalty.png" />,
event: (
<>Customer earned 100 reward points for subscribing to your mailing list. (LoyaltyPlus)</>
),
timestamp: new Date('2024-09-10T18:14:00'),
},
{
tone: 'caution',
event: <>Account flagged for unusual activity.</>,
timestamp: new Date('2024-09-10T16:00:00'),
},
{
tone: 'base',
url: 'https://example.com/fraud-check',
event: (
<>
Fraud check was initiated for order <Badge>#1236</Badge>
</>
),
timestamp: new Date('2024-09-10T12:10:00'),
},
{
tone: 'base',
event: (
<>
Customer placed an order <Badge>#1234</Badge>
</>
),
timestamp: new Date('2024-09-10T10:30:00'),
},
{
tone: 'base',
event: (
<>
Customer placed order <Badge>#1239</Badge>
</>
),
timestamp: new Date('2024-09-09T13:25:00'),
},
{
tone: 'base',
url: 'https://example.com/points-earned',
event: <>Customer earned 200 reward points after purchase.</>,
timestamp: new Date('2024-09-09T13:00:00'),
},
{
tone: 'base',
event: <>Customer earned 100 reward points.</>,
timestamp: new Date('2024-09-09T11:30:00'),
},
{
tone: 'base',
event: <>Customer contacted support regarding an issue with order.</>,
timestamp: new Date('2024-09-09T11:00:00'),
},
{
tone: 'critical',
icon: <AppIcon src="/timeline-icon_security.png" />,
event: <>Customer flagged for fraud. (Securité)</>,
timestamp: new Date('2024-09-09T08:15:00'),
},
{
tone: 'base',
icon: <AppIcon src="/timeline-icon_ricemill.png" />,
event: <>Customer updated their shipping address. (Ricemill)</>,
timestamp: new Date('2024-09-08T14:09:00'),
},
{
tone: 'base',
event: <>Customer's email address was updated.</>,
timestamp: new Date('2024-09-08T12:44:00'),
},
{
tone: 'base',
url: 'https://example.com/account-updated',
event: <>Account details updated.</>,
timestamp: new Date('2024-09-08T11:19:00'),
},
{
tone: 'base',
event: <>Customer subscribed to newsletter.</>,
timestamp: new Date('2024-09-07T09:29:00'),
},
];
export const Example = () => {
let lastDate = null;
return (
<Box paddingInline={{ xs: '300', md: '0' }}>
<style>{TIMELINE_STYLES}</style>
<BlockStack gap="300">
{ITEMS.map((item, index) => {
const currentDate = item.timestamp.toLocaleDateString([], {
year: 'numeric',
month: 'long',
day: 'numeric',
});
const showDate = currentDate !== lastDate;
lastDate = currentDate;
const markerIcon = markerIconFor(item.tone);
return (
<React.Fragment key={index}>
{showDate ? (
<InlineGrid gap="200" columns="30px auto 90px">
<div />
<Box paddingBlockStart="600">
<Text alignment="start" as="h2" variant="bodySm" tone="subdued">
{currentDate}
</Text>
</Box>
<div />
</InlineGrid>
) : null}
<InlineGrid gap="200" columns="30px auto 90px" alignItems="center">
<div className="Timeline-Marker">
{markerIcon ? (
<span className="Timeline-MarkerIcon">
<Icon source={markerIcon} tone={item.tone} />
</span>
) : (
<div className="Timeline-MarkerDot">
<div className="Timeline-MarkerDotInner" />
</div>
)}
</div>
<div className="Timeline-Event">
<InlineStack gap="200" wrap={false} blockAlign="center">
{item.icon}
{item.url ? (
<Link url={item.url} monochrome removeUnderline>
<InlineStack gap="0" wrap={false} blockAlign="start">
<span className="Timeline-EventLink">{item.event}</span>
<Icon source={ChevronRightIcon} />
</InlineStack>
</Link>
) : (
<span>{item.event}</span>
)}
</InlineStack>
</div>
<Text as="p" alignment="end" tone="subdued" variant="bodySm">
{item.timestamp.toLocaleTimeString([], {
hour: 'numeric',
minute: '2-digit',
hour12: true,
})}
</Text>
</InlineGrid>
</React.Fragment>
);
})}
</BlockStack>
</Box>
);
};