Toggle Group

Segmented toggle button group component.

python 7 params

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 = value
my_template.html
django
{{ component }}

Events this component sends to the view: toggle_select.

Parameters

NameTypeDefault
namestr''
optionslist | NoneNone
valuestr''
eventstr — renames the event'toggle_select'
sizestr'md'
custom_classstr''
**kwargs— passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state
Source & styles
FilePathNotes
moduledjust.components.components.toggle_groupSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 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.
cssdjust_theming/catalogue.cssDefines 1 of this component's classes at line 181. Override those rules, or the custom properties they read, in a stylesheet loaded after it.