Masonry Grid
Pinterest-style masonry grid layout.
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
| Name | Type | Default |
|---|---|---|
| items | list | None | None |
| columns | int | 3 |
| gap | int | 16 |
| custom_class | str | '' |
| **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
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.masonry_grid | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 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. |