Tree View

Expandable tree view component.

python 6 params

Preview

Arguments
tree_view(nodes=[{'id': 'src', 'label': 'src', 'expanded': True, 'children': [{'id': 'src/app', 'label': 'app.py'}, {'id': 'src/util', 'label': 'util.py'}]}, {'id': 'tests', 'label': 'tests', 'children': []}])

Usage

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


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

    def mount(self, request, **kwargs):
        self.component = TreeView(nodes=[{'id': 'src', 'label': 'src', 'expanded': True, 'children': [{'id': 'src/app', 'label': 'app.py'}, {'id': 'src/util', 'label': 'util.py'}]}, {'id': 'tests', 'label': 'tests', 'children': []}])

    @event_handler()
    def tree_expand(self, **kwargs):
        self.component.nodes = ...  # `toggle_node` — see this component's docs

    @event_handler()
    def tree_select(self, value, **kwargs):
        self.component.selected = value
my_template.html
django
{{ component }}

Events this component sends to the view: tree_expand, tree_select.

Parameters

NameTypeDefault
nodeslist | NoneNone
expand_eventstr — renames the event; identity is `name`'tree_expand'
select_eventstr — renames the event; identity is `name`'tree_select'
selectedstr''
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.tree_viewSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 8 of this component's classes at line 827, 828, 829, 831, 833, 834, 837, 838. Override those rules, or the custom properties they read, in a stylesheet loaded after it.