@taiga-ui/kit
Version:
Taiga UI Angular main components kit
143 lines (138 loc) • 7.03 kB
JavaScript
import { __extends, __decorate, __param } from 'tslib';
import { Optional, Self, Inject, ChangeDetectorRef, ElementRef, Input, HostBinding, ViewChildren, Component, ChangeDetectionStrategy, forwardRef, NgModule } from '@angular/core';
import { NgControl, FormsModule } from '@angular/forms';
import { TUI_DEFAULT_IDENTITY_MATCHER, ALWAYS_FALSE_HANDLER, EMPTY_QUERY, isNativeFocusedIn, tuiDefaultProp, TUI_FOCUSABLE_ITEM_ACCESSOR, AbstractTuiNullableControl } from '@taiga-ui/cdk';
import { TuiRadioLabeledComponent, TuiRadioLabeledModule } from '@taiga-ui/kit/components/radio-labeled';
import { CommonModule } from '@angular/common';
import { TuiRadioGroupModule } from '@taiga-ui/kit/components/radio-group';
import { PolymorpheusModule } from '@tinkoff/ng-polymorpheus';
var TuiRadioListComponent = /** @class */ (function (_super) {
__extends(TuiRadioListComponent, _super);
function TuiRadioListComponent(control, changeDetectorRef, elementRef) {
var _this = _super.call(this, control, changeDetectorRef) || this;
_this.elementRef = elementRef;
_this.items = [];
_this.size = 'm';
_this.identityMatcher = TUI_DEFAULT_IDENTITY_MATCHER;
_this.orientation = "vertical" /* Vertical */;
// @bad TODO: Remove & { index: number }
_this.itemContent = function (_a) {
var $implicit = _a.$implicit;
return String($implicit);
};
_this.disabledItemHandler = ALWAYS_FALSE_HANDLER;
_this.radioButtons = EMPTY_QUERY;
return _this;
}
TuiRadioListComponent_1 = TuiRadioListComponent;
Object.defineProperty(TuiRadioListComponent.prototype, "nativeFocusableElement", {
get: function () {
var focusableRadioButton = this.radioButtons.find(function (radioButton) { return radioButton.nativeFocusableElement !== null; });
return focusableRadioButton ? focusableRadioButton.nativeFocusableElement : null;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TuiRadioListComponent.prototype, "focused", {
get: function () {
return isNativeFocusedIn(this.elementRef.nativeElement);
},
enumerable: true,
configurable: true
});
TuiRadioListComponent.prototype.computeId = function (index) {
return this.id + "-" + index;
};
TuiRadioListComponent.prototype.itemIsDisabled = function (item) {
return this.disabledItemHandler(item);
};
TuiRadioListComponent.prototype.getContentContext = function (item, index, active) {
return { $implicit: item, index: index, active: active };
};
TuiRadioListComponent.prototype.onModelChange = function (value) {
this.updateValue(value);
};
TuiRadioListComponent.prototype.itemIsActive = function (item) {
return this.value === null
? item === null
: this.identityMatcher(this.value, item);
};
var TuiRadioListComponent_1;
TuiRadioListComponent.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()
], TuiRadioListComponent.prototype, "items", void 0);
__decorate([
Input(),
HostBinding('attr.data-tui-host-size'),
tuiDefaultProp()
], TuiRadioListComponent.prototype, "size", void 0);
__decorate([
Input(),
tuiDefaultProp()
], TuiRadioListComponent.prototype, "identityMatcher", void 0);
__decorate([
Input(),
HostBinding('attr.data-tui-host-orientation'),
tuiDefaultProp()
], TuiRadioListComponent.prototype, "orientation", void 0);
__decorate([
Input(),
tuiDefaultProp()
], TuiRadioListComponent.prototype, "itemContent", void 0);
__decorate([
Input(),
tuiDefaultProp()
], TuiRadioListComponent.prototype, "disabledItemHandler", void 0);
__decorate([
ViewChildren(TuiRadioLabeledComponent)
], TuiRadioListComponent.prototype, "radioButtons", void 0);
TuiRadioListComponent = TuiRadioListComponent_1 = __decorate([
Component({
selector: 'tui-radio-list',
template: "<tui-radio-group class=\"group\">\n <tui-radio-labeled\n *ngFor=\"let item of items; index as index\"\n class=\"item\"\n [readOnly]=\"readOnly\"\n [nativeId]=\"computeId(index)\"\n [disabled]=\"disabled\"\n [item]=\"item\"\n [size]=\"size\"\n [pseudoInvalid]=\"computedInvalid\"\n [pseudoDisabled]=\"itemIsDisabled(item)\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange($event)\"\n >\n <div\n polymorpheus-outlet\n [content]=\"itemContent\"\n [context]=\"getContentContext(item, index, itemIsActive(item))\"\n ></div>\n </tui-radio-labeled>\n</tui-radio-group>\n",
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
{
provide: TUI_FOCUSABLE_ITEM_ACCESSOR,
useExisting: forwardRef(function () { return TuiRadioListComponent_1; }),
},
],
styles: [":host{display:block}:host._readonly{pointer-events:none}:host[data-tui-host-orientation=horizontal] .group{display:flex;justify-content:inherit}:host[data-tui-host-orientation=horizontal] .item:nth-child(n+2){margin-left:24px}:host[data-tui-host-orientation=vertical] .item:nth-child(n+2){margin-top:12px}:host[data-tui-host-size='l'][data-tui-host-orientation=horizontal] .item:nth-child(n+2){margin-left:40px}:host[data-tui-host-size='l'][data-tui-host-orientation=vertical] .item:nth-child(n+2){margin-top:16px}"]
}),
__param(0, Optional()),
__param(0, Self()),
__param(0, Inject(NgControl)),
__param(1, Inject(ChangeDetectorRef)),
__param(2, Inject(ElementRef))
], TuiRadioListComponent);
return TuiRadioListComponent;
}(AbstractTuiNullableControl));
var TuiRadioListModule = /** @class */ (function () {
function TuiRadioListModule() {
}
TuiRadioListModule = __decorate([
NgModule({
imports: [
CommonModule,
FormsModule,
PolymorpheusModule,
TuiRadioGroupModule,
TuiRadioLabeledModule,
],
declarations: [TuiRadioListComponent],
exports: [TuiRadioListComponent],
})
], TuiRadioListModule);
return TuiRadioListModule;
}());
/**
* Generated bundle index. Do not edit.
*/
export { TuiRadioListComponent, TuiRadioListModule };
//# sourceMappingURL=taiga-ui-kit-components-radio-list.js.map