blob: af5fb7fc748224bcd57dffa383aa6b9c5a220f57 [file] [log] [blame]
import * as tslib_1 from "tslib";
import { Component, ViewChild, Input, Output, EventEmitter, Optional, ChangeDetectionStrategy, ChangeDetectorRef, forwardRef, NgModule } from '@angular/core';
import { trigger, state, style, transition, animate, AUTO_STYLE } from '@angular/animations';
import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
import { Dir } from '@angular/cdk/bidi';
import { MatInput, MatInputModule } from '@angular/material/input';
import { debounceTime } from 'rxjs/operators/debounceTime';
import { skip } from 'rxjs/operators/skip';
import { mixinControlValueAccessor } from '@covalent/core/common';
import { CommonModule } from '@angular/common';
import { MatIconModule } from '@angular/material/icon';
import { MatButtonModule } from '@angular/material/button';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var TdSearchInputBase = /** @class */ (function () {
/**
* @param {?} _changeDetectorRef
*/
function TdSearchInputBase(_changeDetectorRef) {
this._changeDetectorRef = _changeDetectorRef;
}
return TdSearchInputBase;
}());
/* tslint:disable-next-line */
var _TdSearchInputMixinBase = mixinControlValueAccessor(TdSearchInputBase);
var TdSearchInputComponent = /** @class */ (function (_super) {
tslib_1.__extends(TdSearchInputComponent, _super);
/**
* @param {?} _dir
* @param {?} _changeDetectorRef
*/
function TdSearchInputComponent(_dir, _changeDetectorRef) {
var _this = _super.call(this, _changeDetectorRef) || this;
_this._dir = _dir;
/**
* showUnderline?: boolean
* Sets if the input underline should be visible. Defaults to 'false'.
*/
_this.showUnderline = false;
/**
* debounce?: number
* Debounce timeout between keypresses. Defaults to 400.
*/
_this.debounce = 400;
/**
* clearIcon?: string
* The icon used to clear the search input.
* Defaults to 'cancel' icon.
*/
_this.clearIcon = 'cancel';
/**
* searchDebounce: function($event)
* Event emitted after the [debounce] timeout.
*/
_this.onSearchDebounce = new EventEmitter();
/**
* search: function($event)
* Event emitted after the key enter has been pressed.
*/
_this.onSearch = new EventEmitter();
/**
* clear: function()
* Event emitted after the clear icon has been clicked.
*/
_this.onClear = new EventEmitter();
/**
* blur: function()
* Event emitted after the blur event has been called in underlying input.
*/
_this.onBlur = new EventEmitter();
return _this;
}
Object.defineProperty(TdSearchInputComponent.prototype, "isRTL", {
/**
* @return {?}
*/
get: function () {
if (this._dir) {
return this._dir.dir === 'rtl';
}
return false;
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
TdSearchInputComponent.prototype.ngOnInit = function () {
var _this = this;
this._input.ngControl.valueChanges.pipe(debounceTime(this.debounce), skip(1)).subscribe(function (value) {
_this._searchTermChanged(value);
});
};
/**
* Method to focus to underlying input.
* @return {?}
*/
TdSearchInputComponent.prototype.focus = function () {
this._input.focus();
};
/**
* @return {?}
*/
TdSearchInputComponent.prototype.handleBlur = function () {
this.onBlur.emit(undefined);
};
/**
* @param {?} event
* @return {?}
*/
TdSearchInputComponent.prototype.stopPropagation = function (event) {
event.stopPropagation();
};
/**
* @param {?} event
* @return {?}
*/
TdSearchInputComponent.prototype.handleSearch = function (event) {
this.stopPropagation(event);
this.onSearch.emit(this.value);
};
/**
* Method to clear the underlying input.
* @return {?}
*/
TdSearchInputComponent.prototype.clearSearch = function () {
this.value = '';
this._changeDetectorRef.markForCheck();
this.onClear.emit(undefined);
};
/**
* @param {?} value
* @return {?}
*/
TdSearchInputComponent.prototype._searchTermChanged = function (value) {
this.onSearchDebounce.emit(value);
};
return TdSearchInputComponent;
}(_TdSearchInputMixinBase));
TdSearchInputComponent.decorators = [
{ type: Component, args: [{
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(function () { return TdSearchInputComponent; }),
multi: true,
}],
selector: 'td-search-input',
template: "<div class=\"td-search-input\">\n <mat-form-field class=\"td-search-input-field\"\n [class.mat-hide-underline]=\"!showUnderline\"\n floatPlaceholder=\"never\">\n <input matInput\n #searchElement\n type=\"search\"\n [(ngModel)]=\"value\"\n [placeholder]=\"placeholder\"\n (blur)=\"handleBlur()\"\n (search)=\"stopPropagation($event)\"\n (keyup.enter)=\"handleSearch($event)\"/>\n </mat-form-field>\n <button mat-icon-button\n class=\"td-search-input-clear\"\n type=\"button\"\n [@searchState]=\"(searchElement.value ? 'show' : (isRTL ? 'hide-left' : 'hide-right'))\"\n (click)=\"clearSearch()\">\n <mat-icon>{{clearIcon}}</mat-icon>\n </button>\n</div>",
styles: [".td-search-input{\n overflow-x:hidden;\n -webkit-box-sizing:border-box;\n box-sizing:border-box;\n display:-webkit-box;\n display:-ms-flexbox;\n display:flex;\n -webkit-box-orient:horizontal;\n -webkit-box-direction:normal;\n -ms-flex-direction:row;\n flex-direction:row;\n -webkit-box-align:center;\n -ms-flex-align:center;\n align-items:center;\n -ms-flex-line-pack:center;\n align-content:center;\n max-width:100%;\n -webkit-box-pack:end;\n -ms-flex-pack:end;\n justify-content:flex-end; }\n .td-search-input .td-search-input-field{\n -webkit-box-flex:1;\n -ms-flex:1;\n flex:1; }\n .td-search-input ::ng-deep mat-form-field.mat-hide-underline .mat-form-field-underline{\n display:none; }\n .td-search-input .td-search-input-clear{\n -webkit-box-flex:0;\n -ms-flex:0 0 auto;\n flex:0 0 auto; }\n"],
changeDetection: ChangeDetectionStrategy.OnPush,
inputs: ['value'],
animations: [
trigger('searchState', [
state('hide-left', style({
transform: 'translateX(-150%)',
display: 'none',
})),
state('hide-right', style({
transform: 'translateX(150%)',
display: 'none',
})),
state('show', style({
transform: 'translateX(0%)',
display: 'block',
})),
transition('* => show', animate('200ms ease-in')),
transition('show => *', animate('200ms ease-out')),
]),
],
},] },
];
/** @nocollapse */
TdSearchInputComponent.ctorParameters = function () { return [
{ type: Dir, decorators: [{ type: Optional },] },
{ type: ChangeDetectorRef, },
]; };
TdSearchInputComponent.propDecorators = {
"_input": [{ type: ViewChild, args: [MatInput,] },],
"showUnderline": [{ type: Input, args: ['showUnderline',] },],
"debounce": [{ type: Input, args: ['debounce',] },],
"placeholder": [{ type: Input, args: ['placeholder',] },],
"clearIcon": [{ type: Input, args: ['clearIcon',] },],
"onSearchDebounce": [{ type: Output, args: ['searchDebounce',] },],
"onSearch": [{ type: Output, args: ['search',] },],
"onClear": [{ type: Output, args: ['clear',] },],
"onBlur": [{ type: Output, args: ['blur',] },],
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var TdSearchBoxBase = /** @class */ (function () {
/**
* @param {?} _changeDetectorRef
*/
function TdSearchBoxBase(_changeDetectorRef) {
this._changeDetectorRef = _changeDetectorRef;
}
return TdSearchBoxBase;
}());
/* tslint:disable-next-line */
var _TdSearchBoxMixinBase = mixinControlValueAccessor(TdSearchBoxBase);
var TdSearchBoxComponent = /** @class */ (function (_super) {
tslib_1.__extends(TdSearchBoxComponent, _super);
/**
* @param {?} _changeDetectorRef
*/
function TdSearchBoxComponent(_changeDetectorRef) {
var _this = _super.call(this, _changeDetectorRef) || this;
_this._searchVisible = false;
/**
* backIcon?: string
* The icon used to close the search toggle, only shown when [alwaysVisible] is false.
* Defaults to 'search' icon.
*/
_this.backIcon = 'search';
/**
* searchIcon?: string
* The icon used to open/focus the search toggle.
* Defaults to 'search' icon.
*/
_this.searchIcon = 'search';
/**
* clearIcon?: string
* The icon used to clear the search input.
* Defaults to 'cancel' icon.
*/
_this.clearIcon = 'cancel';
/**
* showUnderline?: boolean
* Sets if the input underline should be visible. Defaults to 'false'.
*/
_this.showUnderline = false;
/**
* debounce?: number
* Debounce timeout between keypresses. Defaults to 400.
*/
_this.debounce = 400;
/**
* alwaysVisible?: boolean
* Sets if the input should always be visible. Defaults to 'false'.
*/
_this.alwaysVisible = false;
/**
* searchDebounce: function($event)
* Event emitted after the [debounce] timeout.
*/
_this.onSearchDebounce = new EventEmitter();
/**
* search: function($event)
* Event emitted after the key enter has been pressed.
*/
_this.onSearch = new EventEmitter();
/**
* clear: function()
* Event emitted after the clear icon has been clicked.
*/
_this.onClear = new EventEmitter();
return _this;
}
Object.defineProperty(TdSearchBoxComponent.prototype, "searchVisible", {
/**
* @return {?}
*/
get: function () {
return this._searchVisible;
},
enumerable: true,
configurable: true
});
/**
* Method executed when the search icon is clicked.
* @return {?}
*/
TdSearchBoxComponent.prototype.searchClicked = function () {
if (this.alwaysVisible || !this._searchVisible) {
this._searchInput.focus();
}
this.toggleVisibility();
};
/**
* @return {?}
*/
TdSearchBoxComponent.prototype.toggleVisibility = function () {
this._searchVisible = !this._searchVisible;
this._changeDetectorRef.markForCheck();
};
/**
* @param {?} value
* @return {?}
*/
TdSearchBoxComponent.prototype.handleSearchDebounce = function (value) {
this.onSearchDebounce.emit(value);
};
/**
* @param {?} value
* @return {?}
*/
TdSearchBoxComponent.prototype.handleSearch = function (value) {
this.onSearch.emit(value);
};
/**
* @return {?}
*/
TdSearchBoxComponent.prototype.handleClear = function () {
this.onClear.emit(undefined);
};
return TdSearchBoxComponent;
}(_TdSearchBoxMixinBase));
TdSearchBoxComponent.decorators = [
{ type: Component, args: [{
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(function () { return TdSearchBoxComponent; }),
multi: true,
}],
selector: 'td-search-box',
template: "<div class=\"td-search-box\">\n <button mat-icon-button type=\"button\" class=\"td-search-icon\" (click)=\"searchClicked()\">\n <mat-icon *ngIf=\"searchVisible && !alwaysVisible\">{{backIcon}}</mat-icon>\n <mat-icon *ngIf=\"!searchVisible || alwaysVisible\">{{searchIcon}}</mat-icon>\n </button>\n <td-search-input #searchInput\n [@inputState]=\"alwaysVisible || searchVisible\"\n [debounce]=\"debounce\"\n [(ngModel)]=\"value\"\n [showUnderline]=\"showUnderline\"\n [placeholder]=\"placeholder\"\n [clearIcon]=\"clearIcon\"\n (searchDebounce)=\"handleSearchDebounce($event)\"\n (search)=\"handleSearch($event)\"\n (clear)=\"handleClear(); toggleVisibility()\">\n </td-search-input>\n</div>",
styles: [":host{\n display:block; }\n.td-search-box{\n -webkit-box-sizing:border-box;\n box-sizing:border-box;\n display:-webkit-box;\n display:-ms-flexbox;\n display:flex;\n -webkit-box-orient:horizontal;\n -webkit-box-direction:normal;\n -ms-flex-direction:row;\n flex-direction:row;\n -webkit-box-align:center;\n -ms-flex-align:center;\n align-items:center;\n -ms-flex-line-pack:center;\n align-content:center;\n max-width:100%;\n -webkit-box-pack:end;\n -ms-flex-pack:end;\n justify-content:flex-end; }\n .td-search-box .td-search-icon{\n -webkit-box-flex:0;\n -ms-flex:0 0 auto;\n flex:0 0 auto; }\n .td-search-box td-search-input{\n margin-left:12px; }\n ::ng-deep [dir='rtl'] .td-search-box td-search-input{\n margin-right:12px;\n margin-left:0 !important; }\n"],
changeDetection: ChangeDetectionStrategy.OnPush,
inputs: ['value'],
animations: [
trigger('inputState', [
state('0', style({
width: '0%',
margin: '0px',
})),
state('1', style({
width: '100%',
margin: AUTO_STYLE,
})),
transition('0 => 1', animate('200ms ease-in')),
transition('1 => 0', animate('200ms ease-out')),
]),
],
},] },
];
/** @nocollapse */
TdSearchBoxComponent.ctorParameters = function () { return [
{ type: ChangeDetectorRef, },
]; };
TdSearchBoxComponent.propDecorators = {
"_searchInput": [{ type: ViewChild, args: [TdSearchInputComponent,] },],
"backIcon": [{ type: Input, args: ['backIcon',] },],
"searchIcon": [{ type: Input, args: ['searchIcon',] },],
"clearIcon": [{ type: Input, args: ['clearIcon',] },],
"showUnderline": [{ type: Input, args: ['showUnderline',] },],
"debounce": [{ type: Input, args: ['debounce',] },],
"alwaysVisible": [{ type: Input, args: ['alwaysVisible',] },],
"placeholder": [{ type: Input, args: ['placeholder',] },],
"onSearchDebounce": [{ type: Output, args: ['searchDebounce',] },],
"onSearch": [{ type: Output, args: ['search',] },],
"onClear": [{ type: Output, args: ['clear',] },],
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var CovalentSearchModule = /** @class */ (function () {
function CovalentSearchModule() {
}
return CovalentSearchModule;
}());
CovalentSearchModule.decorators = [
{ type: NgModule, args: [{
imports: [
FormsModule,
CommonModule,
MatInputModule,
MatIconModule,
MatButtonModule,
],
declarations: [
TdSearchInputComponent,
TdSearchBoxComponent,
],
exports: [
TdSearchInputComponent,
TdSearchBoxComponent,
],
},] },
];
/** @nocollapse */
CovalentSearchModule.ctorParameters = function () { return []; };
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* Generated bundle index. Do not edit.
*/
export { CovalentSearchModule, TdSearchBoxBase, _TdSearchBoxMixinBase, TdSearchBoxComponent, TdSearchInputBase, _TdSearchInputMixinBase, TdSearchInputComponent };
//# sourceMappingURL=covalent-core-search.js.map