| 24 | preserveWhitespaces: false, |
| 25 | }) |
| 26 | export class AlertComponent implements OnChanges, OnDestroy, AfterViewInit { |
| 27 | @Input() type: AlertType = 'info'; |
| 28 | @Input() cssClass: string; |
| 29 | @Input() closeable = true; |
| 30 | @Input() showIcon = true; |
| 31 | @Input() autoplay = false; |
| 32 | @Input() autoplaySpeed = 3000; |
| 33 | @Input() transitionSpeed = 500; |
| 34 | @Input() operationTemplate: TemplateRef<any>; |
| 35 | @Input() set dismissTime(time: number) { |
| 36 | setTimeout(() => { |
| 37 | this.close(); |
| 38 | }, time); |
| 39 | } |
| 40 | @Output() closeEvent = new EventEmitter<AlertComponent>(); |
| 41 | @ViewChild('carouselContainer') box: ElementRef<any>; |
| 42 | @ContentChildren(AlertCarouselItemComponent) carouselItems: QueryList<AlertCarouselItemComponent>; |
| 43 | hide = false; |
| 44 | autoplayHeight: string; |
| 45 | carouselNum: number; |
| 46 | currentIndex = 1; |
| 47 | scheduledId: any; |
| 48 | SINGLE_LINE_HEIGHT = '24px'; |
| 49 | |
| 50 | constructor(private el: ElementRef, private renderer: Renderer2) {} |
| 51 | |
| 52 | ngOnChanges(changes: SimpleChanges) { |
| 53 | const { autoplay, autoplaySpeed, transitionSpeed } = changes; |
| 54 | if ((autoplay || autoplaySpeed) && (!this.autoplay || !this.autoplaySpeed)) { |
| 55 | this.clearScheduledTransition(); |
| 56 | } else { |
| 57 | this.autoScheduleTransition(); |
| 58 | } |
| 59 | if (transitionSpeed && this.transitionSpeed) { |
| 60 | this.renderer.setStyle(this.box.nativeElement, 'transition', `top ${this.transitionSpeed}ms ease`); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | ngAfterViewInit(): void { |
| 65 | this.renderCarouselItem(); |
| 66 | this.carouselItems.changes.subscribe(() => this.renderCarouselItem()); |
| 67 | } |
| 68 | |
| 69 | ngOnDestroy() { |
| 70 | this.clearScheduledTransition(); |
| 71 | } |
| 72 | |
| 73 | renderCarouselItem() { |
| 74 | this.carouselNum = this.carouselItems.length; |
| 75 | if (this.carouselNum > 1) { |
| 76 | if (!this.autoplayHeight) { |
| 77 | const itemHeights = this.carouselItems.map((item) => { |
| 78 | const rect = item?.el.nativeElement.getBoundingClientRect(); |
| 79 | return rect?.height || 0; |
| 80 | }); |
| 81 | const maxHeight = Math.max(...itemHeights); |
| 82 | this.autoplayHeight = maxHeight ? `${maxHeight}px` : this.SINGLE_LINE_HEIGHT; |
| 83 | } |
nothing calls this directly
no test coverage detected