Box
The lowest-level layout primitive: a div that only speaks Polaris tokens for padding, background, border, radius and shadow.
Preview
Code
Example.jsx
import { Card, Box, BlockStack, InlineStack, Text } from '@shopify/polaris';
const PADDINGS = ['100', '200', '400', '600'];
const BACKGROUNDS = [
{ token: 'bg-surface-secondary', label: 'bg-surface-secondary' },
{ token: 'bg-surface-success', label: 'bg-surface-success' },
{ token: 'bg-surface-warning', label: 'bg-surface-warning' },
{ token: 'bg-surface-critical', label: 'bg-surface-critical' },
];
const SectionTitle = ({ children }) => (
<Text as="h3" variant="headingSm">
{children}
</Text>
);
export const Example = () => (
<Card>
<BlockStack gap="500">
<BlockStack gap="200">
<SectionTitle>padding</SectionTitle>
<InlineStack gap="300" blockAlign="start">
{PADDINGS.map((padding) => (
<Box key={padding} background="bg-surface-secondary" borderRadius="200">
<Box padding={padding}>
<Box background="bg-fill-brand" borderRadius="100" padding="200">
<Text as="span" variant="bodySm" tone="text-inverse">
{padding}
</Text>
</Box>
</Box>
</Box>
))}
</InlineStack>
</BlockStack>
<BlockStack gap="200">
<SectionTitle>background</SectionTitle>
<InlineStack gap="300">
{BACKGROUNDS.map((item) => (
<Box key={item.token} background={item.token} padding="300" borderRadius="200">
<Text as="span" variant="bodySm">
{item.label}
</Text>
</Box>
))}
</InlineStack>
</BlockStack>
<BlockStack gap="200">
<SectionTitle>border, radius and shadow</SectionTitle>
<InlineStack gap="300" blockAlign="stretch">
<Box background="bg-surface" padding="400" borderWidth="025" borderColor="border" borderRadius="200" minWidth="160px">
<Text as="span" variant="bodySm">
borderWidth="025"
</Text>
</Box>
<Box background="bg-surface" padding="400" borderWidth="050" borderColor="border-brand" borderRadius="300" minWidth="160px">
<Text as="span" variant="bodySm">
borderColor="border-brand"
</Text>
</Box>
<Box background="bg-surface" padding="400" borderRadius="200" shadow="300" minWidth="160px">
<Text as="span" variant="bodySm">
shadow="300"
</Text>
</Box>
</InlineStack>
</BlockStack>
<BlockStack gap="200">
<SectionTitle>directional padding and minHeight</SectionTitle>
<Box background="bg-surface-secondary" borderRadius="200" paddingBlock="200" paddingInline="600">
<Box background="bg-fill-brand" borderRadius="100" minHeight="64px" padding="300">
<Text as="span" variant="bodySm" tone="text-inverse">
paddingBlock="200" paddingInline="600"
</Text>
</Box>
</Box>
</BlockStack>
</BlockStack>
</Card>
);