Skip to Content

masonry-grid

ui

CSS columns-based variable-height grid layout.

Source Code

View the full component source code below.

"use client"

import * as React from "react"

import { cn } from "@/lib/utils"

function MasonryGrid({
  children,
  columns = 3,
  gap = "1rem",
  className,
  ...props
}: {
  children: React.ReactNode
  columns?: number
  gap?: string
} & React.ComponentProps<"div">) {
  return (
    <div
      data-slot="masonry-grid"
      className={cn("[&>*]:break-inside-avoid", className)}
      style={{
        columns,
        columnGap: gap,
      }}
      {...props}
    >
      {React.Children.map(children, (child) => (
        <div style={{ marginBottom: gap }}>{child}</div>
      ))}
    </div>
  )
}

export { MasonryGrid }

Installation

npx shadcn@latest add https://registry.mukoko.com/api/v1/ui/masonry-grid

API

Fetch this component's metadata and source code from the registry API.

GET/api/v1/ui/masonry-grid

Source

components/ui/masonry-grid.tsx