Nanoviews Regular Grid
RegularMasonryGrid from @masonry-grid/nanoviews keeps the frames in their source order: each frame is pulled up to the frame above it, so the columns can end at different heights. Pick it when the order matters, for example in a feed sorted by date. Every Frame gets the width and height of its content, and the grid places the frame by this aspect ratio without waiting for images to load.
Use the controls above the grid to change the number of frames, the minimum frame width (frameWidth), the gap and the width of the container.
Source code
Section titled “Source code”The controls and the random frames come from controls.ts, see the whole example on GitHub.
import { div, h1, for_, component$, mount} from 'nanoviews'import { RegularMasonryGrid, Frame} from '@masonry-grid/nanoviews'import { Controls, createControls, createItems} from './controls'import './index.css'
const App = component$(() => { const controls = createControls() const $items = createItems(() => Number(controls.$itemsCount()))
return ( div({ class: 'container' })( h1()( 'Masonry Grid - Nanoviews' ), Controls(controls), RegularMasonryGrid({ class: 'container', gap: () => Number(controls.$gap()), frameWidth: () => Number(controls.$frameWidth()), style: () => ({ width: `${controls.$containerWidth()}%` }) })( for_($items)( ($item, $index) => Frame({ class: 'frame', width: () => $item().width, height: () => $item().height, style: () => ({ backgroundColor: $item().backgroundColor }) })( () => $index() + 1 ) ) ) ) )})
mount(App, document.getElementById('root')!)