openaire-library/searchPages/searchUtils/searchForm.component.ts

50 lines
2.4 KiB
TypeScript

import {Component, Input, Output, EventEmitter} from '@angular/core';
import {RouterHelper} from '../../utils/routerHelper.class';
import {Router} from '@angular/router';
@Component({
selector: 'search-form',
template: `
<form [class]="((isDisabled)?'uk-disabled':'')+(setFormCentered?' uk-text-center':'')">
<input type="text" class="uk-input uk-width-xlarge@l uk-width-medium@m uk-width-auto" [placeholder]="placeholderText" aria-describedby="sizing-addon2" [(ngModel)]="keyword" name="keyword" >
<button *ngIf="!link" (click)="keywordChanged()" type="submit" class=" uk-button portal-button uk-margin-small-left">
<span class="uk-icon" ><svg width="30" height="30" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="search" ratio="1.5"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9" cy="9" r="7"></circle><path fill="none" stroke="#000" stroke-width="1.1" d="M14,14 L18,18 L14,14 Z"></path></svg></span>
</button>
<button *ngIf="link" (click)="goTo()" type="submit" class="uk-button portal-button uk-padding uk-padding-remove-vertical uk-margin-small-left">
<span class="uk-icon" ><svg width="30" height="30" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="search" ratio="1.5"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9" cy="9" r="7"></circle><path fill="none" stroke="#000" stroke-width="1.1" d="M14,14 L18,18 L14,14 Z"></path></svg></span>
</button>
</form>
`
})
export class SearchFormComponent {
@Input() isDisabled: boolean = false;
@Input() keyword: string = '';
@Input() generalSearch: boolean = false;
@Input() placeholderText: string = "Type keywords";
@Input() link: string = "";
@Input() setFormCentered: boolean = true;
public routerHelper:RouterHelper = new RouterHelper();
@Output() keywordChange = new EventEmitter();
constructor (private _router:Router) {
}
ngOnInit() {
}
keywordChanged() {
//console.info("inside form: "+this.keyword);
this.keywordChange.emit({
value: this.keyword
});
}
goTo() {
//this._router.navigate(['/search/find'], { queryParams: this.routerHelper.createQueryParam('keyword',this.keyword) });
this._router.navigate([this.link], { queryParams: this.routerHelper.createQueryParam('keyword',this.keyword) });
}
}