jsim-lazy-expandable
Version:
Light weight and easy to use expansion panel with lazy loaded content.
1 lines • 13.8 kB
Source Map (JSON)
{"version":3,"file":"jsim-lazy-expandable.mjs","sources":["../../../projects/jsim-lazy-expandable/src/lib/lazy-content.directive.ts","../../../projects/jsim-lazy-expandable/src/lib/lazy-expandable.component.ts","../../../projects/jsim-lazy-expandable/src/lib/lazy-expandable.component.html","../../../projects/jsim-lazy-expandable/src/lib/lazy-expandable.module.ts","../../../projects/jsim-lazy-expandable/src/jsim-lazy-expandable.ts"],"sourcesContent":["import { Directive, TemplateRef, ViewContainerRef } from '@angular/core';\n\n@Directive({\n selector: 'ng-template[jsimLazyContent]'\n})\nexport class LazyContentDirective {\n viewLoaded: boolean = false;\n\n constructor(private templateRef: TemplateRef<any>, private viewContainer: ViewContainerRef) {\n this.viewContainer.clear();\n this.viewLoaded = false;\n }\n\n public showContent(){\n if(!this.viewLoaded){\n this.viewContainer.createEmbeddedView(this.templateRef);\n this.viewLoaded = true;\n }\n }\n}\n","import { AfterContentInit, Component, ContentChild, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';\nimport { LazyContentDirective } from './lazy-content.directive';\n\n@Component({\n selector: 'jsim-lazy-expandable',\n templateUrl: './lazy-expandable.component.html',\n styleUrls: ['./lazy-expandable.component.css']\n})\nexport class LazyExpandableComponent implements OnInit, AfterContentInit {\n\n /** Is the panel open? */\n @Input() isOpen: boolean = false;\n\n /** Event emitted when isOpen changes */\n @Output() openChanged = new EventEmitter<boolean>();\n\n /** Hide the arrow icon */\n @Input() hideIcon: boolean = false;\n\n /** Height of the header when collapsed (in pixels) */\n @Input() headerHeight: number = 48;\n\n /** Height of the header when expanded (in pixels) */\n @Input() headerHeightExpanded: number = 64;\n\n /** Speed of the expand and collapse animation (in pixel by milisecond) */\n @Input() animationSpeed: number = 0.5;\n\n /** Event emitted when animation ends */\n @Output() animationEnd = new EventEmitter<boolean>();\n\n /** Is expanding and collapsing disabled? */\n @Input() disabled: boolean = false;\n\n @ViewChild('lazyContent') content: ElementRef | undefined;\n\n @ContentChild(LazyContentDirective) directive: LazyContentDirective | undefined;\n\n headerHeightStyle: string = this.headerHeight + 'px';\n contentHeight: string = this.headerHeight + 'px';\n\n private currentContentHeight: number = 0;\n private desiredContentHeight: number = 0;\n private timeLastFrame: number = Date.now();\n private animationDuration: number = 0;\n private currentAnimationTime: number = 0;\n\n private animationFrameRef: number | undefined;\n\n constructor() {}\n\n ngOnInit(): void {}\n\n ngAfterContentInit(): void {\n setTimeout(() => {\n this.setContentHeight(false);\n if(this.isOpen && this.directive){\n this.directive.showContent();\n }\n }, 0);\n }\n\n toggleOpen(){\n if(this.disabled){\n return;\n }\n\n this.isOpen = !this.isOpen;\n\n if(this.isOpen && this.directive){\n this.directive.showContent();\n }\n\n this.openChanged.emit(this.isOpen);\n this.setContentHeight();\n }\n\n private setContentHeight(animate: boolean = true){\n if(animate){\n if(this.isOpen){\n this.headerHeightStyle = this.headerHeightExpanded + 'px';\n this.desiredContentHeight = this.content!.nativeElement.clientHeight;\n this.currentContentHeight = 0;\n } else {\n this.headerHeightStyle = this.headerHeight + 'px';\n this.desiredContentHeight = 0;\n this.currentContentHeight = this.content!.nativeElement.clientHeight;\n }\n this.animationDuration = Math.abs(this.desiredContentHeight - this.currentContentHeight) / this.animationSpeed;\n this.startAnimation();\n } else {\n if(this.isOpen){\n this.headerHeightStyle = this.headerHeightExpanded + 'px';\n this.contentHeight = 'unset';\n } else {\n this.headerHeightStyle = this.headerHeight + 'px';\n this.contentHeight = this.headerHeight + 'px';\n }\n }\n }\n\n private startAnimation(){\n this.timeLastFrame = Date.now();\n this.currentAnimationTime = 0;\n if(this.animationFrameRef){\n cancelAnimationFrame(this.animationFrameRef);\n }\n this.animationFrameRef = requestAnimationFrame(this.animateHeader.bind(this));\n }\n\n private animateHeader() {\n const time = Date.now();\n const deltatime = time - this.timeLastFrame;\n this.timeLastFrame = time;\n this.currentAnimationTime += deltatime;\n\n const amount = this.currentAnimationTime / this.animationDuration;\n\n this.currentContentHeight = this.lerp(this.currentContentHeight, this.desiredContentHeight, amount);\n\n if(this.isOpen){\n this.currentContentHeight = Math.min(this.currentContentHeight, this.desiredContentHeight);\n this.contentHeight = this.headerHeightExpanded + this.currentContentHeight + 'px';\n } else {\n this.currentContentHeight = Math.max(this.currentContentHeight, this.desiredContentHeight);\n this.contentHeight = this.headerHeight + this.currentContentHeight + 'px';\n }\n\n if(this.currentContentHeight == this.desiredContentHeight){\n this.animationEnded();\n return;\n }\n\n this.animationFrameRef = requestAnimationFrame(this.animateHeader.bind(this));\n }\n\n private lerp = (x: number, y: number, a: number) => x * (1 - a) + y * a;\n\n private animationEnded(){\n this.animationEnd.emit(this.isOpen);\n if(this.isOpen){\n this.contentHeight = 'unset';\n }\n }\n}\n","<div class=\"lazy-exp-container\" [class.is-open]=\"isOpen\" [style.height]=\"contentHeight\" [class.disabled]=\"disabled\">\n <div class=\"lazy-exp-header\" (click)=\"toggleOpen()\" [style.height]=\"headerHeightStyle\">\n <div class=\"lazy-exp-header-title\">\n <ng-content select=\"[exp-header-title]\"></ng-content>\n </div>\n <div class=\"lazy-exp-header-subtitle\">\n <ng-content select=\"[exp-header-subtitle]\"></ng-content>\n </div>\n <div *ngIf=\"!hideIcon\" class=\"lazy-exp-header-icon\"></div>\n </div>\n <div #lazyContent class=\"lazy-exp-content\">\n <div class=\"lazy-exp-content-container\">\n <ng-content select=\"[exp-content]\"></ng-content>\n </div>\n </div>\n</div>\n","import { NgModule } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { LazyExpandableComponent } from './lazy-expandable.component';\nimport { LazyContentDirective } from './lazy-content.directive';\n\n@NgModule({\n declarations: [\n LazyExpandableComponent,\n LazyContentDirective\n ],\n imports: [\n CommonModule\n ],\n exports: [\n LazyExpandableComponent,\n LazyContentDirective\n ]\n})\nexport class LazyExpandableModule { }\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;MAKa,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