-
Notifications
You must be signed in to change notification settings - Fork 8
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): support for relation mixin plugin for ESLCarousel…
… component
- Loading branch information
Showing
9 changed files
with
84 additions
and
97 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
@import "./core"; | ||
|
||
@import "./plugin/esl-carousel-plugin.less"; | ||
|
||
@import "./plugin/nav/esl-carousel.nav.arrows.less"; | ||
@import "./plugin/nav/esl-carousel.nav.dots.less"; |
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
77 changes: 0 additions & 77 deletions
77
src/modules/esl-carousel/plugin/esl-carousel-link.plugin.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
src/modules/esl-carousel/plugin/relation/esl-carousel.relation.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,57 @@ | ||
import {ExportNs} from '../../../esl-utils/environment/export-ns'; | ||
import {ESLMixinElement} from '../../../esl-mixin-element/core'; | ||
import {attr, listen, memoize} from '../../../esl-utils/decorators'; | ||
import {ESLTraversingQuery} from '../../../esl-traversing-query/core'; | ||
|
||
import {ESLCarousel} from '../../core/esl-carousel'; | ||
|
||
/** | ||
* Slide Carousel Link plugin mixin to bind carousel positions | ||
*/ | ||
@ExportNs('Carousel.Link') | ||
export class ESLCarouselRelationMixin extends ESLMixinElement { | ||
public static override is = 'esl-carousel-relate-to'; | ||
|
||
public override $host: ESLCarousel; | ||
|
||
@attr({name: ESLCarouselRelationMixin.is}) | ||
public target: string; | ||
|
||
@memoize() | ||
public get $target(): ESLCarousel | null { | ||
const $target = ESLTraversingQuery.first(this.target); | ||
return ($target instanceof ESLCarousel) ? $target : null; | ||
} | ||
|
||
protected override async connectedCallback(): Promise<void> { | ||
const {$host} = this; | ||
await ESLCarousel.registered; | ||
if (($host as unknown) instanceof ESLCarousel) { | ||
super.connectedCallback(); | ||
} else { | ||
console.error('[ESL]: %o is not correct target for %o', $host, ESLCarouselRelationMixin.is); | ||
} | ||
} | ||
|
||
protected override attributeChangedCallback(attrName: string, oldVal: string, newVal: string): void { | ||
memoize.clear(this, '$target'); | ||
} | ||
|
||
/** Handles event that fires when the carousel slides state is changed. */ | ||
@listen('esl:slide:changed') | ||
protected _onSlideChange(e: CustomEvent): void { | ||
if (!this.$target) return; | ||
if (e.detail.activator !== this) { | ||
this.$target.goTo(this.$host.firstIndex, { | ||
direction: e.detail.direction, | ||
activator: this | ||
}); | ||
} | ||
} | ||
} | ||
|
||
declare global { | ||
export interface ESLCarouselNS { | ||
Link: typeof ESLCarouselRelationMixin; | ||
} | ||
} |