PhiaUi.Components.Layout.MasonryGrid (phia_ui v0.1.17)

Copy Markdown View Source

CSS columns masonry grid — items flow top-to-bottom in columns like a Pinterest board or photo wall.

Unlike CSS Grid, items fill columns from top to bottom, so shorter items pack into gaps left by taller items. Use break-inside-avoid on children to prevent items from splitting across columns.

All layout attributes accept either a plain value (backward compatible) or a responsive map like %{base: 1, md: 3} for per-breakpoint control.

Examples

<%!-- 3-column masonry --%>
<.masonry_grid cols={3} gap={4}>
  <%= for card <- @cards do %>
    <div class="break-inside-avoid mb-4">
      <.card>{card.content}</.card>
    </div>
  <% end %>
</.masonry_grid>

<%!-- Responsive masonry: 1 col on mobile, 2 from md, 3 from lg --%>
<.masonry_grid cols={%{base: 1, md: 2, lg: 3}} gap={%{base: 2, md: 4}}>
  ...
</.masonry_grid>

<%!-- 2-column narrow layout --%>
<.masonry_grid cols={2} gap={3}>
  ...
</.masonry_grid>

Summary

Functions

Renders a CSS columns masonry grid.

Functions

masonry_grid(assigns)

Renders a CSS columns masonry grid.

Attributes

  • cols (:any) - Number of columns (1–5) → columns-N. Accepts integer or responsive map. Defaults to 3.
  • gap (:any) - Gap between columns (0–12) → gap-N. Accepts integer or responsive map. Defaults to 4.
  • class (:string) - Additional CSS classes merged via cn/1. Defaults to nil.
  • Global attributes are accepted. HTML attributes forwarded to the root element.

Slots

  • inner_block (required) - Masonry children (use break-inside-avoid on each).