Skip to Content
Neshel-UI
Layout

Stack

A vertical flex layout with token spacing, alignment and optional separators.

Purpose

Stack arranges children in a column with a consistent gap. It is the most common primitive: forms, card contents, page sections.

Import

import.tsx
import { Stack } from "@neshel-ui/layout";

Usage

Preview: stack-basic
Preview theme
First
Second, a little longer
Third
stack-basic.tsx
import { Stack } from "@neshel-ui/layout";
import { Tile } from "./_tile";

export default function StackBasic() {
  return (
    <Stack space={{ base: "2", md: "4" }} alignX="start">
      <Tile>First</Tile>
      <Tile>Second, a little longer</Tile>
      <Tile>Third</Tile>
    </Stack>
  );
}

API

StackProps

StackProps
PropTypeDefaultDescription
alignResponsive<MainAxisAlign>——
alignXResponsive<"start" | "center" | "end" | "stretch">——
alignYResponsive<MainAxisAlign>——
asLayoutElement——
asChildboolean——
justifyResponsive<Justify>——
refRef<HTMLElement>——
separatorSeparatorProp——
spaceResponsive<SpaceValue>——
spaceXResponsive<SpaceValue>——
spaceYResponsive<SpaceValue>——

Also accepts the props of: React DOM attributes.

  • alignX maps to align-items (start center end stretch), alignY to justify-content.
  • justify distributes the vertical axis when the Stack is taller than its content.

Separators

Preview: stack-separator
Preview theme
  • Profile
  • Security
  • Notifications
stack-separator.tsx
import { Inline, Stack } from "@neshel-ui/layout";
import { Text } from "@neshel-ui/typography";

const items = ["Profile", "Security", "Notifications"];

export default function StackSeparator() {
  return (
    <Stack space="6">
      {/* true: a decorative rule between items; inside a <ul> it is rendered as an <li>. */}
      <Stack as="ul" space="3" separator>
        {items.map((item) => (
          <li key={item}>{item}</li>
        ))}
      </Stack>
      {/* A custom separator element is inserted unchanged between items. */}
      <Inline as="nav" aria-label="Footer" space="3" separator={<Text aria-hidden="true">·</Text>}>
        <a href="#privacy">Privacy</a>
        <a href="#terms">Terms</a>
        <a href="#contact">Contact</a>
      </Inline>
    </Stack>
  );
}

SeparatorProp

true renders the default decorative separator; an element renders that element.

type SeparatorProp = boolean | ReactElement
  • separator (true) renders a decorative rule (aria-hidden, colour --neshel-border) between rendered items — an li inside ul/ol, a span inside span, otherwise a div.
  • A custom element is inserted unchanged (only a key is added) and keeps its own semantics.
  • null, undefined, booleans and "" children are skipped; a Fragment counts as one item.
  • separator together with wrap throws (a wrapped line could start with a separator).

Responsive

Every spacing and alignment prop is responsive: space={{ base: "2", md: "6" }}.

Composition

as="ul" (or ol) makes a list; children should then be li. With asChild, the stack styles go to your element and separators are inserted inside it (a component child with separator throws).

Common mistakes

  • Adding margins to children to space them: let space do it so the rhythm stays consistent.
  • space with spaceY together: a type error and a runtime error.
Edit on GitHub

On this page