PPolaris ComponentsConnect an agent

Page actions

The primary and secondary actions that close out a page, such as saving a discount or deleting it, placed at the bottom of the form.

Preview

Code

Example.jsx
import { useState } from 'react';
import { Card, Box, BlockStack, Text, TextField, PageActions } from '@shopify/polaris';
import { DeleteIcon, DuplicateIcon } from '@shopify/polaris-icons';

export const Example = () => {
  const [title, setTitle] = useState('Summer sale 20% off');
  const [saved, setSaved] = useState(false);

  return (
    <BlockStack gap="400">
      <Card>
        <BlockStack gap="300">
          <Text as="h2" variant="headingMd">
            Discount details
          </Text>
          <TextField
            label="Title"
            value={title}
            onChange={(value) => {
              setTitle(value);
              setSaved(false);
            }}
            autoComplete="off"
            helpText="Customers see this in their cart and at checkout."
          />
          {saved && (
            <Text as="p" tone="success">
              Discount saved.
            </Text>
          )}
        </BlockStack>
      </Card>

      <Box background="bg-surface" borderRadius="300" borderWidth="025" borderColor="border">
        <PageActions
          primaryAction={{
            content: 'Save discount',
            disabled: title.length === 0,
            onAction: () => setSaved(true),
          }}
          secondaryActions={[
            { content: 'Duplicate', icon: DuplicateIcon, onAction: () => setSaved(false) },
            { content: 'Delete', icon: DeleteIcon, destructive: true, onAction: () => setSaved(false) },
          ]}
        />
      </Box>
    </BlockStack>
  );
};