UNPKG

@taiga-ui/kit

Version:
122 lines (116 loc) 5.15 kB
import { __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, AbstractTuiControl, isNativeFocused, setNativeFocused, tuiDefaultProp, 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'; const TUI_INPUT_PROVIDERS = [ TUI_VALUE_ACCESSOR_PROVIDER, FIXED_DROPDOWN_CONTROLLER_PROVIDER, { provide: TUI_FOCUSABLE_ITEM_ACCESSOR, useExisting: forwardRef(() => TuiInputComponent), }, { provide: TUI_DATA_LIST_HOST, useExisting: forwardRef(() => TuiInputComponent), }, ]; let TuiInputComponent = class TuiInputComponent extends AbstractTuiControl { constructor(control, changeDetectorRef) { super(control, changeDetectorRef); this.icon = null; this.iconAlign = 'left'; this.open = false; this.datalist = ''; } get nativeFocusableElement() { return this.computedDisabled || !this.textfield ? null : this.textfield.nativeFocusableElement; } get focused() { return (isNativeFocused(this.nativeFocusableElement) || (!!this.hostedDropdown && this.hostedDropdown.focused)); } get canOpen() { return !this.computedDisabled && !this.readOnly && !!this.datalist; } onValueChange(value) { this.updateValue(value); this.open = true; } onHovered(hovered) { this.updateHovered(hovered); } onActiveZone(active) { this.updateFocused(active); } handleOption(item) { this.focusInput(); this.updateValue(String(item)); this.open = false; } getFallbackValue() { return ''; } focusInput(preventScroll = false) { if (this.nativeFocusableElement) { setNativeFocused(this.nativeFocusableElement, true, preventScroll); } } }; TuiInputComponent.ctorParameters = () => [ { 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); let TuiInputModule = class TuiInputModule { }; TuiInputModule = __decorate([ NgModule({ imports: [ CommonModule, TuiActiveZoneModule, TuiPrimitiveTextfieldModule, TuiHostedDropdownModule, ], declarations: [TuiInputComponent], exports: [TuiInputComponent], }) ], TuiInputModule); /** * Generated bundle index. Do not edit. */ export { TUI_INPUT_PROVIDERS, TuiInputComponent, TuiInputModule }; //# sourceMappingURL=taiga-ui-kit-components-input.js.map