PPolaris ComponentsConnect an agent

Theme Extension Card

App embed and app block status rows with On/Off badges and settings actions, built with Polaris Card, Badge, Banner, Divider and Button.

Preview

Code

Example.jsx
import { useState } from 'react';
import { Badge, BlockStack, Banner, Button, Card, Divider, Icon, InlineStack, Text } from '@shopify/polaris';
import { AppsIcon, RefreshIcon } from '@shopify/polaris-icons';

const ExtensionRow = ({ title, description, enabled, onRefresh, actionLabel }) => (
  <InlineStack align="space-between" blockAlign="center" gap="400" wrap={false}>
    <InlineStack gap="200" blockAlign="center" wrap={false}>
      <Icon source={AppsIcon} tone="base" />
      <BlockStack gap="050" inlineAlign="start">
        <InlineStack gap="150" blockAlign="center">
          <Text as="h3" variant="bodyMd" fontWeight="semibold">
            {title}
          </Text>
          <Badge tone={enabled ? 'success' : undefined}>{enabled ? 'On' : 'Off'}</Badge>
        </InlineStack>
        <Text as="p" tone="subdued">
          {description}
        </Text>
      </BlockStack>
    </InlineStack>
    <InlineStack gap="200" blockAlign="center" wrap={false}>
      <Button icon={RefreshIcon} onClick={onRefresh}>
        Refresh status
      </Button>
      <Button variant="primary">{actionLabel}</Button>
    </InlineStack>
  </InlineStack>
);

export const Example = () => {
  const [appEmbedEnabled, setAppEmbedEnabled] = useState(false);
  const [appBlockEnabled, setAppBlockEnabled] = useState(true);
  const [bannerDismissed, setBannerDismissed] = useState(false);

  const refreshAppEmbed = () => setAppEmbedEnabled((prev) => !prev);
  const refreshAppBlock = () => setAppBlockEnabled((prev) => !prev);

  return (
    <BlockStack gap="400">
      {!appEmbedEnabled && !bannerDismissed && (
        <Banner
          tone="warning"
          title="Your app embed is turned off"
          onDismiss={() => setBannerDismissed(true)}
          action={{ content: 'Enable app embed', onAction: () => setAppEmbedEnabled(true) }}
          secondaryAction={{ content: 'Refresh status', onAction: refreshAppEmbed }}
        >
          <Text as="p">
            The widget will not appear on your storefront until the app embed is enabled in your
            published theme.
          </Text>
        </Banner>
      )}

      <Card>
        <BlockStack gap="300">
          <ExtensionRow
            title="Theme app embed"
            description="Loads the widget on every page of your storefront."
            enabled={appEmbedEnabled}
            onRefresh={refreshAppEmbed}
            actionLabel="App embed settings"
          />
          <Divider />
          <ExtensionRow
            title="Product page app block"
            description="Adds the badge to the main section of your product template."
            enabled={appBlockEnabled}
            onRefresh={refreshAppBlock}
            actionLabel="App block settings"
          />
        </BlockStack>
      </Card>
    </BlockStack>
  );
};