Vitral 0.2.18
Layout

Masonry

Items of different heights in columns with no gaps under the short ones, laid out in reading order, so a keyboard and a screen reader go left to right as the eye does.

Import

main.ts
import { Masonry } from '@vitral/vue';

Cards

Each item goes into the column that is shortest so far. Resize the window: there are as many columns as fit `min-column-width`, and an item that grows (open one) moves the ones under it.

Groceries

Rice, beans, coffee, lemons.

Ideas for the talk

Open with the stained-glass metaphor. Show tokens before components. End on the theme designer, live, with the audience picking the primary colour.

Call Ana

About the release.

Reading

Chapters 4 to 6, and the notes on accessibility of drag and drop — the keyboard part especially.

Gym

Tuesday and Thursday.

Trip

Book the train to Lisboa. Check the museum hours. Ask Bruno about the restaurant near the river he mentioned.

Plants

Water on Sundays.

Budget

Rent, internet, the course, and something put aside every month however small.

<script setup lang="ts">import { Card, Masonry } from '@vitral/vue';import { ref } from 'vue'; const notes = [    { title: 'Groceries', text: 'Rice, beans, coffee, lemons.' },    { title: 'Ideas for the talk', text: 'Open with the stained-glass metaphor. Show tokens before components. End on the theme designer, live, with the audience picking the primary colour.' },    { title: 'Call Ana', text: 'About the release.' },    { title: 'Reading', text: 'Chapters 4 to 6, and the notes on accessibility of drag and drop — the keyboard part especially.' },    { title: 'Gym', text: 'Tuesday and Thursday.' },    { title: 'Trip', text: 'Book the train to Lisboa. Check the museum hours. Ask Bruno about the restaurant near the river he mentioned.' },    { title: 'Plants', text: 'Water on Sundays.' },    { title: 'Budget', text: 'Rent, internet, the course, and something put aside every month however small.' }];const open = ref<number | null>(null);</script> <template>    <Masonry min-column-width="12rem">        <Card v-for="(note, i) in notes" :key="note.title">            <template #title>{{ note.title }}</template>            <template #default>                <p style="margin: 0">{{ note.text }}</p>                <p v-if="open === i" style="margin: 0.5rem 0 0">More lines, shown on demand, push the cards below down.</p>                <button type="button" class="vt-button vt-button-text vt-button-sm" style="margin-top: 0.5rem" @click="open = open === i ? null : i">{{ open === i ? 'Less' : 'More' }}</button>            </template>        </Card>    </Masonry></template>

A fixed number of columns

`columns` fixes the count, and `gap` the space between. Images are measured again as they load.

Photo 1Photo 2Photo 3Photo 4Photo 5Photo 6Photo 7Photo 8Photo 9
<script setup lang="ts">import { Masonry } from '@vitral/vue'; // Blocks of colour with the proportions of photographs, drawn inline.const shapes = [    [4, 5, '#fca5a5'],    [4, 3, '#fdba74'],    [1, 1, '#fcd34d'],    [3, 4, '#86efac'],    [16, 9, '#67e8f9'],    [2, 3, '#93c5fd'],    [4, 3, '#c4b5fd'],    [1, 1, '#f9a8d4'],    [3, 4, '#a5b4fc']] as const;const src = (w: number, h: number, fill: string) =>    'data:image/svg+xml;utf8,' + encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${w * 100} ${h * 100}"><rect width="100%" height="100%" fill="${fill}"/></svg>`);</script> <template>    <Masonry :columns="3" gap="0.5rem">        <img v-for="([w, h, fill], i) in shapes" :key="i" :src="src(w, h, fill)" :alt="`Photo ${i + 1}`" style="display: block; width: 100%; border-radius: 0.5rem" />    </Masonry></template>

API

Read from packages/vue/src/components/Masonry/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
columns numberA fixed number of columns; otherwise as many as fit `minColumnWidth`.
minColumnWidth stringAny CSS length; the theme's (`15rem`) otherwise.
gap stringAny CSS length; the theme's (`1rem`) otherwise.

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Slots

NameSlot propsDescription
default —The items, one element each, in reading order.