ActionList
A vertical list of actions, grouped into sections with icons, that a merchant picks from inside a popover or menu.
Preview
Code
Example.jsx
import { useState, useCallback } from 'react';
import { Card, BlockStack, InlineStack, Text, Button, Popover, ActionList, Badge } from '@shopify/polaris';
import { EditIcon, DuplicateIcon, ExportIcon, ViewIcon, ArchiveIcon, DeleteIcon } from '@shopify/polaris-icons';
const DISCOUNT_TITLE = 'Summer sale — 20% off';
export const Example = () => {
const [active, setActive] = useState(false);
const [archived, setArchived] = useState(false);
const [lastAction, setLastAction] = useState(null);
const toggleActive = useCallback(() => setActive((current) => !current), []);
const runAction = useCallback((label) => {
setLastAction(label);
setActive(false);
}, []);
const sections = [
{
title: 'Manage',
items: [
{ content: 'Edit discount', icon: EditIcon, onAction: () => runAction('Edit discount') },
{ content: 'Duplicate', icon: DuplicateIcon, onAction: () => runAction('Duplicate') },
{ content: 'Preview on storefront', icon: ViewIcon, onAction: () => runAction('Preview on storefront') },
],
},
{
title: 'Status',
items: [
{
content: archived ? 'Unarchive' : 'Archive',
icon: ArchiveIcon,
onAction: () => {
setArchived((current) => !current);
runAction(archived ? 'Unarchive' : 'Archive');
},
},
{ content: 'Export report', icon: ExportIcon, onAction: () => runAction('Export report') },
{
content: 'Delete discount',
icon: DeleteIcon,
destructive: true,
onAction: () => runAction('Delete discount'),
},
],
},
];
return (
<Card>
<BlockStack gap="300">
<InlineStack align="space-between" blockAlign="center" gap="400">
<InlineStack gap="200" blockAlign="center">
<Text as="h2" variant="headingMd">
{DISCOUNT_TITLE}
</Text>
<Badge tone={archived ? undefined : 'success'}>{archived ? 'Archived' : 'Active'}</Badge>
</InlineStack>
<Popover
active={active}
onClose={() => setActive(false)}
autofocusTarget="first-node"
activator={
<Button disclosure onClick={toggleActive} accessibilityLabel="More actions">
More actions
</Button>
}
>
<ActionList actionRole="menuitem" sections={sections} />
</Popover>
</InlineStack>
<Text as="p" tone="subdued">
{lastAction ? `Last action: ${lastAction}` : 'Open the menu to pick an action.'}
</Text>
</BlockStack>
</Card>
);
};