PPolaris ComponentsConnect an agent

Testimonials

A merchant review carousel with star ratings, truncated quotes and dot pagination, built with Polaris Card, BlockStack, InlineStack and Text.

Preview

Code

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

const REVIEWS = [
  {
    id: 'handmadebyuruba',
    rate: 5,
    title: 'handmadebyuruba',
    comment:
      "We've been searching for a solution to set minimum order quantities for our products, and this app on Shopify exceeded our expectations! It's super easy to use and works perfectly with our store. A special shoutout to William for his outstanding support – he went above and beyond to help us get everything set up smoothly.",
  },
  {
    id: 'goprep',
    rate: 5,
    title: 'GoPrep',
    comment:
      "Avada Order Limits has been a lifesaver for my Shopify store. It's incredibly easy to use and has significantly improved my inventory management. The ability to set specific order limits for individual products has been a game-changer. Plus, the customer support, particularly from Christian, has been exceptional.",
  },
  {
    id: 'fam',
    rate: 5,
    title: 'FAM',
    comment:
      'I needed a solution to limit the quantity per order. Avada offers exactly what I need :) It is self explanatory and offers many options. Customer support was very helpful and quick.',
  },
  {
    id: 'myfacecookies',
    rate: 5,
    title: 'Myfacecookies',
    comment:
      'I needed the option to create a min / max order for each of my products. I downloaded the app and it worked great. If you need any help just ask them in the chat. I had no delays and they were very helpful.',
  },
  {
    id: 'unleashed',
    rate: 5,
    title: 'Unleashed Beauty',
    comment:
      'Could not rate the customer service more highly, they deserve 10 stars! Had a persistent issue with order multiples/minimum order quantity not working. The Avada team chatted with me on and off for a whole day, and a few days later the whole thing was fixed!',
  },
  {
    id: 'newera',
    rate: 5,
    title: 'NewEra',
    comment:
      'Outstanding customer service from Esther. She was very quick to reply and help with the installation step by step. Would highly recommend the app and Esther for any queries you may have. 5+ stars',
  },
  {
    id: 'sezpro',
    rate: 5,
    title: 'Sezpro Nutrition',
    comment:
      'The Avada Team solved my difficult problem. I know it was a time-consuming process, and I was willing to wait, but in the end, the team worked very hard on this new task and successfully resolved my big issue.',
  },
  {
    id: 'alsenaan',
    rate: 5,
    title: 'AL SENAAN GENERAL TR L.L.C',
    comment:
      "I've had an excellent experience with this app! The user interface is intuitive and the features are incredibly useful. It has truly streamlined my workflow. Kudos to Team Lydia for their hard work and dedication.",
  },
  {
    id: 'yogella',
    rate: 5,
    title: 'Yogella',
    comment:
      'I can highly recommend the app. The user interface is very clear and the customer service is very kind and helpful. Christian and Toby solved my problem in no time at all. I am super happy and the app is now working perfectly.',
  },
  {
    id: 'kcustom',
    rate: 5,
    title: 'K Custom Design',
    comment:
      'My experience with Christian was very useful i love that I was not rushed as was able to have exceptional customer service by walking me through step by step. Christian resolved my issue with kindness and patience.',
  },
  {
    id: 'nace',
    rate: 5,
    title: 'NACE Events',
    comment:
      "Very useful app that is easy to set up! It came in very handy for our last-minute need. Much appreciated Penelope's prompt and clear support with some clarifications we needed.",
  },
  {
    id: 'crud',
    rate: 5,
    title: 'CRUD',
    comment:
      'I downloaded this app and it worked exactly as promised. Reached out to support with some questions and they got back to me immediately with clear and helpful answers. The world would be a happier place if plugin provider excelled the way Avada does!',
  },
  {
    id: 'deichtorhallen',
    rate: 5,
    title: 'Onlineshop der Deichtorhallen Hamburg',
    comment:
      'Order Limits works fine. The support is first class!!! Audrey and Maison supported us patiently, very quickly and extremely competently. Thank you Audrey.',
  },
  {
    id: 'grooveman',
    rate: 5,
    title: 'Grooveman Music',
    comment:
      "I recently had the pleasure of working with Emily from the Avada app support team, and I can't express how grateful I am for her assistance. Emily was incredibly helpful and went above and beyond to ensure that all my issues were resolved promptly. Her expertise and dedication to customer satisfaction are truly commendable. Thanks to Emily, my...",
  },
  {
    id: 'kushbox',
    rate: 5,
    title: 'KushBox',
    comment:
      'Christian customer service operator answered all my inquiries professionally and helped me solve the problem I had in a very short time. All excellent!',
  },
  {
    id: 'malachiza',
    rate: 5,
    title: 'MALACHIZA',
    comment: 'The app is incredible and works flawlessly! Hana is wonderful and has been an amazing help. Thank you!',
  },
  {
    id: '12wine',
    rate: 5,
    title: '12WINE',
    comment:
      'Easy to setup, possible to create multiple rules, and quick support. Thank you Audrey for your help!',
  },
  {
    id: 'vws',
    rate: 5,
    title: 'VWS Car Parts',
    comment:
      'Brilliant app so far. very helpful staff, Hana especially was awesome and SO helpful, the other adviser christian was also loads of help. Great help',
  },
  {
    id: 'graymatter',
    rate: 5,
    title: 'Graymatter Labs',
    comment:
      'Support helped me implement, it was very easy. Make sure to chat them. Abby and Maison were very helpful.',
  },
  {
    id: 'clearance',
    rate: 5,
    title: 'Clearance.ae',
    comment:
      'The App did exactly what we need and its totally free and There support were amazing especially Esther they helped in installation very fast',
  },
  {
    id: 'stockist',
    rate: 5,
    title: 'Stockist.pk',
    comment:
      'The support team has been highly cooperative and helpful. I really appreciate their assistance. Special thanks to Rosie and Nikita.',
  },
  {
    id: 'petontime',
    rate: 5,
    title: 'petontime',
    comment: 'It works quitely perfect. My theme needed development and they did it within hours.',
  },
];

const ITEMS_PER_PAGE = 2;
const AUTO_PLAY_MS = 4000;
const PAGE_COUNT = Math.ceil(REVIEWS.length / ITEMS_PER_PAGE);
const SLIDE_MS = 400;

const STAR_STYLE = {
  color: '#ffc107',
  fontSize: '1.25rem',
  lineHeight: 1,
};

const CONTENT_CLAMP_STYLE = {
  display: '-webkit-box',
  WebkitLineClamp: 5,
  WebkitBoxOrient: 'vertical',
  overflow: 'hidden',
  minHeight: '6.25rem',
};

const VIEWPORT_STYLE = {
  overflow: 'hidden',
  width: '100%',
};

const trackStyle = (page, withTransition) => ({
  display: 'flex',
  width: '100%',
  transform: `translateX(-${page * 100}%)`,
  transition: withTransition ? `transform ${SLIDE_MS}ms ease` : 'none',
});

const PAGE_STYLE = {
  flex: '0 0 100%',
  display: 'grid',
  gridTemplateColumns: '1fr 1fr',
  gap: 'var(--p-space-200, 0.5rem)',
  minWidth: 0,
  boxSizing: 'border-box',
};

const DOTS_ROW_STYLE = {
  display: 'flex',
  justifyContent: 'center',
  gap: 'var(--p-space-100, 0.25rem)',
  marginBlockStart: 'var(--p-space-400, 1rem)',
};

const dotStyle = (active) => ({
  appearance: 'none',
  width: '0.5rem',
  height: '0.5rem',
  padding: 0,
  borderRadius: 'var(--p-border-radius-full, 62.5rem)',
  border: '0.0625rem solid var(--p-color-border, #8a8a8a)',
  background: active ? 'var(--p-color-bg-fill-brand, #303030)' : 'transparent',
  cursor: 'pointer',
});

const pages = Array.from({ length: PAGE_COUNT }, (_, pageIndex) =>
  REVIEWS.slice(pageIndex * ITEMS_PER_PAGE, pageIndex * ITEMS_PER_PAGE + ITEMS_PER_PAGE)
);

const StarRow = ({ rate }) => (
  <InlineStack gap="100">
    {Array.from({ length: rate }, (_, index) => (
      <span key={index} style={STAR_STYLE} aria-hidden="true">
        ★
      </span>
    ))}
  </InlineStack>
);

const ReviewCard = ({ title, rate, comment }) => (
  <Card>
    <BlockStack gap="400">
      <Text truncate variant="headingMd" as="p">
        {title}
      </Text>
      <StarRow rate={rate} />
      <div style={CONTENT_CLAMP_STYLE}>
        <Text as="p">{comment}</Text>
      </div>
    </BlockStack>
  </Card>
);

export const Example = () => {
  const [page, setPage] = useState(0);
  const [paused, setPaused] = useState(false);
  const [withTransition, setWithTransition] = useState(true);

  const goToPage = (nextPage) => {
    const wrapsAround =
      (page === PAGE_COUNT - 1 && nextPage === 0) || (page === 0 && nextPage === PAGE_COUNT - 1);
    setWithTransition(!wrapsAround);
    setPage(nextPage);
    if (wrapsAround) {
      requestAnimationFrame(() => {
        requestAnimationFrame(() => setWithTransition(true));
      });
    }
  };

  useEffect(() => {
    if (paused) return undefined;
    const timer = setInterval(() => {
      setPage((prev) => {
        const next = (prev + 1) % PAGE_COUNT;
        const wrapsAround = prev === PAGE_COUNT - 1 && next === 0;
        setWithTransition(!wrapsAround);
        if (wrapsAround) {
          requestAnimationFrame(() => {
            requestAnimationFrame(() => setWithTransition(true));
          });
        }
        return next;
      });
    }, AUTO_PLAY_MS);
    return () => clearInterval(timer);
  }, [paused]);

  return (
    <div onMouseEnter={() => setPaused(true)} onMouseLeave={() => setPaused(false)}>
      <div style={VIEWPORT_STYLE}>
        <div style={trackStyle(page, withTransition)}>
          {pages.map((pageReviews, pageIndex) => (
            <div key={pageIndex} style={PAGE_STYLE}>
              {pageReviews.map((review) => (
                <ReviewCard
                  key={review.id}
                  title={review.title}
                  rate={review.rate}
                  comment={review.comment}
                />
              ))}
            </div>
          ))}
        </div>
      </div>
      <div style={DOTS_ROW_STYLE} role="tablist" aria-label="Testimonial pages">
        {Array.from({ length: PAGE_COUNT }, (_, index) => (
          <button
            key={index}
            type="button"
            role="tab"
            aria-selected={page === index}
            aria-label={`Show testimonials page ${index + 1}`}
            style={dotStyle(page === index)}
            onClick={() => goToPage(index)}
          />
        ))}
      </div>
    </div>
  );
};