Popover
A small overlay anchored to a button that holds secondary actions or settings, keeping them out of the way until they are needed.
Preview
Code
Example.jsx
import { useState } from 'react';
import { Card, BlockStack, InlineStack, Text, Button, Popover, ActionList } from '@shopify/polaris';
import { DuplicateIcon, ExportIcon, ArchiveIcon, DeleteIcon } from '@shopify/polaris-icons';
export const Example = () => {
const [active, setActive] = useState(false);
const [lastAction, setLastAction] = useState(null);
const runAction = (content) => {
setLastAction(content);
setActive(false);
};
return (
<Card>
<BlockStack gap="300">
<InlineStack align="space-between" blockAlign="center">
<Text as="h2" variant="headingMd">
Summer sale 2024
</Text>
<Popover
active={active}
onClose={() => setActive(false)}
autofocusTarget="first-node"
preferredAlignment="right"
activator={
<Button disclosure onClick={() => setActive((current) => !current)}>
More actions
</Button>
}
>
<ActionList
actionRole="menuitem"
sections={[
{
title: 'Manage',
items: [
{ content: 'Duplicate discount', icon: DuplicateIcon, onAction: () => runAction('Duplicate discount') },
{ content: 'Export report', icon: ExportIcon, onAction: () => runAction('Export report') },
],
},
{
title: 'Status',
items: [
{ content: 'Archive', icon: ArchiveIcon, onAction: () => runAction('Archive') },
{ content: 'Delete', icon: DeleteIcon, destructive: true, onAction: () => runAction('Delete') },
],
},
]}
/>
</Popover>
</InlineStack>
<Text as="p" tone="subdued">
{lastAction ? `You chose "${lastAction}".` : 'Open the menu to pick an action for this discount.'}
</Text>
</BlockStack>
</Card>
);
};