Server Component · 0 KB client JS

Flex

A Box with flexbox layout props: direction, alignment, wrap and gap as typed tokens.

Nova Starling

Product designer

Import#

import { Flex } from "astralis-ui";
// Flex.Item is available on the component itself

Alignment#

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"

Left alone, alignItems is CSS's stretch: children fill the cross size, so a row gives you equal-height cards and a column gives you equal-width rows. That is usually what you want for a page skeleton (a sidebar reaching the full height of the row it sits in), and it is why a bare <Flex> behaves exactly like display: flex and nothing more. When you want children to keep their natural size, say so:

{/* chips that keep their own height instead of matching the tallest */}
<Flex alignItems="start" gap="2">

Flex items#

basis, flex, grow, shrink, order and alignSelf describe how an element behaves as a child, so they live on Box and work on any primitive: <Flex shrink="0"> needs no wrapper. Flex.Item declares the same props and stays the clearer spelling when a plain div is all you wanted.

basis 24

grow

order first

Responsive direction#

Every layout prop accepts a breakpoint map. The classic: stack on mobile, row on desktop.

One

Two

Three

For simple one-direction stacking, Stack is the shorter spelling.

Props#

Flex extends Box, so every style prop works here too.

PropTypeDefaultDescription
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""stretch"Alignment along the cross axis. Unset, it is CSS's stretch (children fill the cross size), so a row gives equal heights and a column gives equal widths.
wrap"wrap" | "nowrap" | "wrap-reverse""nowrap"Whether children wrap onto new lines.
gap · rowGap · columnGap"0" – "96" (spacing scale)NoneGap between children, together or per axis.
alignContent · placeContent"start" | "center" | "end" | "between" | "around" | "evenly" | "stretch"NoneMulti-line / shorthand content alignment.

Flex.Item#

PropTypeDefaultDescription
basisspacing scale | "3xs"–"8xl" | fractions | "auto" | "full" | "min" | "max" | "fit"Noneflex-basis: the item's starting size.
flex"1" | "auto" | "initial" | "none"NoneThe flex shorthand.
grow · shrinkboolean | "0" | "1"NoneWhether the item grows into / gives up free space.
order"1" – "12" | "first" | "last" | "none"NoneVisual order, independent of source order.
alignSelf"auto" | "start" | "end" | "center" | "stretch" | "baseline"NoneOverrides the container's alignItems for this item.