import {Component, Input, Output, EventEmitter} from 'ng-forward'; export interface BootstrapSwitcherItem { value: any; label: string; } @Component({ selector: 'noosfero-bootstrap-switcher', template: `
`, inputs: ['activeClass', 'defaultClass', 'label', 'options', 'defaultOption'], outputs: ['onSwitch'] }) export class BootstrapSwitcherComponent { @Input() activeClass: string = 'active btn-danger'; @Input() defaultClass: string = 'btn-default'; @Input() label: string; @Input() options: BootstrapSwitcherItem[]; @Input() defaultOption: BootstrapSwitcherItem; @Output() onSwitch: EventEmitter = new EventEmitter(); selectedOption: BootstrapSwitcherItem = null; constructor() { } ngOnInit() { this.selectedOption = this.defaultOption; } isSelectedOption(value: BootstrapSwitcherItem): boolean { return this.selectedOption === value; } getCssClassForItem(value: BootstrapSwitcherItem): string { return this.isSelectedOption(value) ? this.activeClass : this.defaultClass; } switcherClick(value: BootstrapSwitcherItem) { this.selectedOption = value; this.onSwitch.next(value); } }