Skip to Content
Neshel-UI
Layout

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.tsx
import { Flex } from "@neshel-ui/layout";

Usage

Preview: flex-direction
Preview theme
Image
Title and description
Actions
flex-direction.tsx
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

FlexProps
PropTypeDefaultDescription
alignResponsive<MainAxisAlign>——
alignXResponsive<CrossAxisAlign>—Validated at runtime against the axis it maps to for the active direction.
alignYResponsive<CrossAxisAlign>——
asLayoutElement——
asChildboolean——
directionResponsive<FlexDirection>——
justifyResponsive<Justify>——
refRef<HTMLElement>——
spaceResponsive<SpaceValue>——
spaceXResponsive<SpaceValue>——
spaceYResponsive<SpaceValue>——
wrapResponsive<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 Flex with a fixed direction="column" — that is a Stack.
  • alignX="stretch" in a row: stretch is not valid on the main axis and throws.
Edit on GitHub

On this page