Skip to Content
Neshel-UI
Layout

@neshel-ui/layout

Layout primitives with token spacing, logical alignment, responsive values, as and asChild.

Seven primitives cover one- and two-dimensional layout. They render one element each, emit only precompiled static classes (no inline styles) and work in Server Components.

pnpm add @neshel-ui/config @neshel-ui/layout
src/index.css
@import "@neshel-ui/config/tokens.css";
@import "@neshel-ui/layout/styles.css";
PrimitiveCSSUse it for
Boxelement default, optional responsive displaySemantic wrappers, responsive show/hide
Stackflex columnVertical groups
Inlineflex rowHorizontal groups, toolbars, tags
Flexflex with responsive direction and wrapLayouts that change direction
Gridgrid with 1–12 equal columnsTwo-dimensional layouts
Centerflex centred on both axesCentring content
Containercentred max-width with an inline gutterPage-width constraints

Flexbox or Grid?

Use Stack, Inline or Flex when items flow along one axis and size themselves (toolbars, forms, card contents). Use Grid when items must line up in columns across rows (card grids, dashboards). Both use the same space tokens.

Spacing

PropCSSNotes
spacegapCannot be combined with spaceX / spaceY
spaceXcolumn-gapMay be combined with spaceY
spaceYrow-gapMay be combined with spaceX

Values are tokens "0" "0.5" "1" "1.5" "2" "2.5" "3" "4" "5" "6" "8" "10" "12" "16" "20" "24", each calc(var(--neshel-spacing) * n). <Stack space="4" spaceX="2"> is a TypeScript error and throws NeshelLayoutError at runtime. These are gap props, not Tailwind's margin-based space-x-*.

Alignment

X is the inline axis (horizontal in horizontal writing), Y the block axis.

PrimitiveXY
Stackalign-itemsjustify-content
Inlinejustify-contentalign-items
Centerjustify-content (default centre)align-items (default centre)
Gridjustify-itemsalign-items
Flexrow: justify-content, column: align-itemsrow: align-items, column: justify-content
  • align sets both axes; alignX / alignY override one axis.
  • justify (start center end between around evenly) distributes the main axis on Flex, Stack, Inline.
  • Precedence per breakpoint: justify > alignX/alignY > align.
  • Without alignment props nothing is emitted, so native stretch/normal behaviour stays.

Responsive values

Every responsive prop takes a value or { base?, sm?, md?, lg?, xl?, "2xl"? } (or your configured names). Values cascade upwards. See Custom breakpoints.

as and asChild

as picks the element from a closed list; asChild applies the layout to its single child element (Radix Slot): classes join, styles merge (child wins), handlers and refs compose. as together with asChild throws. The child must forward className and ref to a DOM element.

<Stack asChild space="4">
  <section aria-label="Settings">
    <p>Profile</p>
    <p>Preferences</p>
  </section>
</Stack>

RTL and writing modes

Keywords are logical (start/end): in right-to-left documents alignX="start" is the right edge. row-reverse does not flip X. Vertical writing modes are not supported.

Overriding styles

Layout rules live in the components.neshel cascade layer; Tailwind utilities and unlayered CSS override them: <Stack className="md:flex-row"> works. Prefer the props for responsive changes.

Shared types

Responsive

A value, or values per breakpoint that cascade upwards (mobile first).

type Responsive = T | { readonly [K in Breakpoint]?: T; }

Breakpoint

Responsive keys: base (no media query) plus the application's breakpoint names — the defaults sm md lg xl 2xl, or the names configured in neshel.config.ts once the declarations generated by neshel generate are part of the program (ADR 0010).

type Breakpoint = "base" | BreakpointName

SpaceValue

Spacing token; CSS value calc(var(--neshel-spacing) * n).

type SpaceValue = "0" | "0.5" | "1" | "1.5" | "2" | "2.5" | "3" | "4" | "5" | "6" | "8" | "10" | "12" | "16" | "20" | "24"

SpacingProps

space (CSS gap) excludes spaceX (column-gap) and spaceY (row-gap); the latter two may be combined. Also enforced at runtime.

SpacingProps
PropTypeDefaultDescription
spaceResponsive<SpaceValue>——
spaceXResponsive<SpaceValue>——
spaceYResponsive<SpaceValue>——

MainAxisAlign

Alignment on an axis that maps to justify-content.

type MainAxisAlign = "start" | "center" | "end"

CrossAxisAlign

Alignment on an axis that maps to align-items.

type CrossAxisAlign = MainAxisAlign | "stretch" | "baseline"

Justify

Main-axis distribution (justify-content).

type Justify = "start" | "center" | "end" | "between" | "around" | "evenly"

LayoutElement

Elements a primitive can render through as. Use asChild for anything else.

type LayoutElement = "div" | "span" | "section" | "article" | "aside" | "header" | "footer" | "main" | "nav" | "ul" | "ol" | "li" | "form" | "fieldset" | "figure" | "address"

PolymorphicProps

as and asChild are mutually exclusive (also enforced at runtime).

PolymorphicProps
PropTypeDefaultDescription
asLayoutElement——
asChildboolean——

CommonProps

Native attributes and the DOM ref shared by every primitive.

CommonProps
PropTypeDefaultDescription
refRef<HTMLElement>——

Also accepts the props of: React DOM attributes.

Errors

Invalid usage throws NeshelLayoutError ([@neshel-ui/layout] <Component>: …) on the server and the client: conflicting spacing, as + asChild, invalid asChild children, malformed breakpoint keys or values, a Flex main-axis stretch/baseline, separator + wrap. The error class is not exported; check error.name === "NeshelLayoutError" if you need to detect it.

Not included

Spacer (use justify or nested Inline), item-level props (grow, span), grid rows or areas and container queries. Use Tailwind utilities or your own CSS for those.

Edit on GitHub

On this page