Skip to main content

Stack

Lays its children out in a column or a row, with the space between them taken from the theme's spacing scale. VStack and HStack are a column and a row.

import { HStack, Stack, VStack } from 'patine-ui';
Loading…
<VStack gap="md">
  <Text>Delete this project? This can't be undone.</Text>
  <HStack gap="sm" justify="flex-end">
    <Button variant="outline">Cancel</Button>
    <Button variant="destructive">Delete</Button>
  </HStack>
</VStack>

Try the props​

Props
direction
gap
align
<Stack gap="md">
…
</Stack>

Example: a notification row​

A notification in an activity feed, built from stacks alone: an HStack puts the avatar beside the text, a VStack stacks the message over its time, and a wrapping HStack keeps the buttons tidy on a narrow screen.

Loading…
<Box border radius="lg" padding="md" style={{ width: '100%', maxWidth: 440 }}>
  <HStack gap="md" align="flex-start">
    <Avatar name="Priya Shah" src="https://picsum.photos/id/338/120/120" />
    <VStack gap="sm" style={{ flex: 1 }}>
      <VStack gap="xs">
        <Text>
          <Text weight="semibold">Priya Shah</Text> asked you to review <Text weight="semibold">Checkout v2</Text>
        </Text>
        <Text size="sm" color="textSecondary">12 minutes ago · Mobile team</Text>
      </VStack>
      <HStack gap="sm" wrap>
        <Button size="sm">Review</Button>
        <Button size="sm" variant="outline">Later</Button>
      </HStack>
    </VStack>
  </HStack>
</Box>

Spacing​

gap and padding take a step of the spacing scale, xs (4) to xl (24), or a number of points. Change the scale in the theme and every stack follows.

Props​

Stack also takes View props. HStack and VStack take the same, without direction.

PropTypeDefaultDescription
direction'column' | 'row''column'Stack only.
gap'xs' | 'sm' | 'md' | 'lg' | 'xl' | number—Space between children.
padding'xs' | 'sm' | 'md' | 'lg' | 'xl' | number—Space inside the edges.
alignViewStyle['alignItems']—Cross-axis alignment.
justifyViewStyle['justifyContent']—Main-axis alignment.
wrapbooleanfalseWrap onto new lines when the children don't fit.
themeDeepPartial<Theme>—Theme override.