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.components.carousel 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

NameTypeDefaultDescription
imageslist | NoneNonelist of dicts with keys: src, alt, caption
activeint00-based index of active slide prev_event, next_event, go_event: dj-click events
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 879, 881, 882, 883, 884, 885, 886, 888, 889, 890, 891, 893. Override those rules, or the custom properties they read, in a stylesheet loaded after it.