Command palette

@yasinsensoy/web

Web · Components

Stack

Lays out items vertically or side by side with equal gaps between them.

20 exports

Live example

Preview

One
Two long items
Three

Code

import { Stack } from "@yasinsensoy/web";

<Stack direction={{ base: "column", md: "row" }}>
  …
</Stack>

Events

  1. Events appear here when you interact with the preview.

Toolbar: push to both ends

Orders

Custom separator, inline

3 min readNovember 6, 2026New

Import

import {
  AspectRatio,
  Container,
  Grid,
  Show,
  Stack,
  VisuallyHidden,
} from "@yasinsensoy/web";

Stack

componentServer component

Lays out items vertically or side by side with equal gaps between them. Direction, gap and alignment can change with the screen width; you don't need to write responsive classes in className for that.

It is a server component; it contains no client code. Gap numbers are on the Tailwind scale and follow the UIProvider density setting.

Stack({ direction, gap, align, justify, wrap, separator, as, inline, className, style, children, ...props }: StackProps): JSX.Element

Examples

<Stack gap={2}>
  <TextField label="Name" name="name" />
  <TextField label="Email" name="email" />
</Stack>

// Stacked on mobile, side by side at md and up; with dividers between
<Stack direction={{ base: "column", md: "row" }} gap={{ base: 3, md: 6 }} separator>
  <Stat label="Revenue" value={1250} />
  <Stat label="Orders" value={84} />
</Stack>

// Toolbar: justify to both ends, center vertically
<Stack direction="row" justify="between" align="center">
  <h2>Orders</h2>
  <Button>New</Button>
</Stack>

AspectRatio

componentServer component

Shows content in a box with a fixed aspect ratio. Since space is reserved before the media loads, the page doesn't shift (CLS). Direct img, video, iframe, picture and canvas children fill the box.

It is a server component; it contains no client code.

AspectRatio({ ratio, fit, className, style, ...props }: AspectRatioProps): JSX.Element

Examples

<AspectRatio ratio={16 / 9} className="rounded-lg">
  <img src="/cover.jpg" alt="Cover" />
</AspectRatio>

<AspectRatio ratio="1">
  <iframe src="https://www.youtube.com/embed/…" title="Intro" />
</AspectRatio>

Container

componentServer component

Box that centers page content, limits the maximum width and leaves spacing at the edges. Use it with the same size on the page body, header and footer so they align.

It is a server component; it contains no client code.

Container({ size, gutter, query, as, className, style, ...props }: ContainerProps): JSX.Element

Examples

<Container as="main" className="py-8">
  <h1>Orders</h1>
</Container>

<Container size="prose">{article}</Container>

// Cards inside change by the box's width, not the screen
<Container size="md" query>
  <div className="grid @lg:grid-cols-2">…</div>
</Container>

Grid

componentServer component

Grid layout. The column count can change with the screen width or adjust itself with minItemWidth without breakpoints. To span an item across several columns give it className="col-span-2" (responsive: md:col-span-2).

It is a server component; it contains no client code.

Grid({ columns, minItemWidth, autoFlow, gap, rowGap, columnGap, align, justifyItems, dense, as, className, style, ...props }: GridProps): JSX.Element

Examples

// 1 column on mobile, 2 at sm, 4 at lg
<Grid columns={{ base: 1, sm: 2, lg: 4 }} gap={4}>
  {stats.map((s) => <Stat key={s.id} {...s} />)}
</Grid>

// Cards at least 16rem; as many columns as fit
<Grid minItemWidth="16rem" gap={6}>
  {products.map((p) => <ProductCard key={p.id} product={p} />)}
</Grid>

// Sidebar + content
<Grid columns={{ base: 1, md: "16rem 1fr" }}>
  <aside>…</aside>
  <main>…</main>
</Grid>

Show

componentServer component

Shows or hides content with CSS by screen width. Renders correctly on the server too: unlike useMediaQuery, there is no flicker on first paint or hydration mismatch. Both versions are on the page (only one is visible); if you want to load a heavy interactive component only on one screen, use useMediaQuery.

The wrapping element is display: contents; it doesn't break the layout.

It is a server component; it contains no client code.

Show({ above, below, children }: ShowProps): JSX.Element

Examples

<Show above="md"><Sidebar items={menu} /></Show>
<Show below="md"><MobileNav /></Show>

VisuallyHidden

componentServer component

Content that is invisible on screen but read by screen readers: a name for icon-only elements, a table caption, a description for a form section. It is not display: none; the content stays in the accessibility tree.

It is a server component; it contains no client code. If you only need a class, Tailwind's sr-only does the same.

VisuallyHidden({ focusable, as, className, ...props }: VisuallyHiddenProps): JSX.Element

Examples

<button type="button"><TrashIcon /><VisuallyHidden>Delete</VisuallyHidden></button>

// "Skip to content": appears top left when Tab is pressed
<VisuallyHidden as="a" href="#content" focusable
  className="focus:fixed focus:start-4 focus:top-4 focus:z-50 focus:rounded-md focus:bg-background focus:px-3 focus:py-2 focus:shadow">
  Skip to content
</VisuallyHidden>

Props of the AspectRatio component.

Extends: ComponentProps<"div">

NameTypeDefaultDescription
ratio?Responsive<number | string>16 / 9Aspect ratio: a number (16 / 9, 1) or a string ("4/3"). Can be responsive: { base: 1, md: 16 / 9 } (square on mobile, landscape on wide screens).
fit?"cover" | "contain""cover"How an image, video or iframe inside fills the box: cover fills by cropping, contain fits it whole.

Container width: sm 42rem, md 56rem, lg 72rem, xl 80rem, 2xl 96rem, prose a readable text line (~65 characters), full unlimited.

type ContainerSize = "sm" | "md" | "lg" | "xl" | "2xl" | "prose" | "full"

Props of the Container component.

Extends: ComponentProps<"div">

NameTypeDefaultDescription
size?ContainerSize"xl"Maximum width. See ContainerSize.
gutter?booleantrueHorizontal padding: 1rem on mobile, 1.5rem at sm, 2rem at lg. false disables it (e.g. for edge-to-edge media).
query?boolean | stringfalseMakes it a container query root (container-type: inline-size): elements inside change by this box's width, not the screen, with classes like @md:. With a name ("card") select it with @md/card:.
as?LayoutElement"div"Element to render (main, section…).

GridProps

interface

Props of the Grid component.

Extends: ComponentProps<"div">

NameTypeDefaultDescription
columns?Responsive<number | string>1Columns: a number is the count of equal-width columns, a string is used as is as the grid-template-columns value ("240px 1fr"). Can be responsive: { base: 1, sm: 2, lg: 4 }. Ignored if minItemWidth is given.
minItemWidth?LayoutSpaceA responsive grid without breakpoints: each column is at least this wide, and as many columns open as fit (ideal for card lists). A number is the Tailwind scale (64 = 16rem), a string a CSS length ("14rem"). If the container is narrower than this width it becomes one column without overflowing.
autoFlow?"fill" | "fit""fill"With minItemWidth, if the items don't fill the columns: fill keeps the empty columns (items keep the same width), fit spreads the items across the row.
gap?Responsive<LayoutSpace>4Gap between rows and columns (see Stack gap).
rowGap?Responsive<LayoutSpace>Gap between rows only; overrides gap.
columnGap?Responsive<LayoutSpace>Gap between columns only; overrides gap.
align?Responsive<StackAlign>"stretch"Vertical alignment within a cell (align-items).
justifyItems?Responsive<Exclude<StackAlign, "baseline">>"stretch"Horizontal alignment within a cell (justify-items).
dense?booleanfalseIf true, empty cells are filled with later smaller items (grid-auto-flow: dense); the order may change.
as?LayoutElement"div"Element to render.

Tailwind's default breakpoints (sm 40rem … 2xl 96rem).

type Breakpoint = "sm" | "md" | "lg" | "xl" | "2xl"

A single value or values that change with the screen width.

In object form base is the value for the narrowest screen; each breakpoint applies from that width up, and a missing breakpoint carries the previous one (like Tailwind's md: prefixes, mobile first). Breakpoints are Tailwind's defaults: sm 40rem, md 48rem, lg 64rem, xl 80rem, 2xl 96rem.

type Responsive = T | { /** The narrowest screen (before any breakpoint). */ base?: T; /** 40rem (640px) and up. */ sm?: T; /** 48rem (768px) and up. */ md?: T; /** 64rem (1024px) and up. */ lg?: T; /** 80rem (1280px) and up. */ xl?: T; /** 96rem (1536px) and up. */ "2xl"?: T; }

Examples

<Stack direction={{ base: "column", md: "row" }} gap={{ base: 2, lg: 6 }} />
<Grid columns={{ base: 1, sm: 2, lg: 4 }} />

Spacing value: a number is the Tailwind spacing scale (4 = gap-4 = 1rem, follows the density setting), a string is used as is as a CSS length ("2.5rem", "5%").

type LayoutSpace = number | string

ShowProps

interface

Props of the Show component.

NameTypeDescription
above?BreakpointShows at this breakpoint and above ("md" = 48rem and up).
below?BreakpointShows below this breakpoint ("md" = narrower than 48rem).
children?ReactNodeContent to show.

Direction in which items inside a Stack are laid out.

type StackDirection = "column" | "row" | "column-reverse" | "row-reverse"

Alignment on the cross axis (align-items): horizontal in a column, vertical in a row. stretch stretches the items.

type StackAlign = "start" | "center" | "end" | "stretch" | "baseline"

Distribution on the main axis (justify-content): between puts space between, around around, evenly equal space.

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

Element to render.

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

StackProps

interface

Props of the Stack component.

Extends: ComponentProps<"div">

NameTypeDefaultDescription
direction?Responsive<StackDirection>"column"Layout direction; can change with the screen width ({ base: "column", md: "row" }). See Responsive.
gap?Responsive<LayoutSpace>4Gap between items: a number is the Tailwind scale (4 = 1rem, follows the density setting), a string a CSS length ("2.5rem"). Can be responsive.
align?Responsive<StackAlign>"stretch"Alignment on the cross axis. See StackAlign.
justify?Responsive<StackJustify>"start"Distribution on the main axis. See StackJustify.
wrap?Responsive<boolean>falseShould items that don't fit wrap to the next line? For tag and button lists in the row direction.
separator?boolean | ReactNodePuts a divider between items: true a thin line in the border color, or the given element (e.g. <span>·</span>). Even if the direction changes, the divider adjusts itself (horizontal in a column, vertical in a row).
as?LayoutElement"div"Element to render (ul, nav, section…).
inline?booleanfalseIf true, it behaves like an inline element (inline-flex); for small groups like icon + text inside a sentence.

Props of the VisuallyHidden component.

Extends: ComponentProps<"span">

NameTypeDefaultDescription
focusable?booleanfalseBecome visible on keyboard focus? Use it with as="a" for a "Skip to content" link (skip link).
as?"span" | "div" | "a" | "h1" | "h2" | "h3" | "p" | "label""span"Element to render.
href?stringLink URL when as="a".