@@ -6,11 +6,13 @@ import { addAnimationController } from '../../animations/player.js';
66import { carouselContext } from '../common/context.js' ;
77import { addInternalsController } from '../common/controllers/internals.js' ;
88import { registerComponent } from '../common/definitions/register.js' ;
9- import { createCounter , formatString } from '../common/util.js' ;
9+ import { formatString } from '../common/util.js' ;
1010import { animations } from './animations.js' ;
1111import type IgcCarouselComponent from './carousel.js' ;
1212import { styles } from './themes/carousel-slide.base.css.js' ;
1313
14+ let nextId = 1 ;
15+
1416/**
1517 * A single content container within a set of containers used in the context of an `igc-carousel`.
1618 *
@@ -27,25 +29,23 @@ export default class IgcCarouselSlideComponent extends LitElement {
2729 registerComponent ( IgcCarouselSlideComponent ) ;
2830 }
2931
30- private static readonly increment = createCounter ( ) ;
31-
3232 private readonly _internals = addInternalsController ( this , {
3333 initialARIA : {
3434 role : 'tabpanel' ,
3535 ariaRoleDescription : 'slide' ,
3636 } ,
3737 } ) ;
3838
39- private readonly _animationPlayer = addAnimationController ( this ) ;
39+ private readonly _player = addAnimationController ( this ) ;
4040
4141 @consume ( { context : carouselContext , subscribe : true } )
42- private _carousel ?: IgcCarouselComponent ;
42+ private readonly _carousel ?: IgcCarouselComponent ;
4343
44- protected get _index ( ) {
44+ protected get _index ( ) : number {
4545 return this . _carousel ? this . _carousel . slides . indexOf ( this ) : 0 ;
4646 }
4747
48- protected get _total ( ) {
48+ protected get _total ( ) : number {
4949 return this . _carousel ? this . _carousel . slides . length : 0 ;
5050 }
5151
@@ -59,7 +59,7 @@ export default class IgcCarouselSlideComponent extends LitElement {
5959 return animation ;
6060 }
6161
62- protected get _labelFormat ( ) {
62+ protected get _labelFormat ( ) : string {
6363 return this . _carousel ? this . _carousel . slidesLabelFormat : '' ;
6464 }
6565
@@ -81,21 +81,16 @@ export default class IgcCarouselSlideComponent extends LitElement {
8181 public async toggleAnimation (
8282 type : 'in' | 'out' ,
8383 direction : 'normal' | 'reverse' = 'normal'
84- ) {
84+ ) : Promise < boolean > {
8585 const animation = animations . get ( this . _animation ) ! . get ( type ) ! ;
8686
87- const options : KeyframeAnimationOptions = {
88- duration : 320 ,
89- easing : EaseInOut . Quad ,
90- direction,
91- } ;
92-
93- const [ _ , event ] = await Promise . all ( [
94- this . _animationPlayer . stopAll ( ) ,
95- this . _animationPlayer . play ( animation ( options ) ) ,
96- ] ) ;
97-
98- return event . type === 'finish' ;
87+ return await this . _player . playExclusive (
88+ animation ( {
89+ duration : 320 ,
90+ easing : EaseInOut . Quad ,
91+ direction,
92+ } )
93+ ) ;
9994 }
10095
10196 protected override willUpdate ( ) : void {
@@ -104,15 +99,14 @@ export default class IgcCarouselSlideComponent extends LitElement {
10499 } ) ;
105100 }
106101
102+ /** @internal */
107103 public override connectedCallback ( ) : void {
108104 super . connectedCallback ( ) ;
109-
110- this . id =
111- this . id || `igc-carousel-slide-${ IgcCarouselSlideComponent . increment ( ) } ` ;
105+ this . id = this . id || `igc-carousel-slide-${ nextId ++ } ` ;
112106 }
113107
114108 protected override render ( ) {
115- return html ` < slot > </ slot > ` ;
109+ return html `< slot > </ slot > ` ;
116110 }
117111}
118112
0 commit comments