@sol-parts/sol-stimulus-components · документація
Контролер slideshow
Слайдер на серверній розмітці: нескінченний loop через клони країв, автоплей із паузою на hover і поза фокусом вікна, пагінація та свайп-гортання у парі з контролером swipe.
Живе демо
Автоплей кожні 5 секунд; наведіть курсор або перемкніть вкладку — гортання стане на паузу. Слайди можна тягнути мишею чи свайпом.
Installation
With npm or any bundler:
npm install @sol-parts/sol-stimulus-components stimulus-use
With Symfony AssetMapper:
php bin/console importmap:require stimulus-use
php bin/console importmap:require @sol-parts/sol-stimulus-components/slideshow
The window-focus autoplay pause uses the package's stimulus-use peer dependency. The swipe controller itself does not use it.
Usage
import { Application } from '@hotwired/stimulus';
import Slideshow from '@sol-parts/sol-stimulus-components/slideshow';
import Swipe from '@sol-parts/sol-stimulus-components/swipe';
const app = Application.start();
app.register('slideshow', Slideshow);
app.register('swipe', Swipe); // for gesture support
Markup
The slideshow renders from your own markup: slides are slide targets, the sliding track is the wrapper target, pagination dots are paginationItem targets — the class attributes of the first two dots define the active and the normal look. Pagination is optional: edge slides are cloned automatically for seamless looping whether dots are rendered or not.
Clones are hidden from assistive technology and kept out of the tab order, and under prefers-reduced-motion: reduce slides change instantly instead of animating.
<div data-controller="slideshow swipe"
data-slideshow-autoplay-interval-value="5000"
data-action="swipe:swipeLeft->slideshow#next
swipe:swipeRight->slideshow#prev
swipe:dragStart->slideshow#transformOff
swipe:dragging->slideshow#dragging
swipe:dragEnd->slideshow#dragEnd">
<div data-slideshow-target="wrapper" style="display: flex">
<a data-slideshow-target="slide" href="…"><img src="…" alt=""></a>
<a data-slideshow-target="slide" href="…"><img src="…" alt=""></a>
</div>
<button data-action="slideshow#prev">‹</button>
<button data-action="slideshow#next">›</button>
<div>
<button data-slideshow-target="paginationItem" class="dot dot-active" data-action="slideshow#go" data-slideshow-n-param="1"></button>
<button data-slideshow-target="paginationItem" class="dot" data-action="slideshow#go" data-slideshow-n-param="2"></button>
</div>
</div>
Values
| Value | Default | Purpose |
|---|---|---|
autoplayInterval | 0 (off) | autoplay period in ms; pauses on hover and while the window is out of focus |
dynamicAspect | true | animate the container aspect-ratio per slide; when false it is fixed to the first slide |
Actions
next, prev, go (with data-slideshow-n-param), plus dragging / dragEnd / transformOff for wiring up the swipe controller as shown in the markup above.
Turbo notes
Edge clones are marked with data-slideshow-clone and removed on reconnect, so cached Turbo snapshots restore correctly; inline styles are reset in disconnect(). The controller never relies on DOMContentLoaded.