-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(esl-carousel): add
esl-carousel
mouse wheel control support mixin
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/modules/esl-carousel/plugin/wheel/esl-carousel.wheel.mixin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {ExportNs} from '../../../esl-utils/environment/export-ns'; | ||
import {throttle} from '../../../esl-utils/async/throttle'; | ||
import {attr, decorate, listen} from '../../../esl-utils/decorators'; | ||
import {ESLWheelEvent, ESLWheelTarget} from '../../../esl-event-listener/core'; | ||
|
||
import {ESLCarouselPlugin} from '../esl-carousel.plugin'; | ||
|
||
/** | ||
* {@link ESLCarousel} wheel control plugin mixin | ||
* Switch slides by mouse wheel | ||
* | ||
* @author Alexey Stsefanovich (ala'n) | ||
*/ | ||
@ExportNs('Carousel.Wheel') | ||
export class ESLCarouselWheelMixin extends ESLCarouselPlugin { | ||
public static override is = 'esl-carousel-wheel'; | ||
|
||
/** Prefix to request next/prev navigation */ | ||
@attr({name: ESLCarouselWheelMixin.is}) public type: 'slide' | 'group'; | ||
|
||
/** Handles auxiliary events to pause/resume timer */ | ||
@listen({ | ||
event: ESLWheelEvent.type, | ||
target: (plugin: ESLCarouselWheelMixin) => ESLWheelTarget.for(plugin.$host, {distance: 1}) | ||
}) | ||
@decorate(throttle, 400) | ||
protected _onWheel(e: ESLWheelEvent): void { | ||
if (!this.$host || this.$host.animating) return; | ||
const direction = e.deltaY > 0 ? 'next' : 'prev'; | ||
this.$host?.goTo(`${this.type || 'slide'}:${direction}`); | ||
} | ||
} | ||
|
||
declare global { | ||
export interface ESLCarouselNS { | ||
Wheel: typeof ESLCarouselWheelMixin; | ||
} | ||
} |