UNPKG

smart-webcomponents

Version:

Web Components & Custom Elements for Professional Web Applications

132 lines (109 loc) 4.36 kB
import { Timeline } from './../index'; import { ElementRenderMode} from './../index'; import { Component, Directive, AfterViewInit, ElementRef, Input, OnInit, OnChanges, OnDestroy, SimpleChanges, Output, EventEmitter } from '@angular/core'; import { BaseElement, Smart } from './smart.element'; export { ElementRenderMode} from './../index'; export { Smart } from './smart.element'; export { Timeline } from './../index'; @Directive({ exportAs: 'smart-timeline', selector: 'smart-timeline, [smart-timeline]' }) export class TimelineComponent extends BaseElement implements OnInit, AfterViewInit, OnDestroy, OnChanges { constructor(ref: ElementRef<Timeline>) { super(ref); this.nativeElement = ref.nativeElement as Timeline; } private eventHandlers: any[] = []; public declare nativeElement: Timeline; /** @description Creates the component on demand. * @param properties An optional object of properties, which will be added to the template binded ones. */ public createComponent(properties = {}): any { this.nativeElement = <Timeline>document.createElement('smart-timeline'); for (let propertyName in properties) { this.nativeElement[propertyName] = properties[propertyName]; } return this.nativeElement; } /** @description Sets or gets whether the Timeline is with auto width in horizontal mode. */ @Input() get autoWidth(): boolean { return this.nativeElement ? this.nativeElement.autoWidth : undefined; } set autoWidth(value: boolean) { this.nativeElement ? this.nativeElement.autoWidth = value : undefined; } /** @description Sets or gets whether the items can be collapsed. */ @Input() get collapsible(): boolean { return this.nativeElement ? this.nativeElement.collapsible : undefined; } set collapsible(value: boolean) { this.nativeElement ? this.nativeElement.collapsible = value : undefined; } /** @description Sets or gets whether the Timeline is disabled. */ @Input() get disabled(): boolean { return this.nativeElement ? this.nativeElement.disabled : undefined; } set disabled(value: boolean) { this.nativeElement ? this.nativeElement.disabled = value : undefined; } /** @description Sets or gets whether the Timeline is horizontal. */ @Input() get horizontal(): boolean { return this.nativeElement ? this.nativeElement.horizontal : undefined; } set horizontal(value: boolean) { this.nativeElement ? this.nativeElement.horizontal = value : undefined; } /** @description Sets or gets position. The possible values are 'near', 'far' and 'both'. */ @Input() get position(): string { return this.nativeElement ? this.nativeElement.position : undefined; } set position(value: string) { this.nativeElement ? this.nativeElement.position = value : undefined; } /** @description Sets or gets the items. Each item should be an object. The object has the following properties: date: date, description: string, subtitle: string, css: string, dotCSS: string, title: string and icon: string. Example: [{ date: 'May 15, 2024', description: 'Flight: Reserving airline tickets', subtitle: 'May 15, 2024', title: 'Flight Reservation', icon: 'material-icons flight', dotCSS: '' }] */ @Input() get dataSource(): any[] { return this.nativeElement ? this.nativeElement.dataSource : undefined; } set dataSource(value: any[]) { this.nativeElement ? this.nativeElement.dataSource = value : undefined; } get isRendered(): boolean { return this.nativeElement ? this.nativeElement.isRendered : false; } ngOnInit() { } ngAfterViewInit() { const that = this; that.onCreate.emit(that.nativeElement); if (Smart) Smart.Render(); this.nativeElement.classList.add('smart-angular'); if (this.nativeElement.whenRendered) this.nativeElement.whenRendered(() => { that.onReady.emit(that.nativeElement); }); this.listen(); } ngOnDestroy() { this.unlisten(); } ngOnChanges(changes: SimpleChanges) { if (this.nativeElement && this.nativeElement.isRendered) { for (const propName in changes) { if (changes.hasOwnProperty(propName)) { this.nativeElement[propName] = changes[propName].currentValue; } } } } /** @description Add event listeners. */ private listen(): void { const that = this; } /** @description Remove event listeners. */ private unlisten(): void { const that = this; } }