PPolaris ComponentsConnect an agent

Pricing Plans

A Free vs paid plan comparison with a monthly/yearly interval toggle, feature lists and trial CTA, built with Polaris ButtonGroup, Grid, Card, Badge, Icon and Link.

Preview

Code

Example.jsx
import { useState } from 'react';
import { Badge, BlockStack, Box, Button, ButtonGroup, Card, Grid, Icon, InlineStack, Link, Text } from '@shopify/polaris';
import { CheckIcon } from '@shopify/polaris-icons';

const INTERVAL_MONTHLY = 'monthly';
const INTERVAL_YEARLY = 'yearly';
const DOCS_URL = 'https://docs.avada.io';
const IMPRESSION_LIMIT = 100;
const MONTHS_PER_YEAR = 12;

const FREE_FEATURES = [
  `Free ${IMPRESSION_LIMIT} impressions`,
  'Auto-translation limit message',
  'Checkout validations',
  'Product / Variant / Collection limit',
  'Customer tag / Product blocking limit',
  'Limit by quantity, value, and weight',
  'Limit by multiple',
  'Support live chat 24/7',
];

const PAID_FEATURES = [
  { label: 'UNLIMITED IMPRESSIONS', emphasize: true },
  { label: 'Exclude products filter' },
  { label: 'Limit Re-purchase' },
  { label: 'Custom limit notification settings' },
  { label: 'Feature request priority' },
  { label: 'Support live chat 24/7' },
  { label: 'All features in Free plan' },
  { label: 'Exclude customer tags filter' },
  { label: 'Product page, cart validation' },
  { label: 'Scheduled limits' },
  { label: 'Custom CSS support' },
];

const BASIC_PLAN = {
  id: 'basic',
  name: 'Basic',
  price: 9.99,
  priceAnnually: 99.9,
};

const CARD_SHELL_STYLE = { height: '100%' };

const HIGHLIGHTED_SURFACE_STYLE = {
  height: '100%',
  borderRadius: 'var(--p-border-radius-300, 0.75rem)',
  background:
    'radial-gradient(at top left, rgba(255, 245, 225, 1) 0%, rgba(255, 255, 255, 1) 60%, rgb(229, 233, 251) 90%)',
};

const FEATURES_PANE_STYLE = { backgroundColor: 'rgba(255, 255, 255, 0.5)' };

const PRICE_COLOR_STYLE = { color: '#00527c' };

const COLUMN_STYLE = { flex: '1 1 0', minWidth: 0 };

const splitIntoColumns = (features) => {
  const half = Math.ceil(features.length / 2);
  return [features.slice(0, half), features.slice(half)];
};

const monthlyPriceFor = (billingInterval) => {
  if (billingInterval === INTERVAL_YEARLY) {
    return (BASIC_PLAN.priceAnnually / MONTHS_PER_YEAR).toFixed(2);
  }
  return BASIC_PLAN.price.toFixed(2);
};

const FeatureRow = ({ label, emphasize }) => (
  <InlineStack align="start" gap="200" wrap={false}>
    <InlineStack>
      <Icon source={CheckIcon} />
    </InlineStack>
    <Text as="span" fontWeight={emphasize ? 'bold' : 'regular'}>
      {label}
    </Text>
  </InlineStack>
);

const FreePlanCard = () => (
  <div style={CARD_SHELL_STYLE}>
    <Card padding="0">
      <Box padding="400" borderRadius="300">
        <BlockStack gap="400">
          <BlockStack gap="200">
            <Text as="h3" variant="headingLg">
              Free
            </Text>
            <Text as="span" variant="heading2xl">
              $0
            </Text>
          </BlockStack>
          <Box
            borderColor="border"
            borderWidth="025"
            padding="400"
            borderRadius="200"
            background="bg-surface-secondary"
          >
            <BlockStack gap="200">
              {FREE_FEATURES.map((label) => (
                <FeatureRow key={label} label={label} />
              ))}
            </BlockStack>
          </Box>
          <Button variant="primary" size="large" fullWidth disabled>
            <Box paddingBlock="100">
              <Text as="span" variant="headingMd" fontWeight="medium">
                Current plan
              </Text>
            </Box>
          </Button>
        </BlockStack>
      </Box>
    </Card>
  </div>
);

const PaidPlanCard = ({ billingInterval }) => {
  const isYearly = billingInterval === INTERVAL_YEARLY;
  const columns = splitIntoColumns(PAID_FEATURES);

  return (
    <div style={CARD_SHELL_STYLE}>
      <Card padding="0">
        <div style={HIGHLIGHTED_SURFACE_STYLE}>
          <Box padding="400">
            <BlockStack gap="400">
              <BlockStack gap="200">
                <Text as="h3" variant="headingLg">
                  {BASIC_PLAN.name}
                </Text>
                <BlockStack>
                  <InlineStack blockAlign="end" gap="050">
                    <Text as="span" variant="heading2xl">
                      <span style={PRICE_COLOR_STYLE}>${monthlyPriceFor(billingInterval)}</span>
                    </Text>
                    <Text as="span">/month</Text>
                  </InlineStack>
                  {isYearly ? (
                    <Text as="span" tone="subdued">
                      Billed annually
                    </Text>
                  ) : (
                    <Box minHeight="20px" />
                  )}
                </BlockStack>
              </BlockStack>
              <div style={FEATURES_PANE_STYLE}>
                <Box borderColor="border" borderWidth="025" padding="400" borderRadius="200">
                  <InlineStack gap="400" align="start" wrap={false}>
                    {columns.map((column, columnIndex) => (
                      <div key={columnIndex} style={COLUMN_STYLE}>
                        <BlockStack gap="200">
                          {column.map((feature) => (
                            <FeatureRow
                              key={feature.label}
                              label={feature.label}
                              emphasize={feature.emphasize}
                            />
                          ))}
                        </BlockStack>
                      </div>
                    ))}
                  </InlineStack>
                </Box>
              </div>
              <Text as="p">
                The price will be based on your current Shopify plan. To view all pricing,{' '}
                <Link removeUnderline target="_blank" url={DOCS_URL}>
                  click here
                </Link>
              </Text>
              <Button variant="primary" size="large" fullWidth>
                <Box paddingBlock="100">
                  <Text as="span" variant="headingMd" fontWeight="medium">
                    Start 7-day FREE trial
                  </Text>
                </Box>
              </Button>
            </BlockStack>
          </Box>
        </div>
      </Card>
    </div>
  );
};

export const Example = () => {
  const [billingInterval, setBillingInterval] = useState(INTERVAL_YEARLY);

  return (
    <BlockStack gap="400">
      <InlineStack align="center" blockAlign="center">
        <ButtonGroup variant="segmented">
          <Button
            size="large"
            pressed={billingInterval === INTERVAL_MONTHLY}
            onClick={() => setBillingInterval(INTERVAL_MONTHLY)}
          >
            <Box minWidth="12rem">Monthly</Box>
          </Button>
          <Button
            size="large"
            pressed={billingInterval === INTERVAL_YEARLY}
            onClick={() => setBillingInterval(INTERVAL_YEARLY)}
          >
            <Box minWidth="12rem">
              <InlineStack align="center" blockAlign="center" gap="200">
                <Text as="span">Yearly</Text>
                <Badge tone="info">
                  <Text as="span" fontWeight="medium">
                    Save up to $99.99
                  </Text>
                </Badge>
              </InlineStack>
            </Box>
          </Button>
        </ButtonGroup>
      </InlineStack>
      <Grid>
        <Grid.Cell columnSpan={{ xs: 6, sm: 3, md: 3, lg: 5, xl: 5 }}>
          <FreePlanCard />
        </Grid.Cell>
        <Grid.Cell columnSpan={{ xs: 6, sm: 3, md: 3, lg: 7, xl: 7 }}>
          <PaidPlanCard billingInterval={billingInterval} />
        </Grid.Cell>
      </Grid>
    </BlockStack>
  );
};