Accordion

Accordion/collapsible sections component.

python 5 params

Preview

A reactive Django framework.
Arguments
accordion(items=[{'id': '1', 'title': 'What is djust?', 'content': 'A reactive Django framework.'}, {'id': '2', 'title': 'How does it work?', 'content': 'Server-side rendering with live updates.'}], active='1', multiple=False)

Usage

views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import Accordion


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

    def mount(self, request, **kwargs):
        self.component = Accordion(items=[{'id': '1', 'title': 'What is djust?', 'content': 'A reactive Django framework.'}, {'id': '2', 'title': 'How does it work?', 'content': 'Server-side rendering with live updates.'}], active='1')

    @event_handler()
    def accordion_toggle(self, value, **kwargs):
        self.component.active = "" if self.component.active == value else value
my_template.html
django
{{ component }}

Events this component sends to the view: accordion_toggle.

Parameters

NameTypeDefault
itemslist | NoneNone
activestr''
eventstr — renames the event; identity is `name`'accordion_toggle'
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.accordionSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 6 of this component's classes at line 76, 77, 78, 81, 83, 2420. Override those rules, or the custom properties they read, in a stylesheet loaded after it.