Tabs
A horizontal row of views over the same set of data, letting someone switch between related sections without leaving the page.
Preview
Code
Example.jsx
import { useState } from 'react';
import { Card, BlockStack, InlineStack, Text, Badge, Tabs } from '@shopify/polaris';
const TAB_ITEMS = [
{ id: 'all', content: 'All', accessibilityLabel: 'All orders', panelID: 'orders-all' },
{ id: 'unfulfilled', content: 'Unfulfilled', panelID: 'orders-unfulfilled' },
{ id: 'unpaid', content: 'Unpaid', panelID: 'orders-unpaid' },
{ id: 'refunded', content: 'Refunded', panelID: 'orders-refunded' },
];
const ORDERS_BY_TAB = {
all: [
{ id: '1054', customer: 'Amelia Cortez', status: 'Fulfilled', tone: 'success' },
{ id: '1053', customer: 'Ravi Patel', status: 'Unfulfilled', tone: 'attention' },
{ id: '1052', customer: 'Joan Vermeer', status: 'Payment pending', tone: 'warning' },
],
unfulfilled: [
{ id: '1053', customer: 'Ravi Patel', status: 'Unfulfilled', tone: 'attention' },
{ id: '1049', customer: 'Lena Fischer', status: 'Unfulfilled', tone: 'attention' },
],
unpaid: [{ id: '1052', customer: 'Joan Vermeer', status: 'Payment pending', tone: 'warning' }],
refunded: [{ id: '1050', customer: 'Grace Okafor', status: 'Refunded', tone: 'critical' }],
};
export const Example = () => {
const [selected, setSelected] = useState(0);
const current = TAB_ITEMS[selected];
const orders = ORDERS_BY_TAB[current.id];
return (
<BlockStack gap="400">
<Card padding="0">
<Tabs tabs={TAB_ITEMS} selected={selected} onSelect={setSelected} fitted />
</Card>
<Card>
<BlockStack gap="300">
<Text as="h2" variant="headingMd">
{current.content} orders
</Text>
{orders.map((order) => (
<InlineStack key={order.id} align="space-between" blockAlign="center">
<BlockStack gap="050">
<Text as="span" fontWeight="semibold">
#{order.id}
</Text>
<Text as="span" variant="bodySm" tone="subdued">
{order.customer}
</Text>
</BlockStack>
<Badge tone={order.tone}>{order.status}</Badge>
</InlineStack>
))}
</BlockStack>
</Card>
</BlockStack>
);
};