coreui-angular-ex
Version:
CoreUI Components Library for Angular
56 lines (49 loc) • 1.76 kB
text/typescript
import {
AfterContentChecked,
AfterContentInit,
Component,
ContentChildren,
HostBinding,
QueryList
} from '@angular/core';
import { fadeAnimation, slideAnimation } from '../carousel.animation';
import { CarouselItemComponent } from '../carousel-item/carousel-item.component';
import { CarouselState } from '../carousel-state';
export class CarouselInnerComponent implements AfterContentInit, AfterContentChecked {
constructor(private carouselState: CarouselState) {}
carouselInnerClass = true;
activeIndex?: number;
animate?: boolean;
slide = { left: true };
transition = 'slide';
private contentItems!: QueryList<CarouselItemComponent>;
private prevContentItems!: QueryList<CarouselItemComponent>;
ngAfterContentInit(): void {
this.setItems();
}
ngAfterContentChecked(): void {
this.setItems();
const state = this.carouselState?.state;
const nextIndex = state?.activeItemIndex;
const nextDirection = state?.direction;
if (this.activeIndex !== nextIndex) {
this.animate = state?.animate;
this.slide = { left: nextDirection === 'next' };
this.activeIndex = state?.activeItemIndex;
this.transition = state?.transition ?? 'slide';
}
}
setItems(): void {
if (this.prevContentItems !== this.contentItems) {
this.prevContentItems = this.contentItems;
this.carouselState.setItems(this.contentItems);
}
}
}