Masonry Grid

Pinterest-style masonry grid layout.

python 5 params

Preview

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

Usage

views.py
python
from djust import LiveView
from djust.components import MasonryGrid


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

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

Parameters

NameTypeDefaultDescription
itemslist | NoneNoneList of dicts with ``content``, optional ``height``, ``class``. ``content`` is text and is escaped. Markup the app built itself can be passed as ``mark_safe(...)`` to the class or the Django tag; the Rust template engine receives list arguments as data and escapes ``content`` either way.
columnsint3Number of columns (default: 3)
gapint16Gap between items in px (default: 16)
custom_classstr''Additional CSS classes
**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 2282, 2283, 2284. Override those rules, or the custom properties they read, in a stylesheet loaded after it.