File Tree
File browser tree with icons, expand/collapse, and selection.
Preview
app.py
util.py
README.md
Arguments
file_tree(nodes=[{'name': 'src', 'type': 'folder', 'children': [{'name': 'app.py', 'type': 'file'}, {'name': 'util.py', 'type': 'file'}]}, {'name': 'README.md', 'type': 'file'}], selected='src/app.py')Usage
views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import FileTree
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = FileTree(nodes=[{'name': 'src', 'type': 'folder', 'children': [{'name': 'app.py', 'type': 'file'}, {'name': 'util.py', 'type': 'file'}]}, {'name': 'README.md', 'type': 'file'}], selected='src/app.py')
@event_handler()
def select_file(self, value, **kwargs):
self.component.selected = valuemy_template.html
django
{{ component }}Events this component sends to the view: select_file.
Needs a client hook djust does not ship: dj-hook="FileTree". The markup renders, but the interaction described above is yours to add — register window.djust.hooks.FileTree = { mounted() { … } } before client.js loads (see the hooks guide).
Parameters
| Name | Type | Default |
|---|---|---|
| nodes | list | None | None |
| selected | str | '' |
| event | str — renames the event; identity is `name` | 'select_file' |
| show_icons | bool | True |
| 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.file_tree | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 9 of this component's classes at line 2129, 2130, 2133, 2134, 2135, 2136, 2429, 2430, 2431. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |