@taiga-ui/kit
Version:
Taiga UI Angular main components kit
113 lines (108 loc) • 5.49 kB
JavaScript
import { __decorate, __param } from 'tslib';
import { Optional, Self, Inject, ChangeDetectorRef, ViewChild, Component, ChangeDetectionStrategy, forwardRef, NgModule } from '@angular/core';
import { NgControl, FormsModule } from '@angular/forms';
import { AbstractTuiControl, TUI_FOCUSABLE_ITEM_ACCESSOR } from '@taiga-ui/cdk';
import { TuiTextfieldSizeDirective, TUI_TEXTFIELD_SIZE, TuiPrimitiveTextfieldComponent, TuiSvgModule, TuiHintModule, TuiPrimitiveTextfieldModule, TuiTextfieldControllerModule } from '@taiga-ui/core';
import { TUI_PASSWORD_TEXTS } from '@taiga-ui/kit/tokens';
import { Observable } from 'rxjs';
import { CommonModule } from '@angular/common';
import { PolymorpheusModule } from '@tinkoff/ng-polymorpheus';
var TuiInputPasswordComponent_1;
// @dynamic
let TuiInputPasswordComponent = TuiInputPasswordComponent_1 = class TuiInputPasswordComponent extends AbstractTuiControl {
constructor(control, changeDetectorRef, textfieldSize, passwordTexts$) {
super(control, changeDetectorRef);
this.textfieldSize = textfieldSize;
this.passwordTexts$ = passwordTexts$;
this.isPasswordHidden = true;
}
get nativeFocusableElement() {
return this.computedDisabled || !this.textfield
? null
: this.textfield.nativeFocusableElement;
}
get focused() {
return !!this.textfield && this.textfield.focused;
}
get icon() {
if (this.textfieldSize.size === 's') {
return this.isPasswordHidden ? 'tuiIconEyeClosed' : 'tuiIconEyeOpen';
}
return this.isPasswordHidden ? 'tuiIconHideLarge' : 'tuiIconShowLarge';
}
get inputType() {
return this.isPasswordHidden || !this.hasEyeIcon ? 'password' : 'text';
}
get hasEyeIcon() {
return !(this.disabled || this.readOnly);
}
onValueChange(textValue) {
this.updateValue(textValue);
}
onFocused(focused) {
this.updateFocused(focused);
}
onHovered(hovered) {
this.updateHovered(hovered);
}
onPressed(pressed) {
this.updatePressed(pressed);
}
togglePasswordVisibility() {
this.isPasswordHidden = !this.isPasswordHidden;
}
getFallbackValue() {
return '';
}
};
TuiInputPasswordComponent.ctorParameters = () => [
{ type: NgControl, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NgControl,] }] },
{ type: ChangeDetectorRef, decorators: [{ type: Inject, args: [ChangeDetectorRef,] }] },
{ type: TuiTextfieldSizeDirective, decorators: [{ type: Inject, args: [TUI_TEXTFIELD_SIZE,] }] },
{ type: Observable, decorators: [{ type: Inject, args: [TUI_PASSWORD_TEXTS,] }] }
];
__decorate([
ViewChild(TuiPrimitiveTextfieldComponent)
], TuiInputPasswordComponent.prototype, "textfield", void 0);
TuiInputPasswordComponent = TuiInputPasswordComponent_1 = __decorate([
Component({
selector: 'tui-input-password',
template: "<tui-primitive-textfield\n class=\"textfield\"\n [pseudoFocused]=\"pseudoFocused\"\n [pseudoHovered]=\"pseudoHovered\"\n [pseudoPressed]=\"pseudoPressed\"\n [invalid]=\"computedInvalid\"\n [focusable]=\"focusable\"\n [nativeId]=\"nativeId\"\n [tuiTextfieldType]=\"inputType\"\n [disabled]=\"disabled\"\n [readOnly]=\"readOnly\"\n [iconContent]=\"hasEyeIcon ? iconContent : null\"\n [value]=\"value\"\n (valueChange)=\"onValueChange($event)\"\n (focusedChange)=\"onFocused($event)\"\n (hoveredChange)=\"onHovered($event)\"\n (pressedChange)=\"onPressed($event)\"\n>\n <ng-content></ng-content>\n</tui-primitive-textfield>\n\n<ng-template #iconContent>\n <tui-svg\n automation-id=\"tui-password__icon\"\n class=\"icon\"\n tuiHintId=\"not_required\"\n [tuiHint]=\"hintContent\"\n [src]=\"icon\"\n (click)=\"togglePasswordVisibility()\"\n ></tui-svg>\n</ng-template>\n\n<ng-template #hintContent=\"polymorpheus\" polymorpheus>\n <ng-container *ngIf=\"passwordTexts$ | async as texts\">\n {{isPasswordHidden ? texts[0] : texts[1]}}\n </ng-container>\n</ng-template>\n",
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
{
provide: TUI_FOCUSABLE_ITEM_ACCESSOR,
useExisting: forwardRef(() => TuiInputPasswordComponent_1),
},
],
styles: [":host{display:block;border-radius:var(--tui-radius-m)}.icon{cursor:pointer;pointer-events:auto}.textfield{border-radius:inherit}"]
}),
__param(0, Optional()),
__param(0, Self()),
__param(0, Inject(NgControl)),
__param(1, Inject(ChangeDetectorRef)),
__param(2, Inject(TUI_TEXTFIELD_SIZE)),
__param(3, Inject(TUI_PASSWORD_TEXTS))
], TuiInputPasswordComponent);
let TuiInputPasswordModule = class TuiInputPasswordModule {
};
TuiInputPasswordModule = __decorate([
NgModule({
imports: [
CommonModule,
FormsModule,
PolymorpheusModule,
TuiSvgModule,
TuiHintModule,
TuiPrimitiveTextfieldModule,
TuiTextfieldControllerModule,
],
declarations: [TuiInputPasswordComponent],
exports: [TuiInputPasswordComponent],
})
], TuiInputPasswordModule);
/**
* Generated bundle index. Do not edit.
*/
export { TuiInputPasswordComponent, TuiInputPasswordModule };
//# sourceMappingURL=taiga-ui-kit-components-input-password.js.map