Toggle Group
Segmented toggle button group component.
Preview
Arguments
toggle_group(name='view', options=[{'value': 'list', 'label': 'List'}, {'value': 'grid', 'label': 'Grid'}], value='list')Usage
views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import ToggleGroup
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = ToggleGroup(name='view', options=[{'value': 'list', 'label': 'List'}, {'value': 'grid', 'label': 'Grid'}], value='list')
@event_handler()
def toggle_select(self, value, **kwargs):
self.component.value = valuemy_template.html
django
{{ component }}Events this component sends to the view: toggle_select.
Parameters
| Name | Type | Default |
|---|---|---|
| name | str | '' |
| options | list | None | None |
| value | str | '' |
| event | str — renames the event | 'toggle_select' |
| size | str | 'md' |
| custom_class | str | '' |
| **kwargs | — passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.toggle_group | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 4 of this component's classes at line 987, 988, 991, 998. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
| css | djust_theming/catalogue.css | Defines 1 of this component's classes at line 181. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |