PPolaris ComponentsConnect an agent

Review Banner

A dismissible card prompting for an app-store review, with a five-star rating row that fills on hover and reports the score on click.

Preview

Code

Example.jsx
import { useState } from 'react';
import { BlockStack, Button, Card, InlineStack, Text } from '@shopify/polaris';
import { XIcon } from '@shopify/polaris-icons';

const RATINGS = [1, 2, 3, 4, 5];

const ReviewStar = ({ filled, gradientId }) => (
  <svg width="20" height="20" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
    <defs>
      <linearGradient id={gradientId} x1="0%" y1="0%" x2="100%" y2="100%">
        <stop offset="0%" style={{ stopColor: filled ? '#FFD700' : '#d1d1d1' }} />
        <stop offset="100%" style={{ stopColor: filled ? '#FFA500' : '#a9a9a9' }} />
      </linearGradient>
    </defs>
    <path
      d="M12 1.5l2.9 6.2c.1.2.3.4.5.4l6.5.9c.5.1.7.7.3 1.1l-4.7 4.6c-.2.2-.3.4-.2.7l1.1 6.5c.1.5-.5.9-.9.7l-5.8-3.1c-.2-.1-.5-.1-.7 0l-5.8 3.1c-.5.2-1-.2-.9-.7l1.1-6.5c0-.2 0-.5-.2-.7l-4.7-4.6c-.4-.4-.2-1 .3-1.1l6.5-.9c.2 0 .4-.2.5-.4l2.9-6.2c.2-.5.9-.5 1.2 0z"
      fill={`url(#${gradientId})`}
      stroke={filled ? '#FFA500' : '#a9a9a9'}
      strokeWidth="1"
    />
    <path
      d="M12 4.5l1.8 3.8c.2.4.6.7 1 .8l4 .6-2.9 2.8c-.3.3-.5.8-.4 1.2l.7 4-3.6-1.9c-.4-.2-.9-.2-1.3 0l-3.6 1.9.7-4c.1-.4-.1-.9-.4-1.2l-2.9-2.8 4-.6c.4-.1.8-.4 1-.8L12 4.5z"
      fill={filled ? '#FFE45C' : '#d8d8d8'}
      opacity="0.6"
    />
  </svg>
);

export const Example = () => {
  const [rating, setRating] = useState(0);
  const [hovered, setHovered] = useState(0);
  const [dismissed, setDismissed] = useState(false);

  if (dismissed) return null;

  return (
    <Card>
      <BlockStack gap="400">
        <BlockStack gap="200">
          <InlineStack align="space-between" blockAlign="center" wrap={false}>
            <Text as="h3" variant="headingMd">
              Enjoying the app?
            </Text>
            <Button
              icon={XIcon}
              variant="tertiary"
              accessibilityLabel="Dismiss review request"
              onClick={() => setDismissed(true)}
            />
          </InlineStack>
          <Text as="p" variant="bodyMd" tone="subdued">
            Leave us a review on the Shopify App Store — it takes less than a minute and helps other
            merchants find us.
          </Text>
        </BlockStack>
        <InlineStack gap="100" blockAlign="center">
          {RATINGS.map((value) => (
            <button
              key={value}
              type="button"
              aria-label={`Rate ${value} out of 5`}
              aria-pressed={rating === value}
              onClick={() => setRating(value)}
              onMouseEnter={() => setHovered(value)}
              onMouseLeave={() => setHovered(0)}
              onFocus={() => setHovered(value)}
              onBlur={() => setHovered(0)}
              style={{
                appearance: 'none',
                border: 'none',
                background: 'none',
                padding: 0,
                cursor: 'pointer',
                display: 'inline-flex',
              }}
            >
              <ReviewStar
                filled={value <= (hovered || rating)}
                gradientId={`review-banner-star-${value}`}
              />
            </button>
          ))}
        </InlineStack>
      </BlockStack>
    </Card>
  );
};