Skip to content

Nanoviews Unordered List

The grid does not have to be a div: here BalancedMasonryGrid from @masonry-grid/nanoviews renders a ul and every Frame renders an li through the as prop, so the frames are marked up as a list. The layout is the same as in the balanced example: frames are reordered inside rows to make the grid shorter.

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.

The controls and the random frames come from controls.ts, see the whole example on GitHub.

main.ts
import {
div,
h1,
p,
li,
ul,
for_,
component$,
mount
} from 'nanoviews'
import {
BalancedMasonryGrid,
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()(
'Unordered List Masonry Grid - Nanoviews'
),
p({
class: 'description'
})(
'This example demonstrates using semantic HTML elements (ul/li) with the masonry grid.'
),
Controls(controls),
BalancedMasonryGrid({
as: ul,
class: 'container masonry-list',
gap: () => Number(controls.$gap()),
frameWidth: () => Number(controls.$frameWidth()),
style: () => ({
width: `${controls.$containerWidth()}%`
})
})(
for_($items)(
($item, $index) => Frame({
as: li,
class: 'frame',
width: () => $item().width,
height: () => $item().height,
style: () => ({
backgroundColor: $item().backgroundColor
})
})(
() => $index() + 1
)
)
)
)
)
})
mount(App, document.getElementById('root')!)