Flex
A Box with flexbox layout props — direction, alignment, wrap and gap as typed tokens.
Nova Starling
Product designer
import { Flex, Box, Text, Button } from "astralis-ui";
export function FlexDemo() {
return (
<Flex
justifyContent="between"
alignItems="center"
gap="4"
w="full"
maxW="lg"
bg="panel"
p="4"
rounded="xl"
border="normal"
borderColor="subtle"
>
<Flex alignItems="center" gap="3">
<Box size="10" bg="brand-solid" rounded="full" />
<Box>
<Text size="sm" weight="semibold">Nova Starling</Text>
<Text size="xs" color="muted">Product designer</Text>
</Box>
</Flex>
<Button size="sm" variant="outline" colorScheme="gray">
Follow
</Button>
</Flex>
);
}Import#
import { Flex } from "astralis-ui";
// Flex.Item is available on the component itselfAlignment#
justifyContent distributes children along the main axis, alignItems along
the cross axis — the same vocabulary as CSS, minus the flex- prefixes.
justifyContent="start"
justifyContent="center"
justifyContent="end"
justifyContent="between"
justifyContent="around"
justifyContent="evenly"
import { Flex, Box, Text, VStack } from "astralis-ui";
const justifyValues = ["start", "center", "end", "between", "around", "evenly"] as const;
export function FlexAlign() {
return (
<VStack gap="4" alignItems="stretch" w="full" maxW="md">
{justifyValues.map((justify) => (
<VStack key={justify} gap="1" alignItems="stretch">
<Text as="span" size="xs" color="muted">
justifyContent="{justify}"
</Text>
<Flex justifyContent={justify} gap="2" bg="subtle" p="2" rounded="lg">
<Box size="8" bg="brand-solid" rounded="md" />
<Box size="8" bg="brand-muted" rounded="md" />
<Box size="8" bg="brand-subtle" rounded="md" />
</Flex>
</VStack>
))}
</VStack>
);
}Flex items#
For per-child control, wrap children in Flex.Item — it exposes basis,
grow, shrink, order and alignSelf.
basis 24
grow
order first
"use client";
import { Flex, Center, Text } from "astralis-ui";
export function FlexItem() {
return (
<Flex gap="3" w="full" maxW="md">
<Flex.Item basis="24">
<Center bg="brand-subtle" p="3" rounded="lg">
<Text size="xs">basis 24</Text>
</Center>
</Flex.Item>
<Flex.Item grow>
<Center bg="brand-muted" p="3" rounded="lg">
<Text size="xs">grow</Text>
</Center>
</Flex.Item>
<Flex.Item order="first">
<Center bg="brand-solid" p="3" rounded="lg">
<Text size="xs" color="inverted">order first</Text>
</Center>
</Flex.Item>
</Flex>
);
}Responsive direction#
Every layout prop accepts a breakpoint map. The classic: stack on mobile, row on desktop.
One
Two
Three
import { Flex, Box, Text } from "astralis-ui";
export function FlexResponsive() {
return (
/* Column on mobile, row from md up. */
<Flex direction={{ base: "column", md: "row" }} gap="3" w="full" maxW="md">
<Box bg="teal-subtle" p="4" rounded="lg">
<Text size="sm">One</Text>
</Box>
<Box bg="teal-muted" p="4" rounded="lg">
<Text size="sm">Two</Text>
</Box>
<Box bg="teal-emphasized" p="4" rounded="lg">
<Text size="sm">Three</Text>
</Box>
</Flex>
);
}For simple one-direction stacking, Stack is the shorter spelling.
Props#
Flex extends Box, so every style prop works here too.
| Prop | Type | Default | Description |
|---|---|---|---|
direction | "row" | "column" | "row-reverse" | "column-reverse" | "row" | Main-axis direction. |
justifyContent | "start" | "center" | "end" | "between" | "around" | "evenly" | "start" | Distribution along the main axis. |
alignItems | "start" | "center" | "end" | "baseline" | "stretch" | "start" | Alignment along the cross axis. |
wrap | "wrap" | "nowrap" | "wrap-reverse" | "nowrap" | Whether children wrap onto new lines. |
gap · rowGap · columnGap | "0.5" – "96" (spacing scale) | — | Gap between children, together or per axis. |
alignContent · placeContent | "start" | "center" | "end" | "between" | "around" | "evenly" | "stretch" | — | Multi-line / shorthand content alignment. |
Flex.Item#
| Prop | Type | Default | Description |
|---|---|---|---|
basis | spacing scale | "3xs"–"8xl" | fractions | "auto" | "full" | "min" | "max" | "fit" | — | flex-basis — the item's starting size. |
flex | "1" | "auto" | "initial" | "none" | — | The flex shorthand. |
grow · shrink | boolean | "0" | "1" | — | Whether the item grows into / gives up free space. |
order | "1" – "12" | "first" | "last" | "none" | — | Visual order, independent of source order. |
alignSelf | "auto" | "start" | "end" | "center" | "stretch" | "baseline" | — | Overrides the container's alignItems for this item. |