PPolaris ComponentsConnect an agent

Thumbnail

A small square preview of a product image or file, in extra small through large sizes, used beside a line item in lists and orders.

Preview

Code

Example.jsx
import { Card, BlockStack, InlineStack, Text, Thumbnail, Divider } from '@shopify/polaris';
import { ImageIcon } from '@shopify/polaris-icons';

const NECKLACE_URL = 'https://burst.shopifycdn.com/photos/black-leather-choker-necklace_373x@2x.jpg';
const TEA_URL = 'https://burst.shopifycdn.com/photos/green-tea-with-mint.jpg?width=746';
const COFFEE_URL = 'https://burst.shopifycdn.com/photos/coffee-beans-in-bag.jpg?width=746';

const SIZES = ['extraSmall', 'small', 'medium', 'large'];

const LINE_ITEMS = [
  { id: 'necklace', title: 'Black leather choker necklace', source: NECKLACE_URL, price: '$48.00', quantity: 1 },
  { id: 'tea', title: 'Green tea with mint, 100g tin', source: TEA_URL, price: '$18.00', quantity: 2 },
  { id: 'coffee', title: 'Single origin coffee beans, 1kg', source: COFFEE_URL, price: '$32.00', quantity: 1 },
];

const Section = ({ title, children }) => (
  <BlockStack gap="300">
    <Text as="h2" variant="headingSm" tone="subdued">
      {title}
    </Text>
    {children}
  </BlockStack>
);

export const Example = () => (
  <BlockStack gap="400">
    <Card>
      <Section title="Sizes">
        <InlineStack gap="400" blockAlign="end" wrap>
          {SIZES.map((size) => (
            <BlockStack key={size} gap="150" inlineAlign="center">
              <Thumbnail source={NECKLACE_URL} alt="Black leather choker necklace" size={size} />
              <Text as="span" variant="bodyXs" tone="subdued">
                {size}
              </Text>
            </BlockStack>
          ))}
        </InlineStack>
      </Section>
    </Card>

    <Card>
      <BlockStack gap="500">
        <Section title="In an order line item list">
          <BlockStack gap="300">
            {LINE_ITEMS.map((item) => (
              <InlineStack key={item.id} gap="300" blockAlign="center" wrap={false}>
                <Thumbnail source={item.source} alt={item.title} size="small" />
                <BlockStack gap="050">
                  <Text as="p" fontWeight="medium">
                    {item.title}
                  </Text>
                  <Text as="p" variant="bodySm" tone="subdued" numeric>
                    {item.quantity} x {item.price}
                  </Text>
                </BlockStack>
              </InlineStack>
            ))}
          </BlockStack>
        </Section>

        <Divider />

        <Section title="Placeholder with an icon source">
          <InlineStack gap="300" blockAlign="center">
            <Thumbnail source={ImageIcon} alt="No image set" size="small" />
            <Text as="p" tone="subdued">
              Products without a photo fall back to an icon
            </Text>
          </InlineStack>
        </Section>
      </BlockStack>
    </Card>
  </BlockStack>
);