Masonry Grid

Pinterest-style masonry grid layout.

python 5 params

Preview

First card

Second card

Third card

Arguments
masonry_grid(items=[{'content': '<p>First card</p>', 'height': '120px'}, {'content': '<p>Second card</p>', 'height': '90px'}, {'content': '<p>Third card</p>', 'height': '140px'}])

Usage

views.py
python
from djust import LiveView
from djust.components import MasonryGrid
from django.utils.safestring import mark_safe


class MyView(LiveView):
    template_name = "my_template.html"

    def mount(self, request, **kwargs):
        self.component = MasonryGrid(items=[{'content': mark_safe('<p>First card</p>'), 'height': '120px'}, {'content': mark_safe('<p>Second card</p>'), 'height': '90px'}, {'content': mark_safe('<p>Third card</p>'), 'height': '140px'}])
my_template.html
django
{{ component }}

Parameters

NameTypeDefault
itemslist | NoneNone
columnsint3
gapint16
custom_classstr''
**kwargs— passed to `Component.__init__`: `name=` identifies the instance in the events it sends, `id=` sets `component.id`, and any other keyword is kept as state
Source & styles
FilePathNotes
moduledjust.components.components.masonry_gridSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 3 of this component's classes at line 2226, 2227, 2228. Override those rules, or the custom properties they read, in a stylesheet loaded after it.