UNPKG

@taiga-ui/kit

Version:
126 lines (121 loc) 6.37 kB
import { __extends, __spread, __decorate, __param } from 'tslib'; import { EventEmitter, Optional, Self, Inject, ChangeDetectorRef, ElementRef, Input, HostBinding, Output, Component, ChangeDetectionStrategy, NgModule } from '@angular/core'; import { NgControl, FormsModule } from '@angular/forms'; import { TUI_DEFAULT_STRINGIFY, TUI_DEFAULT_IDENTITY_MATCHER, ALWAYS_FALSE_HANDLER, isNativeFocusedIn, tuiDefaultProp, tuiPure, AbstractTuiMultipleControl } from '@taiga-ui/cdk'; import { CommonModule } from '@angular/common'; import { TuiBadgeModule } from '@taiga-ui/kit/components/badge'; import { TuiCheckboxBlockModule } from '@taiga-ui/kit/components/checkbox-block'; import { PolymorpheusModule } from '@tinkoff/ng-polymorpheus'; var TUI_DEFAULT_CONTENT_STRINGIFY = function (item) { return TUI_DEFAULT_STRINGIFY(item.$implicit); }; var ɵ0 = TUI_DEFAULT_CONTENT_STRINGIFY; // @bad TODO: Add active zone to track focus var TuiFilterComponent = /** @class */ (function (_super) { __extends(TuiFilterComponent, _super); function TuiFilterComponent(control, changeDetectorRef, elementRef) { var _this = _super.call(this, control, changeDetectorRef) || this; _this.elementRef = elementRef; _this.identityMatcher = TUI_DEFAULT_IDENTITY_MATCHER; _this.items = []; _this.size = 'm'; _this.content = TUI_DEFAULT_CONTENT_STRINGIFY; _this.badgeHandler = function (item) { return Number(item); }; _this.disabledItemHandler = ALWAYS_FALSE_HANDLER; _this.toggledItem = new EventEmitter(); return _this; } Object.defineProperty(TuiFilterComponent.prototype, "focused", { get: function () { return isNativeFocusedIn(this.elementRef.nativeElement); }, enumerable: true, configurable: true }); TuiFilterComponent.prototype.getItemContentContext = function ($implicit) { return { $implicit: $implicit, }; }; TuiFilterComponent.prototype.onCheckbox = function (value, item) { var _this = this; this.toggledItem.emit(item); this.updateValue(value ? __spread(this.value, [item]) : this.value.filter(function (arrItem) { return !_this.identityMatcher(arrItem, item); })); }; TuiFilterComponent.prototype.isCheckboxEnabled = function (item) { var _this = this; return this.value.some(function (arrItem) { return _this.identityMatcher(arrItem, item); }); }; TuiFilterComponent.ctorParameters = function () { return [ { type: NgControl, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NgControl,] }] }, { type: ChangeDetectorRef, decorators: [{ type: Inject, args: [ChangeDetectorRef,] }] }, { type: ElementRef, decorators: [{ type: Inject, args: [ElementRef,] }] } ]; }; __decorate([ Input(), tuiDefaultProp() ], TuiFilterComponent.prototype, "identityMatcher", void 0); __decorate([ Input(), tuiDefaultProp() ], TuiFilterComponent.prototype, "items", void 0); __decorate([ Input(), HostBinding('attr.data-tui-host-size'), tuiDefaultProp() ], TuiFilterComponent.prototype, "size", void 0); __decorate([ Input(), tuiDefaultProp() ], TuiFilterComponent.prototype, "content", void 0); __decorate([ Input(), tuiDefaultProp() ], TuiFilterComponent.prototype, "badgeHandler", void 0); __decorate([ Input(), tuiDefaultProp() ], TuiFilterComponent.prototype, "disabledItemHandler", void 0); __decorate([ Output() ], TuiFilterComponent.prototype, "toggledItem", void 0); __decorate([ tuiPure ], TuiFilterComponent.prototype, "getItemContentContext", null); TuiFilterComponent = __decorate([ Component({ selector: 'tui-filter', template: "<ng-container *ngFor=\"let item of items\">\n <tui-checkbox-block\n automation-id=\"tui-filter__checkbox\"\n class=\"item\"\n [disabled]=\"disabledItemHandler(item)\"\n [hideCheckbox]=\"true\"\n [ngModel]=\"isCheckboxEnabled(item)\"\n [size]=\"size\"\n (ngModelChange)=\"onCheckbox($event, item)\"\n >\n <div automation-id=\"tui-filter__content\" class=\"content\">\n <div\n polymorpheus-outlet\n [content]=\"content\"\n [context]=\"getItemContentContext(item)\"\n ></div>\n <tui-badge\n *ngIf=\"badgeHandler(item) as badgeValue\"\n automation-id=\"tui-filter__badge\"\n class=\"badge\"\n status=\"light\"\n [class.badge_disabled]=\"disabledItemHandler(item)\"\n [size]=\"size\"\n [value]=\"badgeValue\"\n ></tui-badge>\n </div>\n </tui-checkbox-block>\n</ng-container>\n", changeDetection: ChangeDetectionStrategy.OnPush, styles: [":host{display:block;margin-bottom:-4px}.content{display:flex;align-items:center}.item{margin-right:4px;margin-bottom:4px}.item:last-child,:host[data-tui-host-size='l'] .item:last-child{margin-right:0}:host[data-tui-host-size='l'] .item{margin-right:8px;margin-bottom:8px}.badge{margin-left:4px}.badge_disabled{opacity:var(--tui-disabled-opacity)}"] }), __param(0, Optional()), __param(0, Self()), __param(0, Inject(NgControl)), __param(1, Inject(ChangeDetectorRef)), __param(2, Inject(ElementRef)) ], TuiFilterComponent); return TuiFilterComponent; }(AbstractTuiMultipleControl)); var TuiFilterModule = /** @class */ (function () { function TuiFilterModule() { } TuiFilterModule = __decorate([ NgModule({ imports: [ CommonModule, PolymorpheusModule, TuiCheckboxBlockModule, TuiBadgeModule, FormsModule, ], declarations: [TuiFilterComponent], exports: [TuiFilterComponent], }) ], TuiFilterModule); return TuiFilterModule; }()); /** * Generated bundle index. Do not edit. */ export { TuiFilterComponent, TuiFilterModule, ɵ0 }; //# sourceMappingURL=taiga-ui-kit-components-filter.js.map