Masonry Grid
Pinterest-style masonry grid layout.
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
| Name | Type | Default | Description |
|---|---|---|---|
| items | list | None | None | List 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. |
| columns | int | 3 | Number of columns (default: 3) |
| gap | int | 16 | Gap between items in px (default: 16) |
| custom_class | str | '' | 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
| 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 2282, 2283, 2284. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |