Skip to content

Commit

Permalink
feat(esl-carousel): add step animation duration customization
Browse files Browse the repository at this point in the history
  • Loading branch information
ala-n committed Aug 16, 2024
1 parent 5285b1e commit 4bc8c90
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/modules/esl-carousel/core/esl-carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {ESLBaseElement} from '../../esl-base-element/core';
import {attr, boolAttr, ready, decorate, listen, memoize} from '../../esl-utils/decorators';
import {isMatches} from '../../esl-utils/dom/traversing';
import {microtask} from '../../esl-utils/async';
import {parseBoolean, sequentialUID} from '../../esl-utils/misc';
import {parseBoolean, parseTime, sequentialUID} from '../../esl-utils/misc';

import {CSSClassUtils} from '../../esl-utils/dom/class';
import {ESLTraversingQuery} from '../../esl-traversing-query/core';
Expand Down Expand Up @@ -33,7 +33,7 @@ import type {
@ExportNs('Carousel')
export class ESLCarousel extends ESLBaseElement {
public static override is = 'esl-carousel';
public static observedAttributes = ['media', 'type', 'loop', 'count', 'vertical', 'container'];
public static observedAttributes = ['media', 'type', 'loop', 'count', 'vertical', 'step-duration', 'container'];

/** Media query pattern used for {@link ESLMediaRuleList} of `type`, `loop` and `count` (default: `all`) */
@attr({defaultValue: 'all'}) public media: string;
Expand All @@ -46,6 +46,9 @@ export class ESLCarousel extends ESLBaseElement {
/** Orientation of the carousel (`horizontal` by default). Supports {@link ESLMediaRuleList} syntax */
@attr({defaultValue: 'false'}) public vertical: string | boolean;

/** Duration of the single slide transition */
@attr({defaultValue: '250'}) public stepDuration: string;

/** Container selector (supports traversing query). Carousel itself by default */
@attr({defaultValue: ''}) public container: string;
/** CSS class to add on the container when carousel is empty */
Expand Down Expand Up @@ -85,6 +88,11 @@ export class ESLCarousel extends ESLBaseElement {
public get verticalRule(): ESLMediaRuleList<boolean> {
return ESLMediaRuleList.parse(this.vertical as string, this.media, parseBoolean);
}
/** Duration of the single slide transition {@link ESLMediaRuleList} instance */
@memoize()
public get stepDurationRule(): ESLMediaRuleList<number> {
return ESLMediaRuleList.parse(this.stepDuration, this.media, parseTime);
}

/** Returns observed media rules */
public get observedRules(): ESLMediaRuleList[] {
Expand Down Expand Up @@ -309,7 +317,8 @@ export class ESLCarousel extends ESLBaseElement {

/** Merge request params with default params */
protected mergeParams(params: Partial<ESLCarouselActionParams>): ESLCarouselActionParams {
return {stepDuration: 250, ...params};
const stepDuration = this.stepDurationRule.value || 0;
return {stepDuration, ...params};
}

/** @returns slide by index (supports not normalized indexes) */
Expand Down

0 comments on commit 4bc8c90

Please sign in to comment.