@taiga-ui/kit
Version:
Taiga UI Angular main components kit
141 lines (135 loc) • 6.37 kB
JavaScript
import { __extends, __decorate, __param } from 'tslib';
import { forwardRef, Optional, Self, Inject, ChangeDetectorRef, Input, ContentChild, TemplateRef, ViewChild, Component, ChangeDetectionStrategy, NgModule } from '@angular/core';
import { NgControl } from '@angular/forms';
import { TUI_FOCUSABLE_ITEM_ACCESSOR, isNativeFocused, setNativeFocused, tuiDefaultProp, AbstractTuiControl, TuiActiveZoneModule } from '@taiga-ui/cdk';
import { TUI_VALUE_ACCESSOR_PROVIDER, TUI_DATA_LIST_HOST, TuiDataListDirective, TuiHostedDropdownComponent, TuiPrimitiveTextfieldComponent, TuiPrimitiveTextfieldModule, TuiHostedDropdownModule } from '@taiga-ui/core';
import { FIXED_DROPDOWN_CONTROLLER_PROVIDER } from '@taiga-ui/kit/providers';
import { CommonModule } from '@angular/common';
var TUI_INPUT_PROVIDERS = [
TUI_VALUE_ACCESSOR_PROVIDER,
FIXED_DROPDOWN_CONTROLLER_PROVIDER,
{
provide: TUI_FOCUSABLE_ITEM_ACCESSOR,
useExisting: forwardRef(function () { return TuiInputComponent; }),
},
{
provide: TUI_DATA_LIST_HOST,
useExisting: forwardRef(function () { return TuiInputComponent; }),
},
];
var TuiInputComponent = /** @class */ (function (_super) {
__extends(TuiInputComponent, _super);
function TuiInputComponent(control, changeDetectorRef) {
var _this = _super.call(this, control, changeDetectorRef) || this;
_this.icon = null;
_this.iconAlign = 'left';
_this.open = false;
_this.datalist = '';
return _this;
}
Object.defineProperty(TuiInputComponent.prototype, "nativeFocusableElement", {
get: function () {
return this.computedDisabled || !this.textfield
? null
: this.textfield.nativeFocusableElement;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TuiInputComponent.prototype, "focused", {
get: function () {
return (isNativeFocused(this.nativeFocusableElement) ||
(!!this.hostedDropdown && this.hostedDropdown.focused));
},
enumerable: true,
configurable: true
});
Object.defineProperty(TuiInputComponent.prototype, "canOpen", {
get: function () {
return !this.computedDisabled && !this.readOnly && !!this.datalist;
},
enumerable: true,
configurable: true
});
TuiInputComponent.prototype.onValueChange = function (value) {
this.updateValue(value);
this.open = true;
};
TuiInputComponent.prototype.onHovered = function (hovered) {
this.updateHovered(hovered);
};
TuiInputComponent.prototype.onActiveZone = function (active) {
this.updateFocused(active);
};
TuiInputComponent.prototype.handleOption = function (item) {
this.focusInput();
this.updateValue(String(item));
this.open = false;
};
TuiInputComponent.prototype.getFallbackValue = function () {
return '';
};
TuiInputComponent.prototype.focusInput = function (preventScroll) {
if (preventScroll === void 0) { preventScroll = false; }
if (this.nativeFocusableElement) {
setNativeFocused(this.nativeFocusableElement, true, preventScroll);
}
};
TuiInputComponent.ctorParameters = function () { return [
{ type: NgControl, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NgControl,] }] },
{ type: ChangeDetectorRef, decorators: [{ type: Inject, args: [ChangeDetectorRef,] }] }
]; };
__decorate([
Input(),
tuiDefaultProp()
], TuiInputComponent.prototype, "icon", void 0);
__decorate([
Input(),
tuiDefaultProp()
], TuiInputComponent.prototype, "iconAlign", void 0);
__decorate([
ContentChild(TuiDataListDirective, { read: TemplateRef })
], TuiInputComponent.prototype, "datalist", void 0);
__decorate([
ViewChild(TuiHostedDropdownComponent)
], TuiInputComponent.prototype, "hostedDropdown", void 0);
__decorate([
ViewChild(TuiPrimitiveTextfieldComponent)
], TuiInputComponent.prototype, "textfield", void 0);
TuiInputComponent = __decorate([
Component({
selector: 'tui-input',
template: "<tui-hosted-dropdown\n class=\"hosted\"\n [canOpen]=\"canOpen\"\n [content]=\"datalist || ''\"\n [(open)]=\"open\"\n (tuiActiveZoneChange)=\"onActiveZone($event)\"\n>\n <tui-primitive-textfield\n automation-id=\"tui-input__textfield\"\n class=\"textfield\"\n [pseudoFocused]=\"computedFocused\"\n [pseudoHovered]=\"computedHovered\"\n [invalid]=\"computedInvalid\"\n [nativeId]=\"nativeId\"\n [readOnly]=\"readOnly\"\n [iconContent]=\"icon\"\n [iconAlign]=\"iconAlign\"\n [disabled]=\"computedDisabled\"\n [focusable]=\"computedFocusable\"\n [value]=\"value\"\n (valueChange)=\"onValueChange($event)\"\n (hoveredChange)=\"onHovered($event)\"\n >\n <ng-content></ng-content>\n </tui-primitive-textfield>\n</tui-hosted-dropdown>\n",
changeDetection: ChangeDetectionStrategy.OnPush,
providers: TUI_INPUT_PROVIDERS,
styles: [":host{display:block;border-radius:var(--tui-radius-m)}:host._disabled{pointer-events:none}.hosted{display:block;border-radius:inherit}.textfield{border-radius:inherit}"]
}),
__param(0, Optional()),
__param(0, Self()),
__param(0, Inject(NgControl)),
__param(1, Inject(ChangeDetectorRef))
], TuiInputComponent);
return TuiInputComponent;
}(AbstractTuiControl));
var TuiInputModule = /** @class */ (function () {
function TuiInputModule() {
}
TuiInputModule = __decorate([
NgModule({
imports: [
CommonModule,
TuiActiveZoneModule,
TuiPrimitiveTextfieldModule,
TuiHostedDropdownModule,
],
declarations: [TuiInputComponent],
exports: [TuiInputComponent],
})
], TuiInputModule);
return TuiInputModule;
}());
/**
* Generated bundle index. Do not edit.
*/
export { TUI_INPUT_PROVIDERS, TuiInputComponent, TuiInputModule };
//# sourceMappingURL=taiga-ui-kit-components-input.js.map