masonry-grid
A masonry layout for any items of different heights (cards, notes, photos): packed into columns as wide as column allows, while the order stays the reading order, so Tab, screen readers and search see the items left to right, top to bottom, as written. Browsers with native masonry (CSS grid lanes) lay it out themselves; the others get a small script that measures each item.
Groceries
Oats, apples, coffee, the good bread from the market.
Ideas for the bake sale
Lemon bars. Name cards for each tray. A jar for change. Ask Sam about the folding tables and whether the church has an extension cord.
Call back
The plumber, before Thursday.
Reading
Finish chapter six. Write down the two quotes about gardens before returning it to the library.
Birthday
Order the cake on Monday.
Trip checklist
Chargers, rain jacket, the map, snacks for the drive, tickets printed, and a book for the train in case the signal drops.
This one has no events: it shows what it's given.
Source: masonry-grid.zb, and its registry item.
Install
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/masonry-grid.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/masonry-grid.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/masonry-grid.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/masonry-grid.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/masonry-grid.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/masonry-grid.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/masonry-grid.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/masonry-grid.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/masonry-grid.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/masonry-grid.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/masonry-grid.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/masonry-grid.json
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/masonry-grid.js"></script>The compiled install writes src/components/zubra/masonry-grid.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.
Usage
<masonry-grid column="12rem" gap="0.75rem">
<article><h3>Groceries</h3><p>Oats, apples, coffee, the good bread from the market.</p></article>
<article><h3>Ideas for the bake sale</h3><p>Lemon bars. Name cards for each tray. A jar for change. Ask Sam about the folding tables and whether the church has an extension cord.</p></article>
<article><h3>Call back</h3><p>The plumber, before Thursday.</p></article>
<article><h3>Reading</h3><p>Finish chapter six. Write down the two quotes about gardens before returning it to the library.</p></article>
<article><h3>Birthday</h3><p>Order the cake on Monday.</p></article>
<article><h3>Trip checklist</h3><p>Chargers, rain jacket, the map, snacks for the drive, tickets printed, and a book for the train in case the signal drops.</p></article>
</masonry-grid>
<script type="module">
import './components/zubra/masonry-grid.js';
</script>import './components/zubra/masonry-grid.js';
export function MasonryGridExample() {
return (
<masonry-grid column="12rem" gap="0.75rem">
<article><h3>Groceries</h3><p>Oats, apples, coffee, the good bread from the market.</p></article>
<article><h3>Ideas for the bake sale</h3><p>Lemon bars. Name cards for each tray. A jar for change. Ask Sam about the folding tables and whether the church has an extension cord.</p></article>
<article><h3>Call back</h3><p>The plumber, before Thursday.</p></article>
<article><h3>Reading</h3><p>Finish chapter six. Write down the two quotes about gardens before returning it to the library.</p></article>
<article><h3>Birthday</h3><p>Order the cake on Monday.</p></article>
<article><h3>Trip checklist</h3><p>Chargers, rain jacket, the map, snacks for the drive, tickets printed, and a book for the train in case the signal drops.</p></article>
</masonry-grid>
);
}<script setup>
import './components/zubra/masonry-grid.js';
</script>
<template>
<masonry-grid column="12rem" gap="0.75rem">
<article><h3>Groceries</h3><p>Oats, apples, coffee, the good bread from the market.</p></article>
<article><h3>Ideas for the bake sale</h3><p>Lemon bars. Name cards for each tray. A jar for change. Ask Sam about the folding tables and whether the church has an extension cord.</p></article>
<article><h3>Call back</h3><p>The plumber, before Thursday.</p></article>
<article><h3>Reading</h3><p>Finish chapter six. Write down the two quotes about gardens before returning it to the library.</p></article>
<article><h3>Birthday</h3><p>Order the cake on Monday.</p></article>
<article><h3>Trip checklist</h3><p>Chargers, rain jacket, the map, snacks for the drive, tickets printed, and a book for the train in case the signal drops.</p></article>
</masonry-grid>
</template>
<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) --><script>
import './components/zubra/masonry-grid.js';
</script>
<masonry-grid column="12rem" gap="0.75rem">
<article><h3>Groceries</h3><p>Oats, apples, coffee, the good bread from the market.</p></article>
<article><h3>Ideas for the bake sale</h3><p>Lemon bars. Name cards for each tray. A jar for change. Ask Sam about the folding tables and whether the church has an extension cord.</p></article>
<article><h3>Call back</h3><p>The plumber, before Thursday.</p></article>
<article><h3>Reading</h3><p>Finish chapter six. Write down the two quotes about gardens before returning it to the library.</p></article>
<article><h3>Birthday</h3><p>Order the cake on Monday.</p></article>
<article><h3>Trip checklist</h3><p>Chargers, rain jacket, the map, snacks for the drive, tickets printed, and a book for the train in case the signal drops.</p></article>
</masonry-grid>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/masonry-grid.js';
@Component({
selector: 'app-masonry-grid-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<masonry-grid column="12rem" gap="0.75rem">
<article><h3>Groceries</h3><p>Oats, apples, coffee, the good bread from the market.</p></article>
<article><h3>Ideas for the bake sale</h3><p>Lemon bars. Name cards for each tray. A jar for change. Ask Sam about the folding tables and whether the church has an extension cord.</p></article>
<article><h3>Call back</h3><p>The plumber, before Thursday.</p></article>
<article><h3>Reading</h3><p>Finish chapter six. Write down the two quotes about gardens before returning it to the library.</p></article>
<article><h3>Birthday</h3><p>Order the cake on Monday.</p></article>
<article><h3>Trip checklist</h3><p>Chargers, rain jacket, the map, snacks for the drive, tickets printed, and a book for the train in case the signal drops.</p></article>
</masonry-grid>
`,
})
export class MasonryGridExample {
}API
| Property | Type | Default |
|---|---|---|
column | string | "16rem" |
gap | string | "1rem" |
| Slot | For |
|---|---|
(default) | The items: any elements. |
Size
0.9 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 17.5 KB.