Masonry
RC.12.1
Included in RC.12.1 for Vue + Vite, Nuxt and NativeScript.
<MMasonry
:items="items"
label="Inspiration"
:columns="3"
><template #item="{ item }"><MCard><MText :text="item.id" /></MCard></template></MMasonry>| Prop | Type | Default | Contract |
|---|---|---|---|
items | readonly MasonryItem[] | required | Unique stable id and optional estimatedHeight. Up to 500 items; app metadata is preserved. |
columns / minColumnWidth | number | 4 / 220 | Maximum 1–12 columns and minimum width >=40 pixels/DIP. Uses available container width. |
gap / animated | Spacing / boolean | md / true | Token or numeric spacing and Jolt layout changes. |
label / id | string | required / optional | Accessible component name and optional stable ID. |
The item slot receives { item, index, width }. Each item is measured and placed in the shortest column while preserving logical DOM/native order and stable identity. Reading and keyboard order follow the original collection. Late image/font measurements update the layout. Initial SSR uses one estimated column and is enhanced after measurement. Give images a height or aspect ratio to reduce initial movement. This is a bounded, non-virtualized collection; use MVirtualList for long feeds. Height changes, filtering, reordering and container resizing use Jolt when animated=true. Observers stop on deactivation/unmount.
item slot → { item, index, width }.
The first time the collection is on screen, tiles rise in reading order, top to bottom, once; tiles added later arrive the same way. A tile that receives focus settles at once, and server-rendered markup starts drawn.
Motion uses Jolt and respects reduced motion. Use :animated="false" for static presentation.
<script setup lang="ts">
import { computed, ref, onBeforeUnmount } from 'vue'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const t = (en: string, pt: string) => ((props.lang ?? locale.value) === 'pt' ? pt : en)
const animated = ref(true)
import { mountains, coast } from '../atlas/photos'
const reverse = ref(false),
query = ref(''),
notes = ref<Record<string, string>>({})
const source = computed(() => [
{
id: 'horizon',
title: t('Chasing the horizon', 'Em busca do horizonte'),
image: mountains,
height: 210,
},
{
id: 'thought',
title: t('Collect moments, not things.', 'Colecione momentos, não coisas.'),
quote: true,
height: 140,
},
{
id: 'shore',
title: t('Where the land exhales', 'Onde a terra respira'),
image: coast,
height: 290,
},
{
id: 'note',
title: t('A place for the unfinished', 'Um lugar para o inacabado'),
note: true,
height: 170,
},
{
id: 'palette',
title: t('The colors we carry', 'As cores que levamos'),
palette: true,
height: 100,
},
{
id: 'small',
title: t('Leave room for a surprise.', 'Deixe espaço para uma surpresa.'),
quote: true,
height: 100,
},
])
const items = computed(() => {
const rows = source.value.filter((x) => x.title.toLowerCase().includes(query.value.toLowerCase()))
return reverse.value ? [...rows].reverse() : rows
})
const entry = (id: string) => source.value.find((x) => x.id === id)!
</script>
<template>
<MColumn gap="lg">
<MText text="THE FIELD GUIDE / 02" variant="overline" tone="primary" />
<MText
:text="t('A collection with its own rhythm.', 'Uma coleção com seu próprio ritmo.')"
variant="title"
/>
<MRow gap="sm" wrap
><MInput v-model="query" :label="t('Filter collection', 'Filtrar coleção')" /><MButton
:text="t('Reverse collection', 'Inverter coleção')"
variant="secondary"
@click="reverse = !reverse"
/></MRow>
<MMasonry
id="studio-masonry"
:items="items"
:columns="3"
:minColumnWidth="210"
:animated="animated"
:label="t('Collected inspirations', 'Inspirações colecionadas')"
>
<template #item="{ item }"
><MCard :id="'masonry-' + item.id" padding="none"
><MColumn gap="none">
<MImage
v-if="entry(item.id).image"
:src="entry(item.id).image!"
:height="entry(item.id).height"
:alt="entry(item.id).title"
/>
<MBox v-if="entry(item.id).quote" padding="lg" :height="entry(item.id).height"
><MText :text="entry(item.id).title" variant="heading"
/></MBox>
<MColumn padding="md" gap="md"
><MText v-if="!entry(item.id).quote" :text="entry(item.id).title" variant="heading" />
<MRow v-if="entry(item.id).palette" gap="xs"
><MBox
v-for="color in ['#809587', '#E6B68B', '#A48086', '#D7CEB9']"
:key="color"
:backgroundColor="color"
:width="36"
:height="70"
radius="sm"
/></MRow>
<MInput
v-if="entry(item.id).note"
v-model="notes[item.id]"
:label="t('A thought to keep', 'Uma ideia para guardar')" />
<MText
:text="t('From the studio journal', 'Do caderno do estúdio')"
variant="caption"
tone="muted"
/></MColumn> </MColumn></MCard
></template>
</MMasonry>
<MSwitch v-model="animated" :label="t('Animate changes', 'Animar mudanças')" />
</MColumn>
</template>On Web, iOS and Android, removing a tile lets its neighbours move into the available space. A visual copy can finish the exit after the tile has left the data. Pass :animated="false" to settle the grid immediately.
Desktop
The desktop host measures each tile and distributes tiles across columns using masonryLayout. Changing the available width or moving a tile animates the new arrangement. A removed tile fades at its previous position. Reduced motion applies the layout immediately. See Desktop components.