import { Component, OnInit, Input, Output, EventEmitter, ElementRef, ViewChild } from '@angular/core'; import { CfCoreComponent } from '../core/core.component'; import { CfCheckboxComponent } from '../checkbox/checkbox.component'; import { ItemStylingModel } from '../../models/item/item-styling.model'; @Component({ selector: 'cf-item', template: "
arrow_right
", styles: [".cf-list-item-action { width: 100%; display: flex; flex-direction: row; align-items: center; font-family: 'Avenir', \"Helvetica Neue\", sans-serif; box-sizing: border-box; font-size: 16px; padding: 8px 0; } .cf-list-item-details { transition: all .5s; display: none; } .cf-list-item-details.cf-expanded { transition: all .5s; display: block; } .cf-list-item-trigger { transition: all .5s; z-index: 100; } .cf-list-item-trigger.cf-expanded { transform: rotate(90deg); } .cf-list-item-details-container { width: 100%; font-family: 'Avenir', \"Helvetica Neue\", sans-serif; } [hidden] { display: none !important; } .item { background-color: white; } .itemSelected { background-color: lightgray; } "] }) /** *

The item component can be used anywhere as a general item or inside cf-list component as a list item.

*

The item component consists of 2 tabs: Default template (always shown) and the details template.

*/ export class CfItemComponent extends CfCoreComponent implements OnInit { @Input() styling: ItemStylingModel; /** *

True if the item will contain a details tab.

*/ @Input() details:boolean = false; selectedValue: boolean = false; /** *

If the item is selectable, then show a checkbox

*/ @Input() selectable: boolean = false; @Input() withCheckbox: boolean = true; @Input() get selected() { return this.selectedValue; } @Output() selectedChange: EventEmitter = new EventEmitter(); @Output() itemClicked = new EventEmitter(); set selected(val) { this.selectedValue = val; this.selectedChange.emit(this.selectedValue); } internalId: number; /** *

Set to true when the user presses on the details icon.

*/ showDetails: boolean = false; constructor(public elementRef: ElementRef) { super(elementRef); } ngOnInit() { if(this.styling==null) this.styling = new ItemStylingModel(); } ngOnChanges(changes: any){ } @ViewChild(CfCheckboxComponent) checkbox: CfCheckboxComponent; selectMe() { if(this.selectable==true) { this.selected = !this.selected; this.itemClicked.emit({"id":this.internalId, "value": this.selectedValue}); } } notifyList(){ if(this.selectable==true) { this.itemClicked.emit({"id":this.internalId, "value": !this.selectedValue}); } } }