Skip to content

Commit

Permalink
feat(esl-carousel): support for relation mixin plugin for ESLCarousel…
Browse files Browse the repository at this point in the history
… component
  • Loading branch information
ala-n committed May 19, 2023
1 parent 1deea71 commit 77cbbd9
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 97 deletions.
7 changes: 3 additions & 4 deletions pages/src/localdev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
ESLCarousel,
ESLCarouselNavDots,
ESLCarouselNavMixin,
ESLCarouselLinkPlugin,
ESLCarouselRelationMixin,
ESLCarouselTouchPlugin,
ESLCarouselAutoplayMixin
} from '../../src/modules/all';
Expand Down Expand Up @@ -110,11 +110,10 @@ ESLTooltip.register();
ESLAnimate.register();

ESLCarousel.register();
ESLCarouselTouchPlugin.register();
ESLCarouselNavDots.register();
ESLCarouselNavMixin.register();
ESLCarouselTouchPlugin.register();

ESLCarouselLinkPlugin.register();
ESLCarouselRelationMixin.register();
ESLCarouselAutoplayMixin.register();

ESLShare.config(() => fetch('/assets/share/config.json').then((response) => response.json()));
Expand Down
12 changes: 8 additions & 4 deletions pages/views/draft/carousel.njk
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ icon: examples/carousel.svg
<div class="row flex-column" esl-carousel-container>
<button type="button" esl-carousel-nav="group:prev"></button>

<esl-carousel esl-carousel-touch media="@XL|@LG|@MD|@SM|@XS" count="6|5|4|3|1">
<esl-carousel-link-plugin to="#second-carousel"></esl-carousel-link-plugin>
<esl-carousel id="first-carousel"
esl-carousel-touch
esl-carousel-relate-to="#second-carousel"
media="@XL|@LG|@MD|@SM|@XS"
count="6|5|4|3|1">
<div data-slides-area>
<!-- CAROUSEL-ITEM -->
{% for i in range(0, 13) %}
Expand All @@ -204,8 +207,9 @@ icon: examples/carousel.svg
<div class="row flex-column" esl-carousel-container>
<button type="button" esl-carousel-nav="group:prev"></button>

<esl-carousel esl-carousel-autoplay="5000"
id="second-carousel"
<esl-carousel id="second-carousel"
esl-carousel-autoplay="5000"
esl-carousel-relate-to="#first-carousel"
count="1">
<div data-slides-area>
<!-- CAROUSEL-ITEM -->
Expand Down
14 changes: 10 additions & 4 deletions pages/views/examples/carousel.marquee.njk
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ icon: examples/carousel.svg
<section class="container-fluid marquee-carousel">

<div class="row flex-column main-carousel" esl-carousel-container>
<esl-carousel esl-carousel-touch>
<esl-carousel-link-plugin to="#secondary-carousel"></esl-carousel-link-plugin>
<esl-carousel id="main-carousel"
esl-carousel-touch
esl-carousel-relate-to="#nav-carousel">
<div data-slides-area>
{% for item in slides %}
<esl-carousel-slide>
Expand All @@ -32,11 +33,16 @@ icon: examples/carousel.svg
<div class="row flex-column marquee-nav-carousel" esl-carousel-container>
<button class="esl-carousel-arrow inner icon-arrow-prev" esl-carousel-nav="slide:prev"></button>

<esl-carousel esl-carousel-touch id="secondary-carousel" type="@+LG" count="5">
<esl-carousel id="nav-carousel"
esl-carousel-touch
type="@+LG"
count="5">
<div data-slides-area>
{% for item in slides %}
<esl-carousel-slide>
<div class="img-container" esl-carousel-nav="slide:{{ loop.index - 1 }}">
<div class="img-container"
esl-carousel-nav="slide:{{ loop.index - 1 }}"
esl-carousel-nav-target="#main-carousel">
<esl-image mode="cover" lazy
data-alt="{{ 'Carousel slide ' + loop.index }}"
data-src="{{ '/assets/carousel/' + loop.index + '-sm.jpg' | url }}"></esl-image>
Expand Down
2 changes: 0 additions & 2 deletions src/modules/esl-carousel/all.less
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";
4 changes: 2 additions & 2 deletions src/modules/esl-carousel/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export * from './plugin/touch/esl-carousel.touch.mixin';
// Autoplay
export * from './plugin/autoplay/esl-carousel.autoplay.mixin';

// Plugins
export * from './plugin/esl-carousel-link.plugin';
// Link Utility
export * from './plugin/relation/esl-carousel.relation.mixin';
5 changes: 4 additions & 1 deletion src/modules/esl-carousel/core/esl-carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ interface CarouselConfig {

/** {@link ESLCarousel} action params interface */
export interface CarouselActionParams {
/** Element requester of the change */
activator?: any;
/** Direction to move to. */
direction?: ESLCarouselDirection;
/** Force action independently of current state of the Carousel. */
Expand Down Expand Up @@ -242,12 +244,13 @@ export class ESLCarousel extends ESLBaseElement implements ESLCarouselState {

const {index, dir} = toIndex(target, this);
const direction = params.direction || dir;
const activator = params.activator;

if (!direction || firstIndex === index && !params.force) return;

// TODO: change info
const eventDetails = {
detail: {direction},
detail: {direction, activator},
bubbles: false
};

Expand Down
77 changes: 0 additions & 77 deletions src/modules/esl-carousel/plugin/esl-carousel-link.plugin.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/modules/esl-carousel/plugin/esl-carousel-plugin.less

This file was deleted.

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;
}
}

0 comments on commit 77cbbd9

Please # to comment.