Skip to content

Commit

Permalink
feat(esl-carousel): add esl-carousel mouse wheel control support mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
ala-n committed Jan 6, 2024
1 parent a421428 commit 748390c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions site/src/localdev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
ESLCarouselNavDots,
ESLCarouselNavMixin,
ESLCarouselTouchMixin,
ESLCarouselWheelMixin,
ESLCarouselKeyboardMixin,
ESLCarouselRelateToMixin,
ESLCarouselAutoplayMixin
Expand Down Expand Up @@ -119,6 +120,7 @@ ESLCarouselTouchMixin.register();
ESLCarouselKeyboardMixin.register();
ESLCarouselRelateToMixin.register();
ESLCarouselAutoplayMixin.register();
ESLCarouselWheelMixin.register();

ESLAnimate.register();
ESLAnimateMixin.register();
Expand Down
3 changes: 3 additions & 0 deletions src/modules/esl-carousel/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export * from './plugin/autoplay/esl-carousel.autoplay.mixin';
// Link Utility
export * from './plugin/relation/esl-carousel.relation.mixin';

// Wheel support
export * from './plugin/wheel/esl-carousel.wheel.mixin';

// Renderer Default
import './renderers/multi/esl-multi-carousel';
import './renderers/slide/esl-slide-carousel';
38 changes: 38 additions & 0 deletions src/modules/esl-carousel/plugin/wheel/esl-carousel.wheel.mixin.ts
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;
}
}

0 comments on commit 748390c

Please sign in to comment.