summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/components/ui/search-bar/search-bar.component.ts
blob: 08bdf2030fd9a53ee5256f3794bc90591d1e91b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Component, Input, Output, EventEmitter, ViewEncapsulation } from '@angular/core';

@Component({
    selector: 'search-bar',
    templateUrl: './search-bar.component.html',
    styleUrls: ['./search-bar.component.less'],
    encapsulation: ViewEncapsulation.None
})
export class SearchBarComponent {

    @Input() placeholder: string;
    @Input() class: string;
    @Input() searchQuery: string;
    @Output() searchChanged: EventEmitter<any> = new EventEmitter<any>();
    @Output() searchButtonClicked: EventEmitter<string> = new EventEmitter<string>();

    searchButtonClick = (): void => {
        if (this.searchQuery) { //do not allow empty search
            this.searchButtonClicked.emit(this.searchQuery);
        }
    }

    searchQueryChange = ($event): void => {
        this.searchChanged.emit($event);
    }

    private clearSearchQuery = (): void => {
        this.searchQuery = "";
        this.searchButtonClicked.emit(this.searchQuery);
    }
}