PPolaris ComponentsConnect an agent

Badge

A small label that communicates the status of an object, such as an order's fulfillment or payment state, with tones, sizes and a progress pip.

Preview

Code

Example.jsx
import { Badge, Card, BlockStack, InlineStack, Text, Divider } from '@shopify/polaris';
import { DiscountIcon, GlobeIcon, InventoryIcon } from '@shopify/polaris-icons';

const TONE_EXAMPLES = [
  { id: 'info', tone: 'info', label: 'Draft' },
  { id: 'success', tone: 'success', label: 'Paid' },
  { id: 'warning', tone: 'warning', label: 'Payment pending' },
  { id: 'critical', tone: 'critical', label: 'Payment failed' },
  { id: 'attention', tone: 'attention', label: 'Unfulfilled' },
  { id: 'new', tone: 'new', label: 'New order' },
];

const PROGRESS_EXAMPLES = [
  { id: 'incomplete', progress: 'incomplete', tone: 'attention', label: 'Unfulfilled' },
  { id: 'partiallyComplete', progress: 'partiallyComplete', tone: 'warning', label: 'Partially fulfilled' },
  { id: 'complete', progress: 'complete', tone: 'success', label: 'Fulfilled' },
];

const SIZE_EXAMPLES = [
  { id: 'small', size: 'small', label: 'Small' },
  { id: 'medium', size: 'medium', label: 'Medium' },
  { id: 'large', size: 'large', label: 'Large' },
];

const ICON_EXAMPLES = [
  { id: 'discount', icon: DiscountIcon, tone: 'success', label: 'Discount applied' },
  { id: 'inventory', icon: InventoryIcon, tone: 'warning', label: 'Low stock' },
  { id: 'globe', icon: GlobeIcon, tone: 'info', label: 'International' },
];

const Section = ({ title, description, children }) => (
  <BlockStack gap="200">
    <BlockStack gap="050">
      <Text as="h3" variant="headingSm">
        {title}
      </Text>
      <Text as="p" variant="bodySm" tone="subdued">
        {description}
      </Text>
    </BlockStack>
    <InlineStack gap="200" blockAlign="center">
      {children}
    </InlineStack>
  </BlockStack>
);

export const Example = () => (
  <Card>
    <BlockStack gap="400">
      <Section title="Tones" description="Each tone carries the meaning of the status it labels.">
        {TONE_EXAMPLES.map((item) => (
          <Badge key={item.id} tone={item.tone}>
            {item.label}
          </Badge>
        ))}
      </Section>

      <Divider />

      <Section
        title="Progress"
        description="A pip shows how far along a task is, so the status reads without relying on color alone."
      >
        {PROGRESS_EXAMPLES.map((item) => (
          <Badge key={item.id} tone={item.tone} progress={item.progress}>
            {item.label}
          </Badge>
        ))}
      </Section>

      <Divider />

      <Section title="Sizes" description="Small badges sit inside dense tables, large ones next to a page title.">
        {SIZE_EXAMPLES.map((item) => (
          <Badge key={item.id} tone="success" size={item.size}>
            {item.label}
          </Badge>
        ))}
      </Section>

      <Divider />

      <Section title="With an icon" description="An icon replaces the progress pip when the status needs a symbol.">
        {ICON_EXAMPLES.map((item) => (
          <Badge key={item.id} tone={item.tone} icon={item.icon}>
            {item.label}
          </Badge>
        ))}
      </Section>
    </BlockStack>
  </Card>
);