PPolaris ComponentsConnect an agent

Modal

An overlay that interrupts the page to ask for a decision or a short piece of input, and blocks everything else until it is dismissed.

Preview

Code

Example.jsx
import { useState, useRef } from 'react';
import { Card, BlockStack, Text, Button, Modal, TextField, Checkbox, List } from '@shopify/polaris';

export const Example = () => {
  const [open, setOpen] = useState(false);
  const [email, setEmail] = useState('ops@snowdevil.com');
  const [notify, setNotify] = useState(true);

  const activatorRef = useRef(null);

  return (
    <Card>
      <BlockStack gap="300">
        <Text as="h2" variant="headingMd">
          Export products
        </Text>
        <Text as="p" tone="subdued">
          Download a CSV of your catalog. Large stores are emailed a download link instead.
        </Text>

        <div ref={activatorRef}>
          <Button variant="primary" onClick={() => setOpen(true)}>
            Export products
          </Button>
        </div>

        <Modal
          activator={activatorRef}
          open={open}
          onClose={() => setOpen(false)}
          title="Export products"
          primaryAction={{ content: 'Export products', onAction: () => setOpen(false) }}
          secondaryActions={[{ content: 'Cancel', onAction: () => setOpen(false) }]}
        >
          <Modal.Section>
            <BlockStack gap="300">
              <Text as="p">
                This exports all 1,248 products in your catalog as a CSV file, including:
              </Text>
              <List>
                <List.Item>Title, description and product type</List.Item>
                <List.Item>Variants, SKUs and barcodes</List.Item>
                <List.Item>Price, compare-at price and inventory</List.Item>
              </List>
            </BlockStack>
          </Modal.Section>
          <Modal.Section>
            <BlockStack gap="300">
              <TextField
                label="Send the download link to"
                type="email"
                value={email}
                onChange={setEmail}
                autoComplete="email"
              />
              <Checkbox
                label="Email me when the export is ready"
                checked={notify}
                onChange={setNotify}
              />
            </BlockStack>
          </Modal.Section>
        </Modal>
      </BlockStack>
    </Card>
  );
};