Flex Component
A flexible layout component for arranging children with configurable gap, direction, justification, alignment, and wrapping.import { Box, Flex } from "@locus-ui/components";
<Flex gap="4" direction="row" align="center"> <Box px="2" py="1" className="border">Item 1</Box> <Box px="2" py="1" className="border">Item 2</Box> <Box px="2" py="1" className="border">Item 3</Box></Flex>Anatomy
Import the component:Anatomy
import { Box, Flex } from "@locus-ui/components";
<Flex />Examples
Gaps
Thegap prop controls the spacing between child elements using predefined scale values 0 through 8.
0
1
2
3
4
5
6
7
8
gaps.tsx
import { Box, Flex } from "@locus-ui/components";
const gaps = ["0", "1", "2", "3", "4", "5", "6", "7", "8"];
return gaps.map((gap) => ( <Box key={gap} px="2" py="1"> <Text>{gap}</Text> <Flex gap={gap}> <Box px="2" py="1" className="border">Item 1</Box> <Box px="2" py="1" className="border">Item 2</Box> </Flex> </Box>Directions
Thedirection prop sets the flex direction: row, row-reverse, column, or column-reverse.
row
row-reverse
column
column-reverse
directions.tsx
import { Box, Flex } from "@locus-ui/components";
const directions = ["row", "row-reverse", "column", "column-reverse"];
return directions.map((direction) => ( <Box key={direction} px="2" py="1"> <Text>{direction}</Text> <Flex direction={direction} gap="2"> <Box px="2" py="1" className="border">Item 1</Box> <Box px="2" py="1" className="border">Item 2</Box> </Flex> </Box>Justify
Thejustify prop controls the main-axis alignment: start, end, center, between, around, or evenly.
start
end
center
between
around
evenly
justify.tsx
import { Box, Flex } from "@locus-ui/components";
const justifies = ["start", "end", "center", "between", "around", "evenly"];
return justifies.map((justify) => ( <Box key={justify} px="2" py="1"> <Text>{justify}</Text> <Flex justify={justify} gap="2" className="w-full"> <Box px="2" py="1" className="border">Item 1</Box> <Box px="2" py="1" className="border">Item 2</Box> </Flex> </Box>Align
Thealign prop controls the cross-axis alignment: start, end, center, stretch, or baseline.
start
end
center
stretch
baseline
align.tsx
import { Box, Flex } from "@locus-ui/components";
const aligns = ["start", "end", "center", "stretch", "baseline"];
return aligns.map((align) => ( <Box key={align} px="2" py="1"> <Text>{align}</Text> <Flex align={align} gap="2" style={{ height: "100px" }}> <Box px="2" py="1" className="border">Item 1</Box> <Box px="2" py="1" className="border">Item 2</Box> </Flex> </Box>Wrap
Thewrap prop controls flex wrapping: nowrap, wrap, or wrap-reverse.
nowrap
wrap
wrap-reverse
wrap.tsx
import { Box, Flex } from "@locus-ui/components";
const wraps = ["nowrap", "wrap", "wrap-reverse"];
return wraps.map((wrap) => ( <Box key={wrap} px="2" py="1"> <Text>{wrap}</Text> <Flex wrap={wrap} gap="2" style={{ width: "200px" }}> <Box px="2" py="1" className="border">Item 1</Box> <Box px="2" py="1" className="border">Item 2</Box> <Box px="2" py="1" className="border">Item 3</Box> </Flex>