Flex
Arrange content with direct flex layout controls.
Overview
Flex is the low-level layout primitive for arranging children along one axis with direct control over direction, alignment, distribution, wrapping, and flexible space.
Compare the layout primitives in the Choose a layout component table.
Use when
You need direct flexbox control for a row or column that wraps, distributes its children, or changes axis responsively.
Use instead
Use Stack, StackRow, or StackCol for ordinary one-dimensional content rhythm. Use Grid when both columns and rows matter.
Usage
Workspace
Updated now
import { Flex, Text } from "@smoothie-framework/whisk-react";
<Flex gap={3} align="center" justify="between">
<Text>Workspace</Text>
<Text color="subtle">Updated now</Text>
</Flex>Examples
Direction
Use a responsive direction when the same content should become a row only after there is enough inline space.
Box 1
Box 2
Box 3
import { Box, Flex, Text } from "@smoothie-framework/whisk-react";
<Flex direction={{ base: "column", md: "row" }} gap={2}>
<Box padding={3} background="surface2" rounded="md">
<Text>Box 1</Text>
</Box>
<Box padding={3} background="surface2" rounded="md">
<Text>Box 2</Text>
</Box>
<Box padding={3} background="surface2" rounded="md">
<Text>Box 3</Text>
</Box>
</Flex>Align
Use align to position children on the cross axis. In a row, that is the vertical axis.
Box 1
Box 2
Box 3
import { Box, Flex, Text } from "@smoothie-framework/whisk-react";
<Flex height={24} align="center" gap={2} padding={2} background="surface1" rounded="md">
<Box padding={2} background="surface2" rounded="md">
<Text>Box 1</Text>
</Box>
<Box padding={4} background="surface2" rounded="md">
<Text>Box 2</Text>
</Box>
<Box padding={2} background="surface2" rounded="md">
<Text>Box 3</Text>
</Box>
</Flex>Justify
Use justify to distribute children on the main axis. In a row, that is the horizontal axis.
start
Box 1
Box 2
center
Box 1
Box 2
end
Box 1
Box 2
between
Box 1
Box 2
import { Box, Flex, Stack, Text } from "@smoothie-framework/whisk-react";
<Stack gap={3}>
<Text size="sm" color="subtle">start</Text>
<Flex background="surface1" rounded="lg" justify="start" gap={2}>
<Box padding={2} background="surface2" rounded="md">
<Text>Box 1</Text>
</Box>
<Box padding={2} background="surface2" rounded="md">
<Text>Box 2</Text>
</Box>
</Flex>
<Text size="sm" color="subtle">center</Text>
<Flex background="surface1" rounded="lg" justify="center" gap={2}>
<Box padding={2} background="surface2" rounded="md">
<Text>Box 1</Text>
</Box>
<Box padding={2} background="surface2" rounded="md">
<Text>Box 2</Text>
</Box>
</Flex>
<Text size="sm" color="subtle">end</Text>
<Flex background="surface1" rounded="lg" justify="end" gap={2}>
<Box padding={2} background="surface2" rounded="md">
<Text>Box 1</Text>
</Box>
<Box padding={2} background="surface2" rounded="md">
<Text>Box 2</Text>
</Box>
</Flex>
<Text size="sm" color="subtle">between</Text>
<Flex background="surface1" rounded="lg" justify="between">
<Box padding={2} background="surface2" rounded="md">
<Text>Box 1</Text>
</Box>
<Box padding={2} background="surface2" rounded="md">
<Text>Box 2</Text>
</Box>
</Flex>
</Stack>Grow
TextInput does not accept the grow style prop, so wrap it in a growing Box when it should take the space left by a fixed action.
import { Box, Button, Flex, TextInput } from "@smoothie-framework/whisk-react";
<Flex gap={2}>
<Box grow={1}>
<TextInput aria-label="Search projects" placeholder="Search projects" />
</Box>
<Button>Search</Button>
</Flex>Wrap
Set wrap when a row can contain more items than a narrow viewport can hold. Keep a gap so wrapped items remain distinct.
import { Box, Flex } from "@smoothie-framework/whisk-react";
<Flex width="full" wrap gap={2}>
<Box width={16} height={16} background="surface2" rounded="md">1</Box>
<Box width={24} height={16} background="surface2" rounded="md">2</Box>
<Box width={32} height={16} background="surface2" rounded="md">3</Box>
<Box width={48} height={16} background="surface2" rounded="md">4</Box>
<Box width={56} height={16} background="surface2" rounded="md">5</Box>
<Box width={64} height={16} background="surface2" rounded="md">6</Box>
</Flex>Props
Component props
Shared props
Accessibility
Flex is a layout primitive. It does not create a list, group, or landmark. Keep the DOM order equal to the visual order so keyboard and screen-reader users encounter content predictably. Avoid reverse directions when that order matters: they change the visual order without changing the DOM order. Flex does not provide an item-order prop.