Carousel

Image carousel/slideshow component.

python 7 params

Preview

Arguments
carousel(images=[{'src': 'https://picsum.photos/seed/one/600/300', 'alt': 'First slide', 'caption': 'Slide one'}, {'src': 'https://picsum.photos/seed/two/600/300', 'alt': 'Second slide', 'caption': 'Slide two'}], active=0, total=0)

Usage

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


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

    def mount(self, request, **kwargs):
        self.component = Carousel(images=[{'src': 'https://picsum.photos/seed/one/600/300', 'alt': 'First slide', 'caption': 'Slide one'}, {'src': 'https://picsum.photos/seed/two/600/300', 'alt': 'Second slide', 'caption': 'Slide two'}], active=0)

    @event_handler()
    def carousel_prev(self, **kwargs):
        self.component.active = self.component.active - 1

    @event_handler()
    def carousel_next(self, **kwargs):
        self.component.active = self.component.active + 1

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

Events this component sends to the view: carousel_prev, carousel_next, carousel_go.

Parameters

NameTypeDefault
imageslist | NoneNone
activeint0
prev_eventstr — renames the event; identity is `name`'carousel_prev'
next_eventstr — renames the event; identity is `name`'carousel_next'
go_eventstr — renames the event; identity is `name`'carousel_go'
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.carouselSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 12 of this component's classes at line 853, 855, 856, 857, 858, 859, 860, 862, 863, 864, 865, 867. Override those rules, or the custom properties they read, in a stylesheet loaded after it.