Flex
A flex layout whose direction and wrapping change per breakpoint, with direction-aware alignment.
Purpose
Flex is for layouts that change direction — a column on phones, a row on larger screens. Its
alignment props follow the current direction, so alignX always means "horizontal".
Import
import { Flex } from "@neshel-ui/layout";Usage
import { Flex } from "@neshel-ui/layout";
import { Tile } from "./_tile";
/** A column on small screens, a row from md: alignment props follow the direction. */
export default function FlexDirection() {
return (
<Flex
direction={{ base: "column", md: "row" }}
space="3"
alignX={{ base: "stretch", md: "start" }}
alignY="center"
>
<Tile tall>Image</Tile>
<Tile>Title and description</Tile>
<Tile>Actions</Tile>
</Flex>
);
}API
FlexProps
| Prop | Type | Default | Description |
|---|---|---|---|
| align | Responsive<MainAxisAlign> | — | — |
| alignX | Responsive<CrossAxisAlign> | — | Validated at runtime against the axis it maps to for the active direction. |
| alignY | Responsive<CrossAxisAlign> | — | — |
| as | LayoutElement | — | — |
| asChild | boolean | — | — |
| direction | Responsive<FlexDirection> | — | — |
| justify | Responsive<Justify> | — | — |
| ref | Ref<HTMLElement> | — | — |
| space | Responsive<SpaceValue> | — | — |
| spaceX | Responsive<SpaceValue> | — | — |
| spaceY | Responsive<SpaceValue> | — | — |
| wrap | Responsive<boolean> | — | — |
Also accepts the props of: React DOM attributes.
FlexDirection
type FlexDirection = "row" | "column" | "row-reverse" | "column-reverse"Direction changes and alignment
In a row, X is the main axis (justify-content); in a column, X is the cross axis (align-items).
The main axis accepts start center end; the cross axis adds stretch (and baseline in rows).
Flex validates this at runtime because the axes move with direction; when a direction change
vacates a property it is reset to normal.
Limitations
Main-axis stretch/baseline validation is exact for a static direction and at the breakpoints
where direction is written. A value inherited from a smaller breakpoint across a direction change
that is not written is not validated at runtime (known limitation carried from feature 004).
Common mistakes
- Using
Flexwith a fixeddirection="column"— that is aStack. alignX="stretch"in a row: stretch is not valid on the main axis and throws.