Skip to content

MasonryLayout

SM · 950B gzip budget

Variable-height masonry grid with load-more support.

Category
Media & layout
Budget
sm, single-purpose control
External runtime
React / React DOM only
axe fixtureSSR rendersource scanbundle budget

Preview

Live fixture
Preview locale
A
B

Try the component here. Locale-aware formatting and direction follow the selected language; example content and labels are not automatically translated. Overlay demos use interactive launchers.

Install

npx shadcn@latest add https://gear5-ui.vercel.app/r/masonry-layout.json

Copies the source into your project.

New here? Set up Tailwind and import aliases first →

Source & props

Edit on GitHub ↗

Prop types and inline documentation are included below. This is repository source; the installer rewrites shared imports for your project.

"use client";

import React from "react";

export interface MasonryLayoutProps {
  children: React.ReactNode;
  columns?: number;
  gap?: string;
  className?: string;
  ariaLabel?: string;
}

export function MasonryLayout({
  children,
  columns = 3,
  gap = "1rem",
  className = "",
  ariaLabel,
}: MasonryLayoutProps) {
  const columnStyle: React.CSSProperties = {
    display: "flex",
    flexDirection: "column",
    gap,
    breakInside: "avoid",
  };

  const columnsArray = Array.from({ length: columns }, (_, i) => i);

  const childArray = React.Children.toArray(children);
  const distributed = columnsArray.map(() => [] as React.ReactNode[]);

  childArray.forEach((child, index) => {
    distributed[index % columns].push(child);
  });

  return (
    <div
      role="group"
      aria-label={ariaLabel}
      className={className}
      style={{
        columnCount: columns,
        columnGap: gap,
      }}
    >
      {distributed.map((column, colIndex) => (
        <div key={colIndex} style={columnStyle}>
          {column}
        </div>
      ))}
    </div>
  );
}

What CI checks

Quality contract
  • Bundled, minified and gzipped against its tier budget
  • Audited by axe in the state previewed above
  • Rendered through react-dom/server with no browser globals
  • Scanned for network calls, dangerous sinks, and unguarded animation