InlineGrid
A simple CSS grid for equal or proportional columns, with a responsive column count and token-based gaps.
Preview
Code
Example.jsx
import { Card, Box, BlockStack, InlineGrid, Text } from '@shopify/polaris';
const METRICS = ['Sessions', 'Orders', 'Conversion', 'Revenue'];
const Cellule = ({ children }) => (
<Box background="bg-surface-secondary" borderRadius="200" padding="400">
<Text as="span" variant="bodySm" alignment="center">
{children}
</Text>
</Box>
);
const Demo = ({ label, children }) => (
<BlockStack gap="200">
<Text as="h3" variant="headingSm">
{label}
</Text>
{children}
</BlockStack>
);
export const Example = () => (
<Card>
<BlockStack gap="500">
<Demo label="columns={4} gap='400'">
<InlineGrid columns={4} gap="400">
{METRICS.map((metric) => (
<Cellule key={metric}>{metric}</Cellule>
))}
</InlineGrid>
</Demo>
<Demo label="columns={{ xs: 1, sm: 2, md: 4 }} — responsive">
<InlineGrid columns={{ xs: 1, sm: 2, md: 4 }} gap="200">
{METRICS.map((metric) => (
<Cellule key={metric}>{metric}</Cellule>
))}
</InlineGrid>
</Demo>
<Demo label="columns={['twoThirds', 'oneThird']} — proportional">
<InlineGrid columns={['twoThirds', 'oneThird']} gap="400">
<Cellule>Main content</Cellule>
<Cellule>Sidebar</Cellule>
</InlineGrid>
</Demo>
<Demo label='columns="1fr auto 1fr" — raw grid template'>
<InlineGrid columns="1fr auto 1fr" gap="400" alignItems="center">
<Cellule>1fr</Cellule>
<Cellule>auto</Cellule>
<Cellule>1fr</Cellule>
</InlineGrid>
</Demo>
<Demo label="gap='100' vs gap='800'">
<BlockStack gap="300">
<InlineGrid columns={3} gap="100">
<Cellule>gap 100</Cellule>
<Cellule>gap 100</Cellule>
<Cellule>gap 100</Cellule>
</InlineGrid>
<InlineGrid columns={3} gap="800">
<Cellule>gap 800</Cellule>
<Cellule>gap 800</Cellule>
<Cellule>gap 800</Cellule>
</InlineGrid>
</BlockStack>
</Demo>
</BlockStack>
</Card>
);